473,756 Members | 3,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "SelectInde x" 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.Select edIndex = i;
break;
}
}

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

Nov 16 '05 #1
4 37465
how about
this.ddlUsers.S electedItem = sUserId;
HTH
sam

"charliewes t" <ch*********@di scussions.micro soft.com> wrote in message
news:5B******** *************** ***********@mic rosoft.com...
I need to set the selected drop down list value at run time. I am aware of
the method "SelectInde x" 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.Select edIndex = 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*********@ya hoo.co.uk> wrote in message
news:uH******** ******@TK2MSFTN GP14.phx.gbl...
how about
this.ddlUsers.S electedItem = sUserId;
HTH
sam

"charliewes t" <ch*********@di scussions.micro soft.com> wrote in message
news:5B******** *************** ***********@mic rosoft.com...
I need to set the selected drop down list value at run time. I am aware of
the method "SelectInde x" 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.Select edIndex = 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*********@ya hoo.co.uk> wrote in message
news:uH******** ******@TK2MSFTN GP14.phx.gbl...
how about
this.ddlUsers.S electedItem = sUserId;
HTH
sam

"charliewes t" <ch*********@di scussions.micro soft.com> wrote in message
news:5B******** *************** ***********@mic rosoft.com...
I need to set the selected drop down list value at run time. I am aware of
the method "SelectInde x" 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.Select edIndex = 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
2096
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 vertical scrollbar I can still only see one item at a time. The effect I want is as follows: The Listbox only displays one item until the user clicks on the right-hand side. When the user clicks on the right-hand side, the list "drops down" to...
4
9423
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: ddlObs.DataSource = ds.Tables.DefaultView; ddlObs.DataTextField = "ObsDate";
3
12485
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 me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following: //Code I use to populate the dropdown list. ddAssignedTo.DataValueField = "PersonnelID"; ddAssignedTo.DataTextField =...
4
9179
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" Runat="server"></asp:dropdownlist> heres the Java var myDropDownList = frmMain.ddlDealers;
1
8453
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 value="California">California</option> <option value="New Jersey">New Jersey</option> <option value="Pennsylvania">Pennsylvania</option> </select> <br /><div id='divState' style="width:100%;height:20"></div>
1
8458
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
4884
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 from a MSQL db. pass it to a button (on the same page) and it to run a SQL statemment and populate the data in a table. What i am having problems with is to get the data to the botton where it will execute on the same page. Code below:<?php...
4
8461
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 everything out except for this drop down box. Right now i am using one cfoutput query to display in the drop down box the values for it that are in the database. However, now i created a second query to display what was entered previously. The thing...
5
2327
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 add a new record its fine and by clicking the drop down the 4 option is showing and i can select and add easily bt when i want to view any selected record whtever has been set for the cmbresult its repeating 2 times... i have tried to use the set...
0
10034
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9713
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6534
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3358
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2666
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.