gridview 给排序字段添加箭头
2011-10-17 14:52
393 查看
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)//如果是表头,则执行如下操作
{
foreach (TableCell tc in e.Row.Cells)
{
//这种方法直接新加一个控件,也可以换成图片
if (tc.Controls.Count > 0)//这里要判断一下此时是不是已经生成了linkbutton
{
string s1 = ((LinkButton)tc.Controls[0]).Text;
//样式Webdings是123都有自己对应的图片
((LinkButton)tc.Controls[0]).Text = s1.Replace(s1, s1 + "<font face='Webdings'>5</font>");
//倒序的样式
if (tc.Controls.Count > 0 && tc.Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
{
if (((LinkButton)tc.Controls[0]).CommandArgument.ToString() == ViewState["OrderField"].ToString())
{
string s2 = ((LinkButton)tc.Controls[0]).Text;
if (ViewState["OrderDire"].ToString() == "DESC")
{
((LinkButton)tc.Controls[0]).Text = s2.Replace("5", "6");
}
}
}
}
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["style"] = "cursor:pointer;";
}
}
{
if (e.Row.RowType == DataControlRowType.Header)//如果是表头,则执行如下操作
{
foreach (TableCell tc in e.Row.Cells)
{
//这种方法直接新加一个控件,也可以换成图片
if (tc.Controls.Count > 0)//这里要判断一下此时是不是已经生成了linkbutton
{
string s1 = ((LinkButton)tc.Controls[0]).Text;
//样式Webdings是123都有自己对应的图片
((LinkButton)tc.Controls[0]).Text = s1.Replace(s1, s1 + "<font face='Webdings'>5</font>");
//倒序的样式
if (tc.Controls.Count > 0 && tc.Controls[0].GetType().ToString() == "System.Web.UI.WebControls.DataControlLinkButton")
{
if (((LinkButton)tc.Controls[0]).CommandArgument.ToString() == ViewState["OrderField"].ToString())
{
string s2 = ((LinkButton)tc.Controls[0]).Text;
if (ViewState["OrderDire"].ToString() == "DESC")
{
((LinkButton)tc.Controls[0]).Text = s2.Replace("5", "6");
}
}
}
}
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["style"] = "cursor:pointer;";
}
}
相关文章推荐
- gridview添加一列自动增长排序字段
- GridView 实现自定义分页、排序、查询、添加、编辑、多选删除 之代码规范
- gridview自定义绑定字段实现排序功能
- 05.NopCommerce给Topic表添加排序及类别字段
- 编写多字段排序的GridView的几点注意
- GridView按字段升降排序
- Gridview自定义排序且显示上下箭头
- Gridview自定义排序且显示上下箭头
- Yii2-GridView 中让关联字段带搜索和排序功能
- 艾伟:Gridview自定义排序且显示上下箭头
- GridView实现自动排序带上下箭头
- Gridview标题头添加排序图片
- GridView 实现自定义分页、排序、查询、添加、编辑、多选删除、导出、突出显示等常见应用实现
- gridview 实现自定义分页、排序、查询、添加、编辑、多选删除 之代码规范
- gridview 排序时候显示箭头
- 扩展GridView控件以包含一个与排序相关的箭头标记
- 使用JQuery插件,排序Gridview的某个字段
- GridView实现自动排序带上下箭头
- Gridview中按字段排序
- yii2 GridView 查询子表数据(情景一)根据子表某字段排序或查询