472,374 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 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 4239
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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.