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. color of Drop down list remove on post back...

color of Drop down list remove on post back...

Scheduled Pinned Locked Moved ASP.NET
question
4 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.
  • G Offline
    G Offline
    Gaurav K Singh
    wrote on last edited by
    #1

    I uses the following code to dynamic fill the dropdownlist and forecolor of list item is set, it show good when first time load, but the style removes when the page postback...Any suggestion? The code i use to fill dropdownlist is following... Try cnn.Open() myreader = cmd.ExecuteReader() While myreader.Read() lst = New ListItem(myreader.GetValue(0).ToString().Trim(), myreader.GetValue(1).ToString().Trim()) If myreader.GetValue(2).ToString().Trim() = 0 Then lst.Attributes.Add("style", "color:Red") Else lst.Attributes.Add("style", "color:Green") End If ddl.Items.Add(lst) End While ddl.DataBind() Catch ex As Exception Throw New Exception(ex.Message) Finally cnn.Close() End Try

    The miracle is this--the more we share, the more we have.

    A 1 Reply Last reply
    0
    • G Gaurav K Singh

      I uses the following code to dynamic fill the dropdownlist and forecolor of list item is set, it show good when first time load, but the style removes when the page postback...Any suggestion? The code i use to fill dropdownlist is following... Try cnn.Open() myreader = cmd.ExecuteReader() While myreader.Read() lst = New ListItem(myreader.GetValue(0).ToString().Trim(), myreader.GetValue(1).ToString().Trim()) If myreader.GetValue(2).ToString().Trim() = 0 Then lst.Attributes.Add("style", "color:Red") Else lst.Attributes.Add("style", "color:Green") End If ddl.Items.Add(lst) End While ddl.DataBind() Catch ex As Exception Throw New Exception(ex.Message) Finally cnn.Close() End Try

      The miracle is this--the more we share, the more we have.

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Why dont you apply the style again... Use if(IsPostBack) ddl.Style.Add(HtmlTextWriterStyle.Color,"red") :thumbsup:

      Abhishek Sur


      My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

      **Don't forget to click "Good Answer" if you like to.

      G 1 Reply Last reply
      0
      • A Abhishek Sur

        Why dont you apply the style again... Use if(IsPostBack) ddl.Style.Add(HtmlTextWriterStyle.Color,"red") :thumbsup:

        Abhishek Sur


        My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

        **Don't forget to click "Good Answer" if you like to.

        G Offline
        G Offline
        Gaurav K Singh
        wrote on last edited by
        #3

        I applid color based on the flag if the flag value in database =0 then the item color will red and if flag value is 1 then item color will green?...

        The miracle is this--the more we share, the more we have.

        A 1 Reply Last reply
        0
        • G Gaurav K Singh

          I applid color based on the flag if the flag value in database =0 then the item color will red and if flag value is 1 then item color will green?...

          The miracle is this--the more we share, the more we have.

          A Offline
          A Offline
          Abhishek Sur
          wrote on last edited by
          #4

          yes .. then why dont you set the Database flag again during postback, and do set style accordingly.

          Abhishek Sur


          My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB

          **Don't forget to click "Good Answer" if you like to.

          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