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. DropDownList coloring in ASP.Net

DropDownList coloring in ASP.Net

Scheduled Pinned Locked Moved ASP.NET
csharpjavascriptasp-nethelptutorial
4 Posts 3 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.
  • C Offline
    C Offline
    coolestCoder
    wrote on last edited by
    #1

    Hi, Is it possible to color individual items of a DropDownList box in ASP.Net? I tried the Attributes collection, but it didnt worked. If there is any other way to do the same, i would be interested in knowing. ( even if it is in javascript no problem !) I will elaborate what i actually want--- If i have some items in my DropDownList as--- ABC XYZ PQR ASDFG SDFKJ These entries will be in some logical groups. Accordingly i want to color those entries with different back colors for items in one group-- For example, ABC, XYZ will go with back color = Red, PQR with back color = Blue, etc...


    "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


    Anant Y. Kulkarni

    _ J 2 Replies Last reply
    0
    • C coolestCoder

      Hi, Is it possible to color individual items of a DropDownList box in ASP.Net? I tried the Attributes collection, but it didnt worked. If there is any other way to do the same, i would be interested in knowing. ( even if it is in javascript no problem !) I will elaborate what i actually want--- If i have some items in my DropDownList as--- ABC XYZ PQR ASDFG SDFKJ These entries will be in some logical groups. Accordingly i want to color those entries with different back colors for items in one group-- For example, ABC, XYZ will go with back color = Red, PQR with back color = Blue, etc...


      "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


      Anant Y. Kulkarni

      _ Offline
      _ Offline
      _AK_
      wrote on last edited by
      #2

      Probably this is what you want: http://www.codeproject.com/aspnet/HtmlColorDropDown.asp[^]

      Best Regards, Apurva Kaushal

      1 Reply Last reply
      0
      • C coolestCoder

        Hi, Is it possible to color individual items of a DropDownList box in ASP.Net? I tried the Attributes collection, but it didnt worked. If there is any other way to do the same, i would be interested in knowing. ( even if it is in javascript no problem !) I will elaborate what i actually want--- If i have some items in my DropDownList as--- ABC XYZ PQR ASDFG SDFKJ These entries will be in some logical groups. Accordingly i want to color those entries with different back colors for items in one group-- For example, ABC, XYZ will go with back color = Red, PQR with back color = Blue, etc...


        "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


        Anant Y. Kulkarni

        J Offline
        J Offline
        jitu gupta
        wrote on last edited by
        #3

        Hi Anant, this is the code which solve your problem. private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { strConn="Data Source=localhost;uid=sa;pwd=;Initial Catalog=northwind"; mycn = new SqlConnection(strConn); myda = new SqlDataAdapter ("Select * FROM CategoryTable ", mycn); ds = new DataSet(); myda.Fill (ds,"Table"); DropDownList1.DataSource =ds.Tables [0] ; DropDownList1.DataTextField =ds.Tables[0].Columns["CategoryName"].ColumnName.ToString(); DropDownList1.DataValueField =ds.Tables[0].Columns["CategoryId"].ColumnName.ToString(); DropDownList1.DataBind () ; for (int i =0;i < DropDownList1.Items.Count ;i++ ) { DropDownList1.Items[i].Attributes.Add("style", "color:" + ds.Tables[0].Rows[i]["CategoryColor"].ToString () ); } } } Hope this will solve your problem. please let me know if any problem arise bye

        C 1 Reply Last reply
        0
        • J jitu gupta

          Hi Anant, this is the code which solve your problem. private void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { strConn="Data Source=localhost;uid=sa;pwd=;Initial Catalog=northwind"; mycn = new SqlConnection(strConn); myda = new SqlDataAdapter ("Select * FROM CategoryTable ", mycn); ds = new DataSet(); myda.Fill (ds,"Table"); DropDownList1.DataSource =ds.Tables [0] ; DropDownList1.DataTextField =ds.Tables[0].Columns["CategoryName"].ColumnName.ToString(); DropDownList1.DataValueField =ds.Tables[0].Columns["CategoryId"].ColumnName.ToString(); DropDownList1.DataBind () ; for (int i =0;i < DropDownList1.Items.Count ;i++ ) { DropDownList1.Items[i].Attributes.Add("style", "color:" + ds.Tables[0].Rows[i]["CategoryColor"].ToString () ); } } } Hope this will solve your problem. please let me know if any problem arise bye

          C Offline
          C Offline
          coolestCoder
          wrote on last edited by
          #4

          Hi,

          jitu gupta wrote:

          DropDownList1.Items[i].Attributes.Add("style", "color:" + ds.Tables[0].Rows[i]["CategoryColor"].ToString () );

          Thats what i wanted. Thanks.


          "A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder


          Anant Y. Kulkarni

          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