Saturday, October 20, 2007

Dropdownlist - Binding Values, and setting a Value

1. To Bind Data to a DropDownList,
Data can be binded to a dropdownlist from , Arraylist or objectdatasource, and DataSource property can be used.

DropDownList1.Datasource=
DropDownList1.DataTextField= "UserName"
DropDownList1.DataValueField="UserID"
DropDownList1.DataBind()

2. To set values to a dropdown list from code, we have to use SelectedValue property of dropdown control

Dim strUserName as string ="Bill"
DropDownList1.SelectedValue=
DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(strUserName))



No comments: