473,378 Members | 1,571 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,378 software developers and data experts.

Dropdownlist default value

Scenario: i have a drop down list control in my form. i
am binding it with a dataset. that dataset contains the
value 1, 2, 3, ..., 10. so when the dropdownlist control
is loaded, it contain the values 1, 2, 3, ..., 10.

Problem: How do i create a default value for the
dropdownlist? After the dropdownlist control is loaded
and binded, i want the value to be "Select A Value", 1, 2,
3, ..., 10. I want to add "Select A value" in the
dropdownlist.

P.S. I am populating the dataset through a datareader
from a database call.

thanx for your help,
aymer
aymerb[@].yahoo.com
Nov 18 '05 #1
2 9363
Hi,
This should work
Dim Item As ListItem = new ListItem()
Item.Text = "Select A Value"
Item.Value = 0
Item.Selected = True
MyDropDownList.Items.Add(Item)

Regards,
Ivan Zashev

"Aymer" <an*******@discussions.microsoft.com> wrote in message
news:07****************************@phx.gbl...
Scenario: i have a drop down list control in my form. i
am binding it with a dataset. that dataset contains the
value 1, 2, 3, ..., 10. so when the dropdownlist control
is loaded, it contain the values 1, 2, 3, ..., 10.

Problem: How do i create a default value for the
dropdownlist? After the dropdownlist control is loaded
and binded, i want the value to be "Select A Value", 1, 2,
3, ..., 10. I want to add "Select A value" in the
dropdownlist.

P.S. I am populating the dataset through a datareader
from a database call.

thanx for your help,
aymer
aymerb[@].yahoo.com

Nov 18 '05 #2
ur idea works, but it places the new item at the bottom of
the dropdownlist. i change some things a little a bit so
the new item is on the top.

Dim Item As ListItem = New ListItem
Item.Text = "New"
Item.Value = "0"
Item.Selected = True
MyDropDownList.Items.Insert(0, Item)

thanx for your help,
aymer
aymerb[@].yahoo.com
Nov 18 '05 #3

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

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: Earl Teigrob | last post by:
I want to write a function where I pass in a reference to a dropdownlist and a "match value" and have it returns the index of the dropdownlist item that matchs (or -1 if there is no match) ...
0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
7
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same...
2
by: huzz | last post by:
How do i make a dropdownlist selected value based on the value i retrive from the database. Basically i have an edit page and like to display the default value in a dropdown list from the...
8
by: tshad | last post by:
Can you databind a dropdownlist to another dropdownlist? I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next...
2
by: Dabbler | last post by:
In my Registrant FormView I have a DropDownList which loads data from a secondary SqlDataSource "sdsOfficeParks". I need the user to select an office park but save the selected value in the...
1
by: Vagabond Software | last post by:
I'm using a DropDownList in an EditItemTemplate column. This DropDownList will only ever have two dates in it; Now and the default DateTime value (1/1/1900 12:00:00 AM). Somewhere, somehow, the...
1
by: clickon | last post by:
Forget about the controlParameter for the moment, for testing purposes i have created the following Markup: <asp:Table ID="tblSelectRoute" runat="server" CssClass="asp-table"> <asp:TableRow>...
18
by: Redhairs | last post by:
Is it possible to get DropDownList.SelectedValue in Page_PreInit() event during the postback?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.