【发布时间】:2017-09-29 21:39:20
【问题描述】:
我有一个简单的 gridview 来显示记录,并且我正在使用排序来按所有列排序。当我在第一页时,当我移动到下一页时排序工作,然后它再次向我显示未排序的记录。
<asp:GridView ID="gv" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID"
Width="1100px" BackColor="White" BorderColor="#f5f5f5" BorderStyle="None" BorderWidth="0px" CellPadding="5" Font-Names="Verdana" Font-Size="X-Small" ForeColor="Black" GridLines="Horizontal" PageSize="500" CssClass="myheader" OnPageIndexChanging="gv_PageIndexChanging" OnSorting="gv_Sorting" AllowSorting="true" onrowdatabound="gv_RowDataBound" onrowcommand="gv_RowCommand" >
代码隐藏
protected void gv_Sorting(object sender, GridViewSortEventArgs e)
{
// getCareerList();
// DataTable dataTable = gv.DataSource as DataTable;
DataSet ds = new DataSet();
ds = DataProvider.GetFormByFormTypeIDForGridview(int.Parse(ddCareerType.SelectedItem.Value.ToString()));
DataTable dataTable = ds.Tables[0];
string SortDirection = "DESC";
if (ViewState["SortExpression"] != null)
{
if (ViewState["SortExpression"].ToString() == e.SortExpression)
{
ViewState["SortExpression"] = null;
SortDirection = "ASC";
}
else
{
ViewState["SortExpression"] = e.SortExpression;
}
}
else
{
ViewState["SortExpression"] = e.SortExpression;
}
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + SortDirection;
gv.DataSource = dataView;
gv.DataBind();
}
}
我不确定是什么原因造成的
【问题讨论】:
标签: c# asp.net sorting gridview