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

How to: set the selected "drop down list" value at run time.

I need to set the selected drop down list value at run time. I am aware of
the method "SelectIndex" however this works only if you know the precise
location of the value within the ListItem collection. Otherwise, what is the
recommended approach?

I have managed to set the appropriate value using the following loop:

for (int i = 1; i < ddlUsers.Items.Count; i++)
{
if (ddlUsers.Items[i].ToString() == sUserId)
{
ddlUsers.SelectedIndex = i;
break;
}
}

However, I wonder if there's an easier way than this "home-made" solution?
Thanks.

Nov 16 '05 #1
4 37441
how about
this.ddlUsers.SelectedItem = sUserId;
HTH
sam

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
I need to set the selected drop down list value at run time. I am aware of
the method "SelectIndex" however this works only if you know the precise
location of the value within the ListItem collection. Otherwise, what is
the
recommended approach?

I have managed to set the appropriate value using the following loop:

for (int i = 1; i < ddlUsers.Items.Count; i++)
{
if (ddlUsers.Items[i].ToString() == sUserId)
{
ddlUsers.SelectedIndex = i;
break;
}
}

However, I wonder if there's an easier way than this "home-made" solution?
Thanks.

Nov 16 '05 #2
Set the SelectedValue property of the drop down list.

NuTcAsE

Nov 16 '05 #3
sorry SelectedValue

"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl...
how about
this.ddlUsers.SelectedItem = sUserId;
HTH
sam

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
I need to set the selected drop down list value at run time. I am aware of
the method "SelectIndex" however this works only if you know the precise
location of the value within the ListItem collection. Otherwise, what is
the
recommended approach?

I have managed to set the appropriate value using the following loop:

for (int i = 1; i < ddlUsers.Items.Count; i++)
{
if (ddlUsers.Items[i].ToString() == sUserId)
{
ddlUsers.SelectedIndex = i;
break;
}
}

However, I wonder if there's an easier way than this "home-made"
solution?
Thanks.


Nov 16 '05 #4
Thanks Sam. The strange thing is that the intellisense description says this
property is read only? But it does work!

"Sam Martin" wrote:
sorry SelectedValue

"Sam Martin" <sa*********@yahoo.co.uk> wrote in message
news:uH**************@TK2MSFTNGP14.phx.gbl...
how about
this.ddlUsers.SelectedItem = sUserId;
HTH
sam

"charliewest" <ch*********@discussions.microsoft.com> wrote in message
news:5B**********************************@microsof t.com...
I need to set the selected drop down list value at run time. I am aware of
the method "SelectIndex" however this works only if you know the precise
location of the value within the ListItem collection. Otherwise, what is
the
recommended approach?

I have managed to set the appropriate value using the following loop:

for (int i = 1; i < ddlUsers.Items.Count; i++)
{
if (ddlUsers.Items[i].ToString() == sUserId)
{
ddlUsers.SelectedIndex = i;
break;
}
}

However, I wonder if there's an easier way than this "home-made"
solution?
Thanks.



Nov 16 '05 #5

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

Similar topics

2
by: Kyle Blaney | last post by:
I am using a Listbox and can not get the "drop down" effect. My listbox is populated with 20 items and a vertical scrollbar is automatically added. One item is visible. When I click on the...
4
by: charliewest | last post by:
Hello - I've binded a dataset to a Drop Down List control on my web form, using C#, however, the DateTime value is printed in long format. For example: 04/07/2006 12:00 AM. My code is: ...
3
by: Mike Collins | last post by:
I'm not feeling too smart right now, but I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. Can someone show...
4
by: nz mark in aus | last post by:
Hi there I am populating an empty <asp:dropdownlist on the client side using Javascript using the following code Heres my dropdown list <asp:dropdownlist id="ddlDealers"...
1
LuiePL
by: LuiePL | last post by:
I'm trying to get the value the user selected in my drop down box. This is the code for the box: <select size='1' name='Location' onchange="javascript:stateChange()"> <option...
1
missshaikh
by: missshaikh | last post by:
Hi All Friends. I need your help.. I want to format Bold Italic in Drop Down List Control in C#.i retrieve my data from db. like this . ________________ CD ROOM
3
hannable80
by: hannable80 | last post by:
Hi, I have being doing some php code for the very first time using wordpress as a template, basicaly what i want the prog to do is get data from a drop down menu, which i have populated with data...
4
by: bonneylake | last post by:
Hey Everyone, Well this is probably a pretty easy question, but for some reason i just can not figure it out. What i am trying to do is redisplay what was entered previously. I have figured...
5
by: squrel | last post by:
Hello everyone.. i have a small problem here... i have a combobox in my project call cmbresult which has been filled up in the properties by using list properties... i have 4 option there... whn i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.