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

Get selected index of specific item before display

Hi,

I have a dropdown control tha is rendered with the follwoing HTML

<select name="FirstStep:CmbTargetGroup" id="FirstStep_CmbTargetGroup"
style="width:152px;">
<option value="1">Martin</option>
<option value="2">Chris</option>
<option value="5">adrian</option>
<option value="7">Tony</option>
<option value="8">Dave</option>
<option value="15">stewart</option>
<option value="20">Bert</option>
</select>

the above values are taken straight from a database and bound to the
control.
Note that the value option does not indicate the selected index.

Once the items are bound to the control I wish to select "Bert" with a value
of 20 to be display in the dropdown box.
ie. the value in the dropdown box is initially set to "bert"

I know the value is 20, but do not know the value of the selected index (in
advance) to set it to before hand.

I would like to ask the best way to set the drop down box to the value of
"bert" after the items are bound to the control but before the page is
displayed.

many thanks in advance.

martin.



Nov 18 '05 #1
2 4266
CmbTargetGroup.SelectedValue = 20
"martin" <ma***************@hotmail.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a dropdown control tha is rendered with the follwoing HTML

<select name="FirstStep:CmbTargetGroup" id="FirstStep_CmbTargetGroup"
style="width:152px;">
<option value="1">Martin</option>
<option value="2">Chris</option>
<option value="5">adrian</option>
<option value="7">Tony</option>
<option value="8">Dave</option>
<option value="15">stewart</option>
<option value="20">Bert</option>
</select>

the above values are taken straight from a database and bound to the
control.
Note that the value option does not indicate the selected index.

Once the items are bound to the control I wish to select "Bert" with a value of 20 to be display in the dropdown box.
ie. the value in the dropdown box is initially set to "bert"

I know the value is 20, but do not know the value of the selected index (in advance) to set it to before hand.

I would like to ask the best way to set the drop down box to the value of
"bert" after the items are bound to the control but before the page is
displayed.

many thanks in advance.

martin.



Nov 18 '05 #2
Bert

You can try

// C
public void SetDropDownIndex(DropDownList dropDown, string databaseValue

for(int i=0; i < dropDown.Items.Count; i++

if(dropDown.Items[i].Value == databaseValue
dropDown.SelectedIndex = dropDown.Items.IndexOf(dropDown.Items[i])

}
Nov 18 '05 #3

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

Similar topics

9
by: Steffen Laser | last post by:
Hi group, I have a problem that I already have posted to the german C# newsgroup. Since nobody could help me there, I'd like to try it here again: I set the selected item of a combobox like...
4
by: wolfgang wagner | last post by:
hi all! after successfully integrating a dropdownlist in my datagrid i have another problem: i cannot set the selected index of the dropdownlistbox. here is my code: hardware.aspx...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
3
by: Mitch | last post by:
Is the following a correct representation of the relationship of the selected index to selected item: INDEX ITEM 0 "item 1" 1 "item 2" 2 "item 3" and so on. I keep...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
3
by: peter.mosley | last post by:
I've tried googling for the answer to this problem, without any luck. I'm sure the truth must be out there somewhere! I have a multiselect listbox populated with many items (set by the RowSource...
2
by: remya1000 | last post by:
i'm using VB.NET. i have a table names "EMP". this table contain employee details like Index, empID, First name, Last name, address, phone number etc. while page loads, i need to display Last...
0
by: divya1949 | last post by:
Create a windows c# application which will Read a xml file and populate nodes in the treeview. 1 On selection of treenode display the child nodes of that node in listview control 2. ...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.