string HeadText;
int i
foreach(DataGridColumn column in DataGrid1.Columns)
{
HeadText = column.HeaderText;
i = HeadText.IndexOf("▼",0,HeadText.Length);
if(i==0)
{
column.HeaderText = column.HeaderText + " ▼";
}
else
{
i = HeadText.IndexOf("▲",0,HeadText.Length);
if(i==0)
{
column.HeaderText = column.HeaderText + " ▲";
}
else
{
column.HeaderText = column.HeaderText + " ▼";
}
}
}
程序执行了没有效果
11 个解决方案
#1
你这是什么事件里面写的?
#2
回复:realljx(勿忘国耻 抵制日货&女人是商品)
private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
#3
if(i==0)
-->
if(i==-1)
-->
if(i==-1)
#4
在ItemDataBound中写
SortCommand过后你一重新绑定数据
HeaderText 又回去了
:)
SortCommand过后你一重新绑定数据
HeaderText 又回去了
:)
#5
楼主应该 在适当的时候去掉 ▼▲ 否则你的这种符号会越来越多,.
#6
column.HeaderText = column.HeaderText + " ▼";
这句话好象根本就不能改变列标题的名称啊
这句话好象根本就不能改变列标题的名称啊
#7
所以你需要先检查 再绑定 然后执行你上面的操作.
#8
column?
columns["id"]
columns["id"]
#9
MArk
#10
//可以在ItemCreated事件里对排序列的Head进行定制,比如,若e.Item.ItemType=ListItemType.Header,可以在Head后面添加表示排序方向的箭头
private void UserDataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
string strSortBy = "";
string strSortAscending = "";
string strOrder = "";
//
for(int i=1;i<6;i++)
{
strSortBy = (string) ViewState["SortExpression"];
strSortAscending = (string) ViewState["orderby"];
strOrder = ("asc" == strSortAscending ? "5" : "6");
Label Lbl_Sorted = new Label();
Lbl_Sorted.Font.Name = "webdings";
Lbl_Sorted.Font.Size = FontUnit.XSmall;
Lbl_Sorted.Text = " " + strOrder;
e.Item.Cells[i].Controls.Add(Lbl_Sorted);
}
}
}
private void UserDataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
string strSortBy = "";
string strSortAscending = "";
string strOrder = "";
//
for(int i=1;i<6;i++)
{
strSortBy = (string) ViewState["SortExpression"];
strSortAscending = (string) ViewState["orderby"];
strOrder = ("asc" == strSortAscending ? "5" : "6");
Label Lbl_Sorted = new Label();
Lbl_Sorted.Font.Name = "webdings";
Lbl_Sorted.Font.Size = FontUnit.XSmall;
Lbl_Sorted.Text = " " + strOrder;
e.Item.Cells[i].Controls.Add(Lbl_Sorted);
}
}
}
#11
for(int i=1;i<6;i++)
可以换成
for(int i=1;i<e.Item.Cells.Count;i++)其他的不变
可以换成
for(int i=1;i<e.Item.Cells.Count;i++)其他的不变
#1
你这是什么事件里面写的?
#2
回复:realljx(勿忘国耻 抵制日货&女人是商品)
private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
#3
if(i==0)
-->
if(i==-1)
-->
if(i==-1)
#4
在ItemDataBound中写
SortCommand过后你一重新绑定数据
HeaderText 又回去了
:)
SortCommand过后你一重新绑定数据
HeaderText 又回去了
:)
#5
楼主应该 在适当的时候去掉 ▼▲ 否则你的这种符号会越来越多,.
#6
column.HeaderText = column.HeaderText + " ▼";
这句话好象根本就不能改变列标题的名称啊
这句话好象根本就不能改变列标题的名称啊
#7
所以你需要先检查 再绑定 然后执行你上面的操作.
#8
column?
columns["id"]
columns["id"]
#9
MArk
#10
//可以在ItemCreated事件里对排序列的Head进行定制,比如,若e.Item.ItemType=ListItemType.Header,可以在Head后面添加表示排序方向的箭头
private void UserDataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
string strSortBy = "";
string strSortAscending = "";
string strOrder = "";
//
for(int i=1;i<6;i++)
{
strSortBy = (string) ViewState["SortExpression"];
strSortAscending = (string) ViewState["orderby"];
strOrder = ("asc" == strSortAscending ? "5" : "6");
Label Lbl_Sorted = new Label();
Lbl_Sorted.Font.Name = "webdings";
Lbl_Sorted.Font.Size = FontUnit.XSmall;
Lbl_Sorted.Text = " " + strOrder;
e.Item.Cells[i].Controls.Add(Lbl_Sorted);
}
}
}
private void UserDataGrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
string strSortBy = "";
string strSortAscending = "";
string strOrder = "";
//
for(int i=1;i<6;i++)
{
strSortBy = (string) ViewState["SortExpression"];
strSortAscending = (string) ViewState["orderby"];
strOrder = ("asc" == strSortAscending ? "5" : "6");
Label Lbl_Sorted = new Label();
Lbl_Sorted.Font.Name = "webdings";
Lbl_Sorted.Font.Size = FontUnit.XSmall;
Lbl_Sorted.Text = " " + strOrder;
e.Item.Cells[i].Controls.Add(Lbl_Sorted);
}
}
}
#11
for(int i=1;i<6;i++)
可以换成
for(int i=1;i<e.Item.Cells.Count;i++)其他的不变
可以换成
for(int i=1;i<e.Item.Cells.Count;i++)其他的不变