ASP.NET Gridview - setting column header's css class from code behind?
Hey guys, what I am trying to do is add a method to my gridview's sorting event to add a class to the column being sorted so the user can know if the data is being sorted ascending or descending and on what column. I am currently trying to do it through a switch statement on the sort expression to determine what column it's coming from but开发者_C百科 I am unaware of how to set the css class. Any ideas?
I got it working, turns out I was over thinking it but the task is easily accomplished via:
gridview.HeaderRow.Cells[0].CssClass = "sorted" + sortString;
You can add the styles to the gridview columns using this sample codes:
// Add styles to table
foreach (GridViewRow row in GridViewSample.Rows)
{
GridViewSample.HeaderRow.Cells[2].CssClass = "text-center";
GridViewSample.HeaderRow.Cells[3].CssClass = "text-center";
if (row.RowType == DataControlRowType.DataRow)
{
row.Cells[2].CssClass = "text-center";
row.Cells[3].CssClass = "text-center";
}
}
精彩评论