当标题文本在RowDataBound事件中改变时,Gridview排序
本文关键字:改变 Gridview 排序 事件 标题 文本 RowDataBound | 更新日期: 2023-09-27 18:10:00
我有一个GridView在我的网页上,其数据源是一个在运行时填充的数据表。GridView的AllowSorting属性是True。我已经成功地为这个GridView实现了手动排序。
但是我必须将网页翻译成其他语言,我使用了本地资源文件。我改变了标题文本的GridView列在RowDataBound事件。从那时起,我无法对GridView进行排序。
protected void GVSummaryTable_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells.Count > 0)
{
//Translate header text
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = GetLocalResourceObject("GVSummaryTableName").ToString();
e.Row.Cells[1].Text = GetLocalResourceObject("GVSummaryTableLoginLevel").ToString();
e.Row.Cells[2].Text = GetLocalResourceObject("GVSummaryTableLoginID").ToString();
e.Row.Cells[4].Text = GetLocalResourceObject("GVSummaryTableDate").ToString();
}
}
}
我应该怎么做才能对列进行排序?任何帮助都会很感激。谢谢!
将代码更改为下面解决了这个问题:
if (e.Row.RowType == DataControlRowType.Header)
{
LinkButton LnkHeaderText = e.Row.Cells[1].Controls[0] as LinkButton;
LnkHeaderText.Text = "Name";
}
我不确定问题是否与标题文本有关,因为排序通常是用排序表达式完成的。请确保在排序时也给了这个属性一个值。希望这对你有帮助!