开发者

GridView sorting with additional functions

I have a GridView which is bound automaticaly to a SqlDataSource. I have a function which goes thru the GridView and colors red certain cells according to their content. I also enabled sorting on the GridView on all columns. When the page first loads the function coloring appropriate cells works. When I cl开发者_StackOverflowick the column header to sort, it sorts, but the cells that should be colored doen't get colored. I tried putting the call to the coloring function in the Page_Load in an if(isPostBack) condition and I tried using the GridView_Sorted event putting the call to the coloring function in there. None of that worked. I also tried adding GridView1.DataBind() in both the Page_Load and GridView_Sorted events before calling the coloring function and after. In all scenarios sorting worked but coloring did not! How can I get both sorting and coloring working? Thank you.


To enable accepting the answer, i copy my comment here:

Put your coloring logic into GridView's RowDataBound event.


Put the coloring in the OnRowDataBound event.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.ForeColor = Color.Red;
    e.Row.Cells[0].ForeColor = Color.Red;
}

Coloring the cells this way, it will happen during the databinding.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜