Changing BackColor in a cell of Hyperlink Column
-
I have a datagrid bound to a datatable containing 10 columns. 6 of the 10 columns are added to the table dynamically and contain the text "Gap", "Met", "Shortfall", "Not_Eval". These 6 columns are hyperlink columns, with the textField set to the appropriate column. I get back hyperlinked Gap, Met, etc.... SO I know that part is working fine. In the Page_Load event, after building the table and setting the grid data source, I execute this code. I am trying to set the cell back color to red, green, yellow or slate blue, depending on the Cell.Text value. Even though the Hyperlink text is displayed correctly, the cell.text is "". Here is the code. Color gap = Color.Red; Color shortFall = Color.Yellow; Color met = Color.Green; Color notEvaluated = Color.SlateBlue; Color duplicate = Color.Orange; foreach(DataGridItem item in Datagrid1.Items) { int taskId = int.Parse( item.Cells[0].Text); for(int i = 3;i < 10;i++) { TableCell cell = item.Cells[i]; switch(cell.Text) { case "Gap": cell.BackColor = gap; break; case "Met": cell.BackColor = met; break; case "Shortfall": cell.BackColor = shortFall; break; case "Not_Eval": cell.BackColor = notEvaluated; cell.ForeColor = notEvaluated; break; } } } I guess it is obvious that the hyperlink text is not the same property as the Cell.text, but I don't know what else to evaluate. I have looked, to no avail. Any help would be appreciated. TF
-
I have a datagrid bound to a datatable containing 10 columns. 6 of the 10 columns are added to the table dynamically and contain the text "Gap", "Met", "Shortfall", "Not_Eval". These 6 columns are hyperlink columns, with the textField set to the appropriate column. I get back hyperlinked Gap, Met, etc.... SO I know that part is working fine. In the Page_Load event, after building the table and setting the grid data source, I execute this code. I am trying to set the cell back color to red, green, yellow or slate blue, depending on the Cell.Text value. Even though the Hyperlink text is displayed correctly, the cell.text is "". Here is the code. Color gap = Color.Red; Color shortFall = Color.Yellow; Color met = Color.Green; Color notEvaluated = Color.SlateBlue; Color duplicate = Color.Orange; foreach(DataGridItem item in Datagrid1.Items) { int taskId = int.Parse( item.Cells[0].Text); for(int i = 3;i < 10;i++) { TableCell cell = item.Cells[i]; switch(cell.Text) { case "Gap": cell.BackColor = gap; break; case "Met": cell.BackColor = met; break; case "Shortfall": cell.BackColor = shortFall; break; case "Not_Eval": cell.BackColor = notEvaluated; cell.ForeColor = notEvaluated; break; } } } I guess it is obvious that the hyperlink text is not the same property as the Cell.text, but I don't know what else to evaluate. I have looked, to no avail. Any help would be appreciated. TF
-
You're a Goddess! It is Control[0] BTW. Added this line of code: HyperLink hlcell = (HyperLink) cell.Controls[0]; switch(hlCell.Text) {.....} Thanks again. TF