1
我已經實現在GridView
控制分揀和分頁的頁面索引變化。代碼如下:排序是失去了對一個GridView asp.net
<asp:GridView ShowHeaderWhenEmpty="True" CssClass="Grid"
AlternatingRowStyle-CssClass="alt" AllowPaging="True" PageSize="15" OnPageIndexChanging="grdAllRequests_PageIndexChanging"
PagerStyle-CssClass="pgr" OnSorting="grdAllRequests_Sorting" AllowSorting="True"
EmptyDataText="No data to show" ID="grdAllRequests" runat="server" AutoGenerateColumns="false"
OnRowDataBound="grdAllRequests_RowDataBound">
下面是背後的代碼分頁和排序
protected void grdAllRequests_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdAllRequests.PageIndex = e.NewPageIndex;
DataTable dt = (DataTable)ViewState["dtAllRequests"];
BindDataBAL bind = new BindDataBAL();
bind.BindGridData(grdAllRequests, dt);
}
protected void grdAllRequests_Sorting(object sender, GridViewSortEventArgs e)
{
DataTable dtrslt = (DataTable)ViewState["dtAllRequests"];
if (dtrslt.Rows.Count > 0)
{
if (Convert.ToString(ViewState["sortdr"]) == "Asc")
{
dtrslt.DefaultView.Sort = e.SortExpression + " Desc";
ViewState["sortdr"] = "Desc";
}
else
{
dtrslt.DefaultView.Sort = e.SortExpression + " Asc";
ViewState["sortdr"] = "Asc";
}
ViewState["dtAllRequests"] = dtrslt;
grdAllRequests.DataSource = dtrslt;
grdAllRequests.DataBind();
}
}
現在是當我在任何標題點擊正確執行問題的排序,但是當我嘗試導航到下一頁,然後排序失去。不知道發生了什麼問題。請幫助。