First of all: Is the datatable filled with any data?
Second: you are trying to fill that one row (given in the event args) with all the colors from the datatable, resulting in that only one property (e.Row.Cells[0].BackColor
) is filled with the color coming from the last row in the table (dtMyList.Rows[i]["Color"]
).
I think you should first lookup the correct datarow which is attached to your gridrow (e.Row.DataItem
), then read its color and then fill the property of your gridrow. Like this:
protected void grdMyList_RowDataBound(object sender, GridViewEventsArgs e)
{
DataRow row = (DataRow)e.Row.DataItem;
e.Row.Cells[0].BackColor = System.Drawing.Color.FromName(row["Color"].ToString());
}