473,396 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

dropdownlist initial value

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
--
_____
DC G
Nov 18 '05 #1
3 4843
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()

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
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
--
_____
DC G

Nov 18 '05 #2
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
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
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
--
_____
DC G

Nov 18 '05 #3
THANKS

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:eO*************@TK2MSFTNGP12.phx.gbl...
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
"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
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
--
_____
DC G

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second...
5
by: VMI | last post by:
My Web dropdownlist with AutoPostback equal to true has code in its SelectedIndexChanged Event . When I change the dropdownlist value and the SelectedIndexChanged Event is executed, the page does...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
0
by: Tand35006 | last post by:
Hi, I hope some one can help with this. I have a basic webform with 2 DropDownLists and a single DataGrid. What I am trying to do is populate the first DDList from a dataset on Form_Load. I then...
12
by: Frederik Vanderhaeghe | last post by:
Hi, I have a dropdownlist that contains should contain several values from the database, I fill it up in de page_load() with this code: If Not Page.IsPostBack Then InlezenConfig() Dim...
1
by: DJ | last post by:
I have a DropDownList in Visual Web Developer that is databound to a SQL Database. Whenever the web page is opened the DropDownList is automatically filled with the first item in the table. My...
1
by: Brent White | last post by:
I can't figure out what I'm doing differently with this one drop-down list control from the other two that are working just fine. Background: I am constructing a page that will allow a user to...
1
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
6
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.