473,385 Members | 1,813 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,385 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 6709
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: 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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.