Conditional changing the backcolor of a DataGrid column
-
Hello. I have a DataGrid which columns bind to columns in a DataSet. What I want to do is changing the backcolor of the Cell in Column 'A' if it has the value '1'. The definition of my DataGrid is as follows: Column 'A' can have values of '1' or '2'. For the items with the value '1' I want to change it's backcolor. Is there an easy way to accomplish this? Thanks.
-
Hello. I have a DataGrid which columns bind to columns in a DataSet. What I want to do is changing the backcolor of the Cell in Column 'A' if it has the value '1'. The definition of my DataGrid is as follows: Column 'A' can have values of '1' or '2'. For the items with the value '1' I want to change it's backcolor. Is there an easy way to accomplish this? Thanks.
Hi there, You simply create an event handler for the ItemDataBound event of the datagrid, and in the handler you can check which value is bound to the column A then you can decide the backcolor for the Cell. You can also use a data binding expression to do that. Btw, next time you should remember to select the "Do not ..." checkbox, otherwise people cannot see the format of the datagrid.
-
Hi there, You simply create an event handler for the ItemDataBound event of the datagrid, and in the handler you can check which value is bound to the column A then you can decide the backcolor for the Cell. You can also use a data binding expression to do that. Btw, next time you should remember to select the "Do not ..." checkbox, otherwise people cannot see the format of the datagrid.
-
Thank you very much for your help. It was quite easy with the ItemDataBound event handler. But how can I do it with the databinding expression? (i guess that you mean code inside the aspx file, in the control's arguments)
Yes, by the the data binding expression I mean you can use the inline code inside the .aspx web page. You can take a look at the syntax from here: Data Binding Expression Syntax[^] You can provide a snippet of code to check the data bound value in the expression or simply make a call to a method which is responsible for checking that for you. The method can be defined in the code-behind or the .aspx page.