在RowDataBound事件中更改标题文本时的Gridview排序

KhD*_*KhD 6 c# asp.net gridview

我的网页上有一个GridView,其DataSource是一个在运行时填充的DataTable.GridView的AllowSorting属性为True.我已经成功实现了这个GridView的手动排序.

但我不得不将网页翻译成我使用本地资源文件的其他语言.我在RowDataBound事件中更改了GridView列的Header文本.从那时起,我无法对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();

        }

    }

}
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能对列进行排序?任何帮助,将不胜感激.谢谢!

KhD*_*KhD 10

将代码更改为以下解决了问题:

          if (e.Row.RowType == DataControlRowType.Header) 
        { 
            LinkButton LnkHeaderText = e.Row.Cells[1].Controls[0] as LinkButton; 
            LnkHeaderText.Text = "Name"; 
        }
Run Code Online (Sandbox Code Playgroud)