Get selected index of specific item before display

Discussion in 'ASP .Net' started by martin, Feb 16, 2004.

  1. martin

    martin Guest

    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.
     
    martin, Feb 16, 2004
    #1
    1. Advertising

  2. martin

    Anatoly Guest

    CmbTargetGroup.SelectedValue = 20


    "martin" <> wrote in message
    news:...
    > 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.
    >
    >
    >
    >
    >
    >
    >
    >
    >
     
    Anatoly, Feb 16, 2004
    #2
    1. Advertising

  3. Bert

    You can try

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

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

    if(dropDown.Items.Value == databaseValue
    dropDown.SelectedIndex = dropDown.Items.IndexOf(dropDown.Items)

    }
     
    =?Utf-8?B?RGF2aWQgQ29lLCBNQ1A=?=, Feb 16, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iain
    Replies:
    3
    Views:
    973
  2. Robert Smith
    Replies:
    1
    Views:
    413
    Mark Rae [MVP]
    Mar 9, 2008
  3. mldardy
    Replies:
    0
    Views:
    1,002
    mldardy
    Sep 28, 2010
  4. haiwen
    Replies:
    3
    Views:
    196
    haiwen
    Jul 14, 2003
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    361
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page