- 积分
- 15512
- 明经币
- 个
- 注册时间
- 2008-11-24
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
【转MSDN】
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (ViewState["SortDirection"] == null)
{
ViewState["SortDirection"] = SortDirection.Descending;
}
for (int i = 0; i <= ((GridView)sender).Columns.Count - 1; i++)
{
((GridView)sender).Columns[i].HeaderText = ((GridView)sender).Columns[i].HeaderText.Replace("▲", "");
((GridView)sender).Columns[i].HeaderText = ((GridView)sender).Columns[i].HeaderText.Replace("▼", "");
}
string ViewState_SortDirection = ViewState["SortDirection"].ToString();
int Columns_i =0;
for (int i = 0; i <= ((GridView)sender).Columns.Count - 1; i++)
{
if (e.SortExpression == ((GridView)sender).Columns[i].SortExpression)
{
Columns_i = i;
if (ViewState["SortDirection"].ToString() == SortDirection.Ascending.ToString())
{
e.SortDirection = SortDirection.Descending;
((GridView)sender).Columns[i].HeaderText = ((GridView)sender).Columns[i].HeaderText + "▼";
ViewState["SortDirection"] = SortDirection.Descending;
}
else
{
e.SortDirection = SortDirection.Ascending;
((GridView)sender).Columns[i].HeaderText = ((GridView)sender).Columns[i].HeaderText + "▲";
ViewState["SortDirection"] = SortDirection.Ascending;
}
}
}
} |
|