Friday, September 10, 2010

Example on filling arraylist to dropdown list

by Narendra, .Net Developer

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title> How to fill dropdownlist using Array list</title>

</head>


<body>
<form id="form1" runat="server">
<div>
<asp:Label ID ="lblexddl" text=" Example on filling arraylist to dropdown list" runat="server" ></asp:Label>
<br />
<asp:DropDownList ID="ddl" runat="server" ForeColor="BlueViolet" Font-Bold="true"
Font-Size="Medium" ></asp:DropDownList>
<br />
<asp:GridView ID="GV" runat="server" ></asp:GridView>

</div>
</form>
</body>
</html>
===
protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
// adding items to arraylist
ArrayList orderarraylist = new ArrayList();
orderarraylist.Add("Product Id");
orderarraylist.Add("Product Name");
orderarraylist.Add("Category");
orderarraylist.Add("Stock");


//Binding the atrraylist to dropdownlist
ddl.DataSource = orderarraylist;
ddl.DataBind();


}
}

No comments:

Post a Comment