开发者

ASP.NET Gridview - setting column header's css class from code behind?

开发者 https://www.devze.com 2022-12-17 19:04 出处:网络
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

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";
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号