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. Alternating colors in dynamic datagrid

Alternating colors in dynamic datagrid

Scheduled Pinned Locked Moved ASP.NET
helpquestion
4 Posts 3 Posters 2 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.
  • R Offline
    R Offline
    rodmul
    wrote on last edited by
    #1

    How is it possible to alternate row colors in a dynamically created datagrid. Please help:rose::rose::rose::rose::rose::rose: A ding is a gind to a _W_H_A_T_ if a dong is a dang to a gand? -- modified at 8:46 Thursday 22nd December, 2005

    M P 2 Replies Last reply
    0
    • R rodmul

      How is it possible to alternate row colors in a dynamically created datagrid. Please help:rose::rose::rose::rose::rose::rose: A ding is a gind to a _W_H_A_T_ if a dong is a dang to a gand? -- modified at 8:46 Thursday 22nd December, 2005

      M Offline
      M Offline
      minhpc_bk
      wrote on last edited by
      #2

      You cannot specify the color for the alternating items using the AlternatingItemStyle property at runtime since you can only sepcify it at design time. To programmatically change the color of an item, you simply create an event handler for the ItemCreated event and change the color of the alternating item. The sample code looks like this:

      private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
      if(e.Item.ItemType == ListItemType.Item)
      {
      e.Item.BackColor = System.Drawing.Color.Blue;
      }
      else if(e.Item.ItemType == ListItemType.AlternatingItem)
      {
      e.Item.BackColor = System.Drawing.Color.Green;
      }
      }

      For more information, see DataGridItem Members[^]

      R 1 Reply Last reply
      0
      • M minhpc_bk

        You cannot specify the color for the alternating items using the AlternatingItemStyle property at runtime since you can only sepcify it at design time. To programmatically change the color of an item, you simply create an event handler for the ItemCreated event and change the color of the alternating item. The sample code looks like this:

        private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
        if(e.Item.ItemType == ListItemType.Item)
        {
        e.Item.BackColor = System.Drawing.Color.Blue;
        }
        else if(e.Item.ItemType == ListItemType.AlternatingItem)
        {
        e.Item.BackColor = System.Drawing.Color.Green;
        }
        }

        For more information, see DataGridItem Members[^]

        R Offline
        R Offline
        rodmul
        wrote on last edited by
        #3

        Thanks very much. Works a treat and I can see it opens the door to even further customization. Excellent.:-D A ding is a gind to a _W_H_A_T_ if a dong is a dang to a gand?

        1 Reply Last reply
        0
        • R rodmul

          How is it possible to alternate row colors in a dynamically created datagrid. Please help:rose::rose::rose::rose::rose::rose: A ding is a gind to a _W_H_A_T_ if a dong is a dang to a gand? -- modified at 8:46 Thursday 22nd December, 2005

          P Offline
          P Offline
          PavanPareta
          wrote on last edited by
          #4

          You did'nt mantion Any condition in this Question you have to spacify programatically Thanks

          Pavan Pareta

          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