After the Blazor Grid has loaded
How does one loop through rows and change the row background color based on a value in the row?
Using the following rules.
var oldRecord = string.Empty;
var myFlip = false;
for(int i = 0; i < DataGrid.Rows.Count - 1; i++)
if(oldRecord != DataGrid.Rows[i].Cells.Text)
oldRecord = DataGrid.Rows[i].Cells.Text;
myFlip = !myFlip;
for(int j = 0; j < DataGrid.Rows[i].Cells.Count - 1; j++)
DataGrid.Rows[i].Cells[j].Style.BackColor = myFlip ? "#ffffff" : "#c8eaea";
Greetings from Syncfusion support.
You want to change the background color based on the value in the row. We have prepared a sample for you based on the rules described in the forum, and we will validate your query. To achieve your requirement, we can use the RowDataBound event. We have similar documentation in our UG documentation section. Please refer to the attached sample and UG documentation link for more information.
Please let us know if you have any concerns.
Thanks for the sample grid and It looks good and should work for us.
Is the method RowBound called sequentially? Meaning the first time it is called, we are on row 1 and the next time, we are on row 2 and so on?
Query:” Is the method RowBound called sequentially?”
Regarding your question, the RowDataBound event is raised for each row in the data grid and is called sequentially in the order of the rows in the data source. This event triggers every time a request is made to access row information, element, or data and before the row element is appended to the DataGrid element. Kindly refer to the UG documentation for your reference.
I got this to work, thanks.
We are glad to hear that your query has been resolved .
Please get back to us if you need further assistance.