473,473 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 6712
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.