How to set Backcolor in cells of Dynamically Created Tables in ASP.NET

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • davidson1
    New Member
    • Feb 2008
    • 144

    How to set Backcolor in cells of Dynamically Created Tables in ASP.NET

    Hai Friends,

    I have the following code for Dynamically Created Tables, I have created the panel in the webform.......

    Dim tab5 As New Table
    Dim row1 As New TableRow

    Dim cell1 As New TableCell
    cell1.Text = "Java"
    row1.Cells.Add( cell1)


    Dim cell2 As New TableCell
    cell2.Text = "C++"
    row1.Cells.Add( cell2)

    tab5.Rows.Add(r ow1)
    panel1.Controls .Add(tab5)

    it works properly , But the Proplem is i cant give backcolor for Cell in this format #FFFFFFF,#66CCF F etc

    when i give like this

    cell2.Backcolor ="#FFFFFFF"

    it shows as Error....

    I have to give color in this Format #FFFFFFF,#66CCF F etc

    Pl Help Me

    Thanks in Advance........ ...........

    Posted Date :- 29 Feb 2008

    Davidson
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Those numbers are just the hex version of your color. (Red Green Blue values). Just create a Color object using those values and assign it to the back color.

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      Originally posted by Plater
      Those numbers are just the hex version of your color. (Red Green Blue values). Just create a Color object using those values and assign it to the back color.
      Alternatively you could use something akin to:
      Code:
      MyTable.Row(n).BackColor = System.Drawing.ColorTranslator.FromHtml("#C0C0C0")
      Should do the job...

      Comment

      • SharpDeveloper
        New Member
        • Feb 2008
        • 12

        #4
        Hi Davidson
        Try this out
        cell2.BackColor = Drawing.ColorTr anslator.FromHt ml("#C3E4F9")
        Hope this helps

        Originally posted by davidson1
        Hai Friends,

        I have the following code for Dynamically Created Tables, I have created the panel in the webform.......

        Dim tab5 As New Table
        Dim row1 As New TableRow

        Dim cell1 As New TableCell
        cell1.Text = "Java"
        row1.Cells.Add( cell1)


        Dim cell2 As New TableCell
        cell2.Text = "C++"
        row1.Cells.Add( cell2)

        tab5.Rows.Add(r ow1)
        panel1.Controls .Add(tab5)

        it works properly , But the Proplem is i cant give backcolor for Cell in this format #FFFFFFF,#66CCF F etc

        when i give like this

        cell2.Backcolor ="#FFFFFFF"

        it shows as Error....

        I have to give color in this Format #FFFFFFF,#66CCF F etc

        Pl Help Me

        Thanks in Advance........ ...........

        Posted Date :- 29 Feb 2008

        Davidson

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          Code:
          System.Drawing.ColorTranslator.FromHtml()
          Learn something new everyday.

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            Originally posted by Plater
            Code:
            System.Drawing.ColorTranslator.FromHtml()
            Learn something new everyday.
            ;o) Glad to inform...hehe

            Comment

            Working...