Gridview Eval function from code behind
I'd like to avoid having an e开发者_运维问答val statement in each of the boundfields in the aspx page. Is there a way, perhaps at databind time, to evaluate the data in the code behind file instead? For instance, I'd like to display a blank if the actual data is 0.
Thanks.
This is achieved by handling RowDataBound event which is called right after the data is bound to each row in the grid view.
Check my answer in this post Change cell color on different values
You could change these lines to something that suites your needs
if(e.Row.Cells[0].Text == "ABC")
e.Row.Cells[0].BackColor = Color.Red;
Maybe those would be
if(e.Row.Cells[0].Text == "0")
e.Row.Cells[0].Text = string.Empty;
Look here for more information on RowDataBound event: More info
精彩评论