Hi everyone
Can someone please give me an example on how to code a drop down list using the source code in c#.
Thanks!
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
KalaiPosted Mar 7, 2014, 4:03 AM
ddl.Items.Add(new ListItem("--Select--", "0"));
ddl.Items.Add(new ListItem("India", "In"));
ddl.Items.Add(new ListItem("Europe", "Eu"));
ddl.Items.Add(new ListItem("Iran", "Ir"));
ddl.Items.Add(new ListItem("Afghanistan", "Af"));
ddl.SelectedValue = "Ir";
Julius MnisiPosted Mar 7, 2014, 3:55 AM
Lets say you want to use Laptops as your items this is an example of how you can code
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddllaps" runat="server">
<asp:ListItem>select a laptopasp:ListItem>
<asp:ListItem>Samsungasp:ListItem>
<asp:ListItem>Acerasp:ListItem>
<asp:ListItem>Lenovoasp:ListItem>
<asp:ListItem>Appleasp:ListItem>
<asp:ListItem>LGasp:ListItem>
<asp:ListItem>asp:ListItem>
asp:DropDownList>