0

我正在尝试在我的 asp.net webforms 应用程序中使用 Ninject 3。它工作正常,除了一些包含. throwsObjectDataSourceSelect方法的页面。我的代码如下:ObjectDataSourceNullReferenceException

Web.Admin.Grades.aspx

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                    EnablePaging="true" TypeName="Web.Admin.Grades"
                    SelectMethod="GetData" SelectCountMethod="GetDataCount"
                    StartRowIndexParameterName="StartRowIndex" MaximumRowsParameterName="MaximumRows">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="SearchTxtBox" Type="String" Name="SearchKeyWord" PropertyName="Text" />
                    </SelectParameters>
                </asp:ObjectDataSource>

Web.Admin.Grades.cs

[Inject]
public IGradesRepository _Grades { get; set; }

public IList GetData(string SearchKeyWord, int StartRowIndex, int MaximumRows)
{
    return _Grades.GetGrades(SearchKeyWord, StartRowIndex, MaximumRows);
}

public int GetDataCount(string SearchKeyWord)
{
    return _Grades.GetGradesCount(SearchKeyWord);
}
4

1 回答 1

1

抱歉造成误解我解决问题如下

 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
                EnablePaging="true" TypeName="Domain.Abstract.IGradesRepository"
                SelectMethod="GetGrades" SelectCountMethod="GetGradesCount"   OnObjectCreating="ObjectDataSource1_ObjectCreating"
                StartRowIndexParameterName="StartRowIndex" MaximumRowsParameterName="MaximumRows">
                <SelectParameters>
                    <asp:ControlParameter ControlID="SearchTxtBox" Type="String" Name="SearchKeyWord"  PropertyName="Text" />
                </SelectParameters>
            </asp:ObjectDataSource>

和 Web.Admin.Grades.cs:

[Inject]
    public IGradesRepository _Grades { get; set; }
protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        e.ObjectInstance = _Grades;
    }
于 2013-03-26T10:07:45.800 回答