I am having trouble reading the text property of TableCell in the following code from this tutorial. During debug I can see the Text value="Blue" but it's displaying "" in the string varible strColor. IDE is VS 2017, C#.net.
The Gridview has 6 columns total. The 2nd column contains text of a color e.g. "White", Blue", "Red", etc. and depending on the color that cells' backcolor should change to that color but their all white because of the empty value. What could be the problem?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCell cellColor = e.Row.Cells[1];
string strColor = cellColor.Text;
switch (strColor)
{
case "White":
//e.Row.BackColor = GetColor("White");//alt
cellColor.BackColor = Color.White;
break;
case "Green":
cellColor.BackColor = Color.Green;
break;
case "Blue":
cellColor.BackColor = Color.Blue;
break;
case "Red":
cellColor.BackColor = Color.Red;
break;
case "Yellow":
cellColor.BackColor = Color.Yellow;
break;
case "Purple":
cellColor.BackColor = Color.Purple;
break;
default:
cellColor.BackColor = Color.White;
break;
}
}
}