2013-01-10 38 views
1

我找不到修復gridviev中頁碼的方法,即根據gridview的內容他們沒有改變位置。如何修復gridviev中的頁碼?

HTML:

<asp:GridView ID="tableResults" runat="server" DataSourceID="sourcePoints" 
CssClass = "table table-bordered" AutoGenerateColumns="False" OnDataBound="tableResults_Bound" 
OnRowDataBound = "tableResults_DataBound" DataKeyNames="i_id" PageSize="4" AllowPaging="true" 
AutoGenerateDeleteButton="True" OnRowDeleted="tableResults_RowDeleted" Height="300px" Width="100%" 
AutoGenerateEditButton = "True" OnRowUpdating="tableResults_RowUpdating" 
AllowSorting="true" OnRowUpdated="tableResults_RowUpdated" BorderStyle="None"> 

回答

1

簡而言之:有一些技巧,而在asp.net GridView控制使用頁碼。

對於分頁工作,您的數據源必須支持它。如果它不像DataTable一樣,那麼你必須自己做這個。

這下面的代碼可以幫助你:

OnPageIndexChanging="myGridview_PageIndexChanging" 

protected void myGridview_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 
    GridView gv = (GridView)sender; 
    DataView dv = gv.DataSource as DataView; 
    DataTable dataTable = dv.Table; 

    gv.DataSource = myDataTable; 
    gv.PageIndex = e.NewPageIndex; 
    gv.DataBind(); 
} 

參考看:

給你一些**互補職位**,說明他們一步一步: