本文介绍了ObjectDataSource控件寻呼 - >没有在GridView中显示的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ObjectDataSource控件和GridView的配置如下图所示(使用VS2008 W / .NET3.5):

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>

有在背后为GridView或数据源

There are no eventhandlers or other code in the code behind for the gridview or the datasource

因此​​,有在底层类ErrorViewModel的方法:        公开数据表GetMainData()        {            变种dt的= provider.MainData();            myMainData = DT;            返回DT;        }

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

我想:自定义服务器端分页。有什么问题:当我在数据源设置EnablePaging =真,就没有在GridView中显示的数据。如果EnablePaging设置为false,有数据显示。正如你可以看到,这两个方法来检索数据会做完全一样的。使用EnablePaging = TRUE时返回调试显示,有行。另一个奇怪的事情(使用EnablePaging = TRUE):在GetMainData maximumRows被设置为15和startRowIndex至0在CountMainData maximumRows被设置为0和startRowIndex至0

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 0in 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?

推荐答案

这个错误是,该CountMainData没有返回一个整数。之后,我改变了CountMainData返回一个整数,一切正常。

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

这篇关于ObjectDataSource控件寻呼 - &GT;没有在GridView中显示的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 19:48