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

大家好,

我的ASP.NET 3.5应用程序有一些问题。我正在尝试获取该程序以拾取单击哪些页码。我正在使用ASP.NET内置的insurepaging =“ 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。帮助!

有帮助吗?

解决方案 2

嗯...没关系。我删除了GridView并添加了另一个,添加了pageIndexchanging的事件,然后使用了e.newpageIndex。由于某种原因,它不允许我在另一个GridView上使用该事件。奇怪的。

其他提示

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

检查您的帖子,您可能会在每个页面加载上加载电网,因此,当您页面时,您可能会调用填充网格的代码,并重置页面索引。您需要确保只有在 不是 寄回,如果是帖子,则必须从viewState等储存区域中获取数据和适当的页面索引。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top