ObjectDataSource Paging -> no data displayed in GridView
i have an objectdatasource and a gridview configured as shown below (using VS2008 w/ .NET3.5):
<asp:ObjectDataSource ID="odsMainData" runat="server" EnablePaging="True" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetMainData" TypeName="ErrorViewer.Model.ErrorViewModel"
SelectCountMethod="CountMainData">
<SelectParameters>
<asp:Parameter Name="maximumRows" Type="Int32" />
<asp:Parameter Name="startRowIndex" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:GridView ID="grdMainData" runat="server" AllowPaging="True" DataSourceID="odsMainData" PageSize="15" AllowSorting="True">
</asp:GridView>
There are no eventhandlers or other code in the code behind for the gridview or the datasource
So there are methods in the underlying class "ErrorViewModel": public DataTable GetMainData() { var dt = provider.MainData(); myMainData = dt; return dt; }
public DataTable GetMainData(int maximumRows, int startRowIndex)
{
var dt = provider.MainData();
myMainData = dt;
return dt;
}
public long CountMainData()
{
var count = provider.GetMainDataCount();
return count;
}
public long CountMainData(int maximumRows, int startRowIndex)
{
var count = CountMainData();
return count;
}
What I want: custom server side paging. What is the problem: When I set EnablePaging=true in the datasource, there will be no data displayed in the gridview. If EnablePaging is set to false, there is data displayed. As you can see, the two methods for retrieving the data will do exactly the same. Debugging shows, that there are rows returned when using EnablePaging=true. Another Strange thing (using EnablePaging=true): in GetMainData maximumRows is set to 15 and startRowIndex to 0 in CountMainData maximumRows is set to 0 and startRowIndex to 0
I've implemented this type of custom paging in another project and did the same configuration - but this time it resides in this strange behavior. What is wrong in my implementation? Did i just forgot one littl开发者_如何转开发e setting? Any suggestions?
The mistake was, that the CountMainData didn't return an integer. After I changed CountMainData to return an integer, everything worked fine.
精彩评论