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

Question: How set dropdownlist SelectedIndex based on value?

I have a dropdownlist. It consists of these Name/Value pairs:
"Apple","1"
"Banana","2"
"Pear","3"

The value (number) is stored in the database.

How can I set the dropdownlist to the correct SelectedIndex based on the
value I retrieve from the db?

Thanks!
Nov 18 '05 #1
2 6711
the Items collection in the DropDownList control has a member function
called FindByValue that you can use:

int i = GetIntFromDB();
myDropDown.Items.FindByValue(i).Selected = true;

HTH,
-Cliff

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
I have a dropdownlist. It consists of these Name/Value pairs:
"Apple","1"
"Banana","2"
"Pear","3"

The value (number) is stored in the database.

How can I set the dropdownlist to the correct SelectedIndex based on the
value I retrieve from the db?

Thanks!

Nov 18 '05 #2
the Items collection in the DropDownList control has a member function
called FindByValue that you can use:

int i = GetIntFromDB();
myDropDown.Items.FindByValue(i).Selected = true;

HTH,
-Cliff

"VB Programmer" <gr*********@go-intech.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
I have a dropdownlist. It consists of these Name/Value pairs:
"Apple","1"
"Banana","2"
"Pear","3"

The value (number) is stored in the database.

How can I set the dropdownlist to the correct SelectedIndex based on the
value I retrieve from the db?

Thanks!

Nov 18 '05 #3

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

Similar topics

1
by: VB Programmer | last post by:
I have a dropdownlist. It consists of these Name/Value pairs: "Apple","1" "Banana","2" "Pear","3" The value (number) is stored in the database. How can I set the dropdownlist to the correct...
3
by: mg | last post by:
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" In DataGrid1_UpdateCommand, the lin DropDownList ddlTest = (DropDownList)...
6
by: Derek Martin | last post by:
I am new to ASP.NET but fairly good at VB.Net. I have an ASP.Net web project going (VB.Net as the codebehind). I have created a page that I dropped a DropDownList and a button on. I populated...
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...
3
by: Richard | last post by:
I've seen articles on GotDotNet and elsewhere on how to put a ddl in a datagrid, and have been able to implement this technique. For a new item, among the datagrid columns there is the one ddl for...
10
by: dhnriverside | last post by:
Hi guys Still having a problem with this dropdownlist. Basically, I've got 4. The first 2 work fine, then my code crashes on the 3rd. ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
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: pleaseexplaintome | last post by:
Hi all, I have a datagrid with a dropdownlist and would like to have the dropdownlist display a database value correctly while the grid is in edit mode. I have a templatecolumn as follows: ...
3
by: =?Utf-8?B?ZGVuIDIwMDU=?= | last post by:
Hi, Trouble in retaining values of dropdownlist, textboxes, and other controls when dropdownlist selectedindexchanged event is triggered, the controls are inside a user control and this user...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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...

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.