How to fill several comboboxes with for loop?
-
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()
-
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()
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 () ); } } }
-
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 () ); } } }
Please use <pre> tags around code!
Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman