注意要把gridview表头的HtmlEncode的值改成false
/**/
/// <summary>
/// 为GridView.HeaderRow添加排序标识符
/// </summary>
/// <param name="headerRow">GridViewRow</param>
private void changeHeaders(GridViewRow headerRow)
{
if (this.GridViewFileList.Rows.Count > 0) //有数据时才执行
{
for (int i = 0; i < headerRow.Cells.Count; i++)
{
if (headerRow.Cells[i] is DataControlFieldCell)
{
DataControlField field = ((DataControlFieldCell)headerRow.Cells[i]).ContainingField;
if (field.HeaderText.IndexOf("↓") >= 0 || field.HeaderText.IndexOf("↑") >= 0)
field.HeaderText = field.HeaderText.Substring(0, field.HeaderText.Length - "<font color='#FF0000'>↓
</font>".Length); //把开始的排序方式去掉
if (this.HiddenFieldGridViewSortExpression.Value != "" &&
this.HiddenFieldGridViewSortExpression.Value.Trim().Equals(field.SortExpression.Trim()))
{
//保存了排序方式的隐藏控件
if (this.HiddenFieldGridViewSortDirection.Value.Equals("DESC")) //增加新的排序方式
field.HeaderText = field.HeaderText + "<font color='#FF0000'>↓</font>";
else
field.HeaderText = field.HeaderText + "<font color='#FF0000'>↑</font>";
}
}
}
}
}
/// 为GridView.HeaderRow添加排序标识符
/// </summary>
/// <param name="headerRow">GridViewRow</param>
private void changeHeaders(GridViewRow headerRow)
{
if (this.GridViewFileList.Rows.Count > 0) //有数据时才执行
{
for (int i = 0; i < headerRow.Cells.Count; i++)
{
if (headerRow.Cells[i] is DataControlFieldCell)
{
DataControlField field = ((DataControlFieldCell)headerRow.Cells[i]).ContainingField;
if (field.HeaderText.IndexOf("↓") >= 0 || field.HeaderText.IndexOf("↑") >= 0)
field.HeaderText = field.HeaderText.Substring(0, field.HeaderText.Length - "<font color='#FF0000'>↓
</font>".Length); //把开始的排序方式去掉
if (this.HiddenFieldGridViewSortExpression.Value != "" &&
this.HiddenFieldGridViewSortExpression.Value.Trim().Equals(field.SortExpression.Trim()))
{
//保存了排序方式的隐藏控件
if (this.HiddenFieldGridViewSortDirection.Value.Equals("DESC")) //增加新的排序方式
field.HeaderText = field.HeaderText + "<font color='#FF0000'>↓</font>";
else
field.HeaderText = field.HeaderText + "<font color='#FF0000'>↑</font>";
}
}
}
}
}