2010-05-26 76 views
0

編輯:現在工作,見下文。ASP.Net Gridview分頁,pageindex始終== 0

大家好,

有我的ASP.Net 3.5應用程序一個小問題。我試圖讓程序拿起被點擊的頁碼。我正在使用內置的AllowPaging =「True」函數的ASP.Net。這是從來沒有不代碼是相同的,所以在這裏它是:

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。幫幫我!

回答

0

嗯...沒關係這個。我刪除了GridView並添加了另一個,爲PageIndexChanging添加了事件,然後使用了e.NewPageIndex。出於某種原因,它不會允許我在其他GridView上使用該事件。奇怪的。

0

您在致電GridView1.DataBind之前是否嘗試過訪問GridView1.PageIndex?當您分配新數據源並將其綁定到網格時,它可能會重置。

+0

是啊,我已經試過這個,仍然是0. – 2010-05-26 12:06:52

+0

你的綁定代碼位於哪個事件中? – AxelEckenberger 2010-05-26 12:31:07

0

檢查您的回覆,您可能在每次加載頁面時加載新網格,因此當您頁面時,您可能會調用填充網格的代碼並重置頁面索引。你需要確保加載它只有當它是不是回發,如果它是回發你必須從像ViewState等存儲區域獲取數據和相應的pageIndex。