在gridview1里面有两列排序列,UserID和Dept,一点列名就会改变排序方式,我想在列名旁加上个图标,比如UserID升序时就是向上的箭头,降序时就变成是向下的箭头。
该如何实现?
以下是我实现排序的代码:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression.ToString();
string sortDirection = "ASC";
if (sortExpression == this.GridView1.Attributes["SortExpression"])
{
sortDirection = (this.GridView1.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
}
this.GridView1.Attributes["SortExpression"] = sortExpression;
this.GridView1.Attributes["SortDirection"] = sortDirection;
this.BindGridView();
}前台代码:
<Columns>
<asp:BoundField DataField="USERID" HeaderText="工号" SortExpression="USERID">
<ControlStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="Dept" HeaderText="部门" SortExpression="Dept">
<ControlStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" Width="80px" />
</asp:BoundField>
</Columns>
该如何实现?
以下是我实现排序的代码:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
string sortExpression = e.SortExpression.ToString();
string sortDirection = "ASC";
if (sortExpression == this.GridView1.Attributes["SortExpression"])
{
sortDirection = (this.GridView1.Attributes["SortDirection"].ToString() == sortDirection ? "DESC" : "ASC");
}
this.GridView1.Attributes["SortExpression"] = sortExpression;
this.GridView1.Attributes["SortDirection"] = sortDirection;
this.BindGridView();
}前台代码:
<Columns>
<asp:BoundField DataField="USERID" HeaderText="工号" SortExpression="USERID">
<ControlStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="Dept" HeaderText="部门" SortExpression="Dept">
<ControlStyle Width="60px" />
<ItemStyle HorizontalAlign="Center" Width="80px" />
</asp:BoundField>
</Columns>
解决方案 »
- 一个 js 的事件控制问题
- 关于数据绑定后使用Updatacom
- 浏览器倒退出现拒绝访问
- 请问,在iframe中用treeview如何实现点击某节点后不刷新 而在另一个iframe中打开点击要打开的页面
- DropDownList动了,为什么没反应?
- 怎么设置DropDownList的选定项
- System.NullReferenceException: 未将对象引用设置到对象的实例,错误!
- 有关页面事件的。DropDownList7_SelectedIndexChanged(object sender, System.EventArgs e)大家帮忙看看。谢谢。
- 求sql语句取出一个字段的值附给一个变量!!(datagrid中一个超联接转移到另外一个页面后的sql语句)
- 客户端如何出现Word界面(有工具栏)编辑保存服务器上的Word文档《以前相关贴子均不能显示》
- cookie! 怎么保存用户名 和怎么取出用户名
- 未将对象引用设置到对象的实例 请教 谢谢!~
<img src="升.gif" onclick="this.src=(this.src=='升.gif')?'降.gif':'升.gif'">标签