|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
add a list item to a bound controlHi,
I have a drop down list thats bound to a SQL query. But I want to have the top item or .SelectedItem to be a generic "Please Select..." with no value. I've searched for the answer and tried every combination and can't find an answer. I've tried adding <ASP:ListItem> to the control but the bound data overides it. I'm using .NET with VB, Any suggestions? Blackstar,
Sql put "Please Select..." as the first result in the querry result. or manipulate list manually in the list data bound event. Good Luck DWS Show quoteHide quote "blackstaronline.net" wrote: > Hi, > > I have a drop down list thats bound to a SQL query. But I want to have > the top item or .SelectedItem to be a generic "Please Select..." with > no value. I've searched for the answer and tried every combination and > can't find an answer. > > > I've tried adding <ASP:ListItem> to the control but the bound data > overides it. > > > I'm using .NET with VB, Any suggestions? > > Hi,
if you use .NET 2.0, you can specify the <asp:ListItem> and then just set AppendDataBoundItems="True", when items added with databinding would be appended to the end. You can also do it in code DropDownList1.Items.Insert(0,New ListItem("Text","Value")) Show quoteHide quote "blackstaronline.net" <jr***@blackstaronline.net> wrote in message news:1139943696.551811.70110@o13g2000cwo.googlegroups.com... > Hi, > > I have a drop down list thats bound to a SQL query. But I want to have > the top item or .SelectedItem to be a generic "Please Select..." with > no value. I've searched for the answer and tried every combination and > can't find an answer. > > > I've tried adding <ASP:ListItem> to the control but the bound data > overides it. > > > I'm using .NET with VB, Any suggestions? > That worked perfectly. Thank you so much!
For anyone else having the same problem, all I did is add 1 line of code directly after binding the data to the control. It now looks like this; Dim objCmd as New SQLCommand(strSQL, objConn) objConn.Open() With DD_Design .DataTextField = "CompanyName" .DataValueField = "CompanyCode" .DataSource = objCmd.ExecuteReader(CommandBehavior.CloseConnection) .DataBind() .Items.Insert(0,New ListItem("Please Select...","")) End With Thanks again Teemu, Jeremy Reid http://blackstaronline.net/hgtit
CustomValidator is not firing
Checkbox in datagrid.... How to read value of a dynamically created radiobuttonlist control? DataGrid Functionality Questions Checkbox state after postback Dynamic checkbox loses checked state Best way to have multiple pages show up as same selection on menu cancel toolbar buttonclick from client-side javascript asp:Repeater + no viewstate + DataBind() ?? Looking for graphic control to use in .NET |
|||||||||||||||||||||||