Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gridview sorting when Header text changed in RowDataBound event

I have a GridView on my webpage whose DataSource is a DataTable which is populated at runtime. AllowSorting property of GridView is True. I have successfully implemented manual sorting for this GridView.

But I had to translate the webpage to other languages for which I used local resource files. I changed the Header text of GridView columns in RowDataBound event. Since then I'm unable to sort the 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();

        }

    }

}

What should I do to enable sorting for the columns? Any help would be appreciated. Thanks!

like image 636
KhD Avatar asked Sep 27 '11 07:09

KhD


1 Answers

Changing the code to below solved the problem:

          if (e.Row.RowType == DataControlRowType.Header) 
        { 
            LinkButton LnkHeaderText = e.Row.Cells[1].Controls[0] as LinkButton; 
            LnkHeaderText.Text = "Name"; 
        }
like image 69
KhD Avatar answered Sep 22 '22 15:09

KhD