菜鸟求围观--GridView GridView 中如何实现点击列头排序,有代码更好!小弟感激不尽! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 貌似GridView有个属性AllowSorting就行 1.升序列头绑定:XXX栏位 + "↑"降序列头绑定:XXX栏位 + "↓"2.AllowSorting =True 在GirdView1单击事件里写要先写上e.rowindex>0 && e.cellindex(culoumn)>0 防止系统宕机然后GirdView1.Columns["列名"].HeaderText = "列v";.HeaderText 这个方法就是改显示的名字的 各位大虾请看代码static string orderby = string.Empty; static string desc = string.Empty; protected void gvBarcodeInfo_Sorting(object sender, GridViewSortEventArgs e) { for (int i = 0; i < gvBarcodeInfo.Columns.Count; i++) { gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" ^", ""); gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" v", ""); } orderby = " order by " + e.SortExpression; if (desc == string.Empty) { desc = " desc "; for (int i = 0; i < gvBarcodeInfo.Columns.Count; i++) { gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText + " v"; } } else { desc = string.Empty; for (int i = 0; i < gvBarcodeInfo.Columns.Count; i++) { gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText + " ^"; } } orderby += desc; string where = getWhere(txtBarcode.Text); getData(where, orderby); }当我点击一列时,所有的列后面都加了 我只需要我点击的那一列加标示。 " for (int i = 0; i < gvBarcodeInfo.Columns.Count; i++) { gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" ^", ""); gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" v", ""); }"这段代码就是造成所有列都加上标记的原因.去 GridViewSortEventArgs e 中取当前发起这个sorting事件的特定列. GirdView1.Columns[e.CellIndex].HeaderText = "列v";不就好了吗 而且你还是循环所有的列去给他加v的不要循环 直接写GirdView1.Columns[e.CellIndex].HeaderText = "列v"; dataGridView不是自动就给你加箭头了吗? win7下调用未签名的activex问题 如何把DataSet中的内容写进文本文件 excel操作问题 搜索文档中的文件 请教从C过度到C#要注意什么呢?? 【求解】C# 解压文件到内存,然后分析内存中的文件把数据保存到数据库 抓取HTML代码速度好慢啊~怎么处理? 【求助】【.net4.0无法登陆百度?】 请求帮助 .net 2005中控件的size属性怎么不能设置高度?比如:comboBox,maskedTextBox 刷新页面时,如何保留动态生成的RadioButtonList的选择状态 Matrix矩阵问题
升序列头绑定:XXX栏位 + "↑"
降序列头绑定:XXX栏位 + "↓"2.AllowSorting =True
要先写上
e.rowindex>0 && e.cellindex(culoumn)>0 防止系统宕机
然后
GirdView1.Columns["列名"].HeaderText = "列v";
.HeaderText 这个方法就是改显示的名字的
static string orderby = string.Empty;
static string desc = string.Empty;
protected void gvBarcodeInfo_Sorting(object sender, GridViewSortEventArgs e)
{
for (int i = 0; i < gvBarcodeInfo.Columns.Count; i++)
{
gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" ^", "");
gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" v", "");
} orderby = " order by " + e.SortExpression;
if (desc == string.Empty)
{
desc = " desc ";
for (int i = 0; i < gvBarcodeInfo.Columns.Count; i++)
{
gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText + " v";
}
}
else
{
desc = string.Empty;
for (int i = 0; i < gvBarcodeInfo.Columns.Count; i++)
{
gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText + " ^";
}
}
orderby += desc;
string where = getWhere(txtBarcode.Text);
getData(where, orderby);
}当我点击一列时,所有的列后面都加了 我只需要我点击的那一列加标示。
{
gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" ^", "");
gvBarcodeInfo.Columns[i].HeaderText = gvBarcodeInfo.Columns[i].HeaderText.Replace(" v", "");
}"这段代码就是造成所有列都加上标记的原因.去 GridViewSortEventArgs e 中取当前发起这个sorting事件的特定列.
不就好了吗
不要循环 直接写
GirdView1.Columns[e.CellIndex].HeaderText = "列v";