簡體   English   中英

ASP.Net Gridview分頁,pageindex始終== 0

[英]ASP.Net Gridview paging, pageindex always == 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。 救命!

您是否嘗試訪問GridView1.PageIndex之前調用GridView1.DataBind 當您分配新的數據源然后將其綁定到網格時,它可能會重置。

嗯...沒關系 我刪除了GridView並添加了另一個,為PageIndexChanging添加了事件,然后使用e.NewPageIndex。 由於某種原因,它不允許我在另一個GridView上使用該事件。 奇怪的。

再次查看您的帖子,您可能會在每次頁面加載時都重新加載網格,因此,在您分頁時,您可能會調用填充網格並重置頁面索引的代碼。 您需要確保僅當它不是回發時才加載它,如果是回發,則必須從諸如ViewState等存儲區域中獲取數據和適當的pageIndex。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM