dropdownlist initial value

D

DC Gringo

I have a dropdownlist that is bound to a recordset. The default selected
item has turned out to be the first record in my table. I need a row that
has value = 0 and text showing "--ALL".

How can I do this?

<asp:dropdownlist id="Provinces" runat="server" Font-Size="8pt"
Width="100px"></asp:dropdownlist>

Sub BindData()

Dim myDataSet5 As New DataSet
Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
ddlCommunities.DataMember = "CommunitiesT2"
ddlCommunities.DataTextField = "clnName"
ddlCommunities.DataValueField = "clnGUID"
ddlCommunities.DataBind()

End Sub
 
C

Carlos Campos

If I am not wrong you can use the DropDownList.Insert to add the ALL item at
position 0. You can do it after databind()
 
T

Teemu Keiski

After call to ddlCommunities.DataBind() do:

ddlCommunities.Items.Insert(0,New ListItem("--ALL","0"))

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


I have a dropdownlist that is bound to a recordset. The default selected
item has turned out to be the first record in my table. I need a row that
has value = 0 and text showing "--ALL".

How can I do this?

<asp:dropdownlist id="Provinces" runat="server" Font-Size="8pt"
Width="100px"></asp:dropdownlist>

Sub BindData()

Dim myDataSet5 As New DataSet
Dim myDataAdapter5 As New SqlDataAdapter(_sqlStmt5, conString)
myDataAdapter5.Fill(myDataSet5, "CommunitiesT2")
ddlCommunities.DataSource = myDataSet5.Tables("CommunitiesT2")
ddlCommunities.DataMember = "CommunitiesT2"
ddlCommunities.DataTextField = "clnName"
ddlCommunities.DataValueField = "clnGUID"
ddlCommunities.DataBind()

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top