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. How to fill several comboboxes with for loop?

How to fill several comboboxes with for loop?

Scheduled Pinned Locked Moved ASP.NET
tutorialquestion
3 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.
  • S Offline
    S Offline
    symeramon
    wrote on last edited by
    #1

    Hi there all, Can you please tell me how to fill several comboboxes with for loop??? Need something like above... I have a string list with names of my comboboxes (combolar)... Thanks in advance...

    (AjaxControlToolkit.ComboBox)this.Page.FindControl(combolar.ElementAt(t)).Items.Add()

    S 1 Reply Last reply
    0
    • S symeramon

      Hi there all, Can you please tell me how to fill several comboboxes with for loop??? Need something like above... I have a string list with names of my comboboxes (combolar)... Thanks in advance...

      (AjaxControlToolkit.ComboBox)this.Page.FindControl(combolar.ElementAt(t)).Items.Add()

      S Offline
      S Offline
      Satheesh1546
      wrote on last edited by
      #2

      Hi, 1.Create a dataset. 2. Populate the dropdown list through the dataset. SqlConnection mycn; SqlDataAdapter myda; DataSet ds; String strConn; 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 () ); } } }

      L 1 Reply Last reply
      0
      • S Satheesh1546

        Hi, 1.Create a dataset. 2. Populate the dropdown list through the dataset. SqlConnection mycn; SqlDataAdapter myda; DataSet ds; String strConn; 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 () ); } } }

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Please use <pre> tags around code!

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        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