Wednesday, 29 February 2012

.Net Beginners : How to populate DropDownList/ListBox from the datasource?

There is datasource property of DropDownList/ListBox which you need to assign and after that you call DataBind method that will bind the data.

Example :
 ddlProduct.DataSource = dtDataTable
 ddlProduct.DataBind()

In this example we are using ddlProduct DropDownList control.
In which we are assigning DataTable as datasource. dtDataTable is a DataTable.
We can also use various datasource like collection of object , Linq object etc...

No comments:

Post a Comment