473,399 Members | 2,278 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,399 software developers and data experts.

How do I programmatically select and highlight a selection in a drop down list


I am using a database to populate a drop down list using

myDropDownList.DataSource = myCmd.ExecuteReader
myDropDownList.DataBind()

That works alright and a few lines later in the code I wish to
select and highlight one of the items in the list. I have tried what I
think are all the alternatives eg
selectedvalue=myString but I cannot find anything that works.

I would be grateful for some help,

Best wishes, John Morgan
Nov 18 '05 #1
3 1741
myDropDownList.SelectedItem =
myDropDownList.Items.IndexOf(MyDropDownList.Items. FindByValue(myString))

Karl

"John Morgan" <jf*@XXwoodlander.co.uk> wrote in message
news:3g********************************@4ax.com...

I am using a database to populate a drop down list using

myDropDownList.DataSource = myCmd.ExecuteReader
myDropDownList.DataBind()

That works alright and a few lines later in the code I wish to
select and highlight one of the items in the list. I have tried what I
think are all the alternatives eg
selectedvalue=myString but I cannot find anything that works.

I would be grateful for some help,

Best wishes, John Morgan

Nov 18 '05 #2
This would also work.

ListItem li = myDropDownList.Items.FindByValue(myValue); // You can also use .FindByText(myText)
if(li != null) li.Selected = true;

Suresh.

----- John Morgan wrote: -----
I am using a database to populate a drop down list using

myDropDownList.DataSource = myCmd.ExecuteReader
myDropDownList.DataBind()

That works alright and a few lines later in the code I wish to
select and highlight one of the items in the list. I have tried what I
think are all the alternatives eg
selectedvalue=myString but I cannot find anything that works.

I would be grateful for some help,

Best wishes, John Morgan

Nov 18 '05 #3
Thank you Suresh,
I will try it out,
Best wishes, John morgan
On Tue, 10 Feb 2004 10:01:07 -0800, Suresh
<an*******@discussions.microsoft.com> wrote:

ListItem li = myDropDownList.Items.FindByValue(myValue); // You can also use .FindByText(myText)
if(li != null) li.Selected = true;


Nov 18 '05 #4

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

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
7
by: lawrence | last post by:
Can I do something like the following to get a browser to redirect to a new url every time someone picks a new value in a select box? function changeUrl() { var redirect; redirect =...
1
by: Eric Trav | last post by:
Hello, I am using mozilla and javascript to change the style background color for my select with onfocus() and back to white with onblur(). When i process onfocus(); i have to click on the...
2
by: Fritz | last post by:
I know it, I know it. It's come up a lot. I've done the Googling, but the standard answer doesn't do what I expect it to. For the record, the standard answer is: "Set the Selected property of a...
2
by: hypomite | last post by:
I have an handler for the SelectedIndexChanged event of a dropdown box. I have also set the AutoPostBack option to True. When you select any item besides the first one, the event sucessfully fires....
4
by: deepee | last post by:
I have a drop down box in HTML using SELECT and OPTION tags: <select title="Choose a number" onchange="obscure()" name="Digit1" ID="Digit1"> <OPTION VALUE="">&nbsp;</OPTION> <OPTION...
3
by: Michael McGrew | last post by:
I have a Dynamic drop-down box that is populated based on a ADO query. This works fine. I want to capture the users selection and assign it to a variable for use in another query. I am using the...
4
by: luftikus143 | last post by:
Hi there, I have a nasty little problem, as so often, only with IE. Here is an screenshot to better illustrate the problem. http://geodata.grid.unep.ch/screenshot13.png The map is clickable (to...
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
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...
0
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...

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.