[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Modify DataGrid cell color based on value from another cell

Posted on 2005-04-26
4
Medium Priority
?
271 Views
Last Modified: 2010-04-07
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)
End Sub

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!
0
Comment
Question by:CoastalData
  • 2
3 Comments
 
LVL 3

Author Comment

by:CoastalData
ID: 13869844
Hey, I answered my own question! Here's the code that I ended up using:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
      Dim strColor As String = e.Item.Cells(5).Text
      Dim r, g, b As String
      r = (e.Item.Cells(1).Text)
      g = (e.Item.Cells(3).Text)
      b = (e.Item.Cells(2).Text)
      Try
            e.Item.Cells(0).BackColor = Color.FromArgb(r, g, b)
      Catch ex As Exception
      End Try
End Sub

I discovered I was using the wrong event, and also went to using r, g, and b values seperately.

Thanks any how!!!!
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 14080845
PAQed with points refunded (400)

modulo
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question