我的gridview排序工作正常,点击标题,我不会替换标题文本。但是我需要替换标题文本以显示在点击之后排序是asc还是desc:
"保险'姓名" - > "保险'姓名▲"
(Default) (Sorted)
AllowSorting设置为true,这里是代码背后的代码:
protected void gvMasterList_Sorting(object sender, GridViewSortEventArgs e)
{
string sort_direct = ViewState["SortDirection"].ToString();
DataTable dtMasterList = QueryVMSSummary();
dtMasterList.DefaultView.Sort = e.SortExpression + " " + sort_direct;
gvMasterList.DataSource = dtMasterList;
gvMasterList.DataBind();
string _sort_image = SortImage();
SetSortDirection(ViewState["SortDirection"].ToString());
int columnIndex = 0;
foreach (DataControlFieldHeaderCell headerCell in gvMasterList.HeaderRow.Cells )
{
if (headerCell.ContainingField.SortExpression == e.SortExpression)
{
columnIndex = gvMasterList.HeaderRow.Cells.GetCellIndex(headerCell);
}
}
gvMasterList.HeaderRow.Cells[columnIndex].Text = gvMasterList.Columns[columnIndex].HeaderText + " " + _sort_image;
}
如果我点击后没有更改标题文本,那么排序正常,但如果我在点击添加向上和向下箭头后更改标题文本,则标题文本变为不可点击。我也试过在HeDataBound中重命名headertext,但仍然没有工作
任何想法都可以解决这个问题吗?
谢谢!