Saturday 8 September 2012

Beginning .Net : Fill dropdownlist or combobox manually C# Examples and VB.Net Examples

There is a need in website that you want to add items manually in dropdownlist or combobox.
You can achieve this using "Items.Add" methods of dropdownlist.

Here is example for this.
In this example we take one dropdownlist control name "ddlProductList". We fill this dropdownlist manually from coding.

ASPX Code :
<b>Product List :</b>  <asp:DropDownList runat="server" ID="ddlProductList"></asp:DropDownList>


 C# Examples :
        ddlProductList.Items.Add(new ListItem("[select]", "-1"));
        ddlProductList.Items.Add(new ListItem("CPU", "1"));
        ddlProductList.Items.Add(new ListItem("LCD", "2"));
        ddlProductList.Items.Add(new ListItem("LED", "3"));

VB.net Example :
        ddlProductList.Items.Add(New ListItem("[select]", "-1"))
        ddlProductList.Items.Add(New ListItem("CPU", "1"))
        ddlProductList.Items.Add(New ListItem("LCD", "2"))
        ddlProductList.Items.Add(New ListItem("LED", "3"))

Output :
For Beginning .Net articles. Click Here...

This type of C# Tips is very useful in day to day programming life.

Note : Give Us your valuable feedback in comments. Give your suggestions in this article so we can update our articles accordingly that.



No comments:

Post a Comment