Modify DataGrid cell color based on value from another cell
Posted on 2005-04-26
Hello, there are several similar postings on this subject, but I was not able to glean a solution for my own project from them.
What I am doing is building a simple database / asp.net app for a college course which sorts the named web-safe colors by red, then green, then blue.
Being new to asp.net, I tried to use the "ItemCreated" event of the datagrid, like this:
Private Sub DataGrid1_ItemCreated(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemCreated
Dim dgi As DataGrid = sender
Dim c As Color
Dim strColor As String
strColor = e.Item.Cells(5).Text
Response.Write(strColor & "<BR>")
e.Item.Cells(1).BackColor = c.FromName(strColor)
But the problem is that strColor only gets a value from the first iteration, which is the header cell. What it's supposed to do is to take the color name from column #5, and assign it to column #1, which is just so that you can see the color in the datagrid.
If need be, I could instead use an RGB value from another cell, as that's available, too, from the database that populates the grid.
Or am I going about this wrong? The object is "web safe colors", but I noticed that my list is very similar to the colors in the System.Drawing.Colors Members list... Could I enumerate them, instead?
This project is not a direct assignment, so I'm not cheating by asking you to do my homework, but I'm offering 400 points because I do need understand this better!
Thanks in advance!