473,326 Members | 2,128 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,326 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 6707
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.