Filling a dropdownlist?
how to fill a dropdownlist?
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
brian dobosh9 reputationPosted Dec 6, 2007, 5:33 AM EST
example:
comboBox1.Items.Add("Item 1");
comboBox1.Items.Add("Item 2");
swarna2 reputationPosted Dec 6, 2007, 5:37 AM EST
Raj KumarRank #25 · 44.2K reputationPosted Dec 18, 2007, 6:19 PM EST
Private Sub FillDropDownList()
Dim ObjDataSet as DataSet = Helper.FillDropDownList()
If Not Object.Equals(ObjDataSet, Nothing) Then
If ObjDataSet.Tables(0).Rows.Count > 0 Then
DropDownList.DataValueField = "Name"
DropDownList.DataTextField = "Name"
DropDownList.DataSource = ObjDataSet.Tables(0)
DropDownList.DataBind()
End If
End Sub
Here Name is column name which you want to fill in dropdown list. i hope this will help you.
David Johnson24 reputationPosted Jun 26, 2008, 7:23 PM EDT
control = (DropDownList)controlRow.FindControl(ControlName);
foreach(object choice in SomeChoiceCollectionObject)
{
ListItem item = new ListItem(choice.Name, choice.ID.ToString());
control.Items.Add(item);
}