0

编辑:现在工作,见下文。

大家好,

我的 ASP.Net 3.5 应用程序有一点问题。我正在尝试让程序获取已单击的页码。我正在使用 ASP.Net 内置的 AllowPaging="True" 函数。没有代码就不一样了,所以这里是:

ASP.NET:

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
            GridLines="Vertical" Width="960px" AllowSorting="True" 
            EnableSortingAndPagingCallbacks="True" AllowPaging="True" PageSize="25" >
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>

C#:

var fillTable = from ft in db.IncidentDatas
                                where ft.pUserID == Convert.ToInt32(ClientList.SelectedValue.ToString())
                                select new
                                {
                                    Reference = ft.pRef.ToString(),
                                    Date = ft.pIncidentDateTime.Value.Date.ToShortDateString(),
                                    Time = ft.pIncidentDateTime.Value.TimeOfDay,
                                    Premesis = ft.pPremises.ToString(),
                                    Latitude = ft.pLat.ToString(),
                                    Longitude = ft.pLong.ToString()
                                };
                if (fillTable.Count() > 0)
                {
                    GridView1.DataSource = fillTable;
                    GridView1.DataBind();
                    var IncidentDetails = fillTable.ToList();
                    for (int i = 0; i < IncidentDetails.Count(); i++)
                    {
                        int pageno = GridView1.PageIndex;
                        int pagenostart = pageno * 25;
                        if (i >= pagenostart && i < (pagenostart + 25))
                        {
                            //Processing
                        }
                    }
                 }

知道为什么 GridView1.PageIndex 总是 = 0 吗?问题是,网格视图的处理工作正常......它总是会转到正确的分页页面,但是当我尝试获取数字时它总是 0。帮助!

4

3 回答 3

0

您是否尝试过GridView1.PageIndex在调用之前访问GridView1.DataBind?当您分配新数据源然后将其绑定到网格时,它可能会被重置。

于 2010-05-26T11:09:03.610 回答
0

嗯...别介意这个。我删除了 GridView 并添加了另一个,添加了 PageIndexChanging 事件,然后使用了 e.NewPageIndex。出于某种原因,它不允许我在另一个 GridView 上使用该事件。奇怪的。

于 2010-05-26T12:47:02.537 回答
0

检查您的帖子,您可能会在每次页面加载时重新加载网格,因此当您分页时,您可能会调用填充网格的代码并重置页面索引。您需要确保仅在不是回发时才加载它,如果是回发,则必须从 ViewState 等存储区域获取数据和适当的 pageIndex。

于 2010-05-26T12:49:40.673 回答