Question

I am trying to use Ninject 3 in my asp.net webforms application. It works fine except some pages that contains ObjectDataSource, the Select method of the ObjectDataSource throws a NullReferenceException. My code is as follows :

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);
}
Was it helpful?

Solution

Sorry for misunderstanding I solve the problem as follows

 <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>

and Web.Admin.Grades.cs:

[Inject]
    public IGradesRepository _Grades { get; set; }
protected void ObjectDataSource1_ObjectCreating(object sender, ObjectDataSourceEventArgs e)
    {
        e.ObjectInstance = _Grades;
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top