我正在尝试在我的asp.net webforms应用程序中使用Ninject 3。它工作正常,但包含ObjectDataSource
的某些网页,Select
的{{1}}方法会抛出ObjectDataSource
。我的代码如下:
NullReferenceException
:
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
答案 0 :(得分: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;
}