Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Changing BackColor in a cell of Hyperlink Column

Changing BackColor in a cell of Hyperlink Column

Scheduled Pinned Locked Moved ASP.NET
csshelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tim Featherston
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • T Tim Featherston

      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

      M Offline
      M Offline
      Marcie Jones
      wrote on last edited by
      #2

      Hi Tim, You can get the hyperlink text by using (Hyperlink)cell.Controls[1]).Text. (It might by Controls[0], I can't remember. Hope that helps! Marcie CP Blog[^]

      T 1 Reply Last reply
      0
      • M Marcie Jones

        Hi Tim, You can get the hyperlink text by using (Hyperlink)cell.Controls[1]).Text. (It might by Controls[0], I can't remember. Hope that helps! Marcie CP Blog[^]

        T Offline
        T Offline
        Tim Featherston
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups