ObjectDataSource Paging -> no data displayed in GridView

强颜欢笑 提交于 2019-12-23 17:35:03

问题


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 little setting? Any suggestions?


回答1:


The mistake was, that the CountMainData didn't return an integer. After I changed CountMainData to return an integer, everything worked fine.



来源:https://stackoverflow.com/questions/6774154/objectdatasource-paging-no-data-displayed-in-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!