|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Default Value in on Databound Drop Down listHello,
I am populating a drop down list control with a table from a database. I would like the control to display a value such as --- select --- when it first comes up, instead of any values from the table. Is there a way to do this without putting the value --- Select --- in the actual table? Regards, Randy. Yes, after calling the Databind() method, use the use the Items.Insert()
method. Here is an example: MyDropDown.DataBind() MyDropDown.Items.Insert(0,"--- Select ---") This inserts an extra ListItem before index 0, therefore changing what was previously index 0 into index 1, index 1 into index 2, etc. Since this is only 1 extra line of code, it is very little extra work, and makes it the first ListItem regardless of what is in the database. Hopefully this helps. Show quote "Randy Galliano" <randy.galli***@thegallianos.com> wrote in message news:ukWS3p%23HIHA.1324@TK2MSFTNGP06.phx.gbl... > Hello, > > I am populating a drop down list control with a table from a database. I > would like the control to display a value such as --- select --- when it > first comes up, instead of any values from the table. Is there a way to > do this without putting the value --- Select --- in the actual table? > > Regards, > > Randy. Thank you so much. That worked very well. I put it in the Page_Load
event so I also added a check for ispostback. Regards, Randy. Nathan Sokalski wrote: Show quote > Yes, after calling the Databind() method, use the use the Items.Insert() > method. Here is an example: > > MyDropDown.DataBind() > MyDropDown.Items.Insert(0,"--- Select ---") > > This inserts an extra ListItem before index 0, therefore changing what was > previously index 0 into index 1, index 1 into index 2, etc. Since this is > only 1 extra line of code, it is very little extra work, and makes it the > first ListItem regardless of what is in the database. Hopefully this helps. |
|||||||||||||||||||||||