set dropdownlist default value
-
Hi I ave a dropdownlist which is populated from a database However how do i set the default value of the dd as Select thanks in advance cheers
use the below code dd.Items.Insert(0, "Select"); Bhanu
-
use the below code dd.Items.Insert(0, "Select"); Bhanu
-
Hi Sorry that did not work, the value did not show in the dropdownlist Is it because I am using asp:sqldatasource to populate it? thanks so far:-)
Totaly depends where are you writing the suggested lines Could you provide the code after binding the datasource just insert select string at 0 index it's simple
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
Hi Sorry that did not work, the value did not show in the dropdownlist Is it because I am using asp:sqldatasource to populate it? thanks so far:-)
Write that line of code after binding the data to dropdownlist Bhanu
-
Hi I ave a dropdownlist which is populated from a database However how do i set the default value of the dd as Select thanks in advance cheers
If DataSet.Tables.Count > 0 Then dtTable = DataSet.Tables(0) objList = CType(drpDropDown, System.Web.UI.WebControls.DropDownList) With objList .Items.Clear() .DataValueField = "value" .DataTextField = "text" dtRow = dtTable.NewRow() dtRow(0) = -1 dtRow(1) = "--Select--" dtTable.Rows.InsertAt(dtRow, 0) .DataSource = DataSet .DataBind() End With
-
Hi Sorry that did not work, the value did not show in the dropdownlist Is it because I am using asp:sqldatasource to populate it? thanks so far:-)
If you are using SQLDataSource, I think you'll need to add the code provided in the Databound event of the dropdownlist
-
If you are using SQLDataSource, I think you'll need to add the code provided in the Databound event of the dropdownlist
i think no need to to have databound event just need to insert the string at perticular index
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
-
i think no need to to have databound event just need to insert the string at perticular index
Thanks and Regards Sandeep If If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything... "
sure, all you need is to insert the string at the particular index after the data binding have occured.With the databound event you can trap the binding process.
-
If DataSet.Tables.Count > 0 Then dtTable = DataSet.Tables(0) objList = CType(drpDropDown, System.Web.UI.WebControls.DropDownList) With objList .Items.Clear() .DataValueField = "value" .DataTextField = "text" dtRow = dtTable.NewRow() dtRow(0) = -1 dtRow(1) = "--Select--" dtTable.Rows.InsertAt(dtRow, 0) .DataSource = DataSet .DataBind() End With