Make a value the default in a databound dropdown

Discussion in 'ASP .Net' started by Steve, Sep 7, 2006.

  1. Steve

    Steve Guest

    I have a databound dropdown in my page. I want to make one of the
    values the default value. Any ideas?

    Just to explain further, I have also appended one item to the dropdown,
    using the AppendDataBoundItems="True" property of the dropdown.
    Unfortunately the item I have appended to the dropdown has become the
    default value of the dropdown list which is not what I want.

    Kind regards,

    Steve.
     
    Steve, Sep 7, 2006
    #1
    1. Advertising

  2. myDropDown.SelectedIndex =
    myDropDown.Items.IndexOf(myDropDown.Items.FindByValue("yourDefaultValue"))

    you can also use FindByText which uses the text, instead of the value.

    Karl

    --
    http://www.openmymind.net/
    http://www.codebetter.com/


    "Steve" <> wrote in message
    news:...
    >I have a databound dropdown in my page. I want to make one of the
    > values the default value. Any ideas?
    >
    > Just to explain further, I have also appended one item to the dropdown,
    > using the AppendDataBoundItems="True" property of the dropdown.
    > Unfortunately the item I have appended to the dropdown has become the
    > default value of the dropdown list which is not what I want.
    >
    > Kind regards,
    >
    > Steve.
    >
     
    Karl Seguin [MVP], Sep 7, 2006
    #2
    1. Advertising

  3. Steve

    Steve Guest

    Thank you for this Karl.

    Should I put this code in the page load event in page behind or can I
    somehow put it as a parameter in between the dropdown tags in the page
    itself.

    Kind regads,

    Steve


    Karl Seguin [MVP] wrote:
    > myDropDown.SelectedIndex =
    > myDropDown.Items.IndexOf(myDropDown.Items.FindByValue("yourDefaultValue"))
    >
    > you can also use FindByText which uses the text, instead of the value.
    >
    > Karl
    >
    > --
    > http://www.openmymind.net/
    > http://www.codebetter.com/
    >
    >
    > "Steve" <> wrote in message
    > news:...
    > >I have a databound dropdown in my page. I want to make one of the
    > > values the default value. Any ideas?
    > >
    > > Just to explain further, I have also appended one item to the dropdown,
    > > using the AppendDataBoundItems="True" property of the dropdown.
    > > Unfortunately the item I have appended to the dropdown has become the
    > > default value of the dropdown list which is not what I want.
    > >
    > > Kind regards,
    > >
    > > Steve.
    > >
     
    Steve, Sep 13, 2006
    #3
  4. I'm pretty sure you're stuck doing it in codebehind.

    Karl

    --
    http://www.openmymind.net/
    http://www.codebetter.com/


    "Steve" <> wrote in message
    news:...
    > Thank you for this Karl.
    >
    > Should I put this code in the page load event in page behind or can I
    > somehow put it as a parameter in between the dropdown tags in the page
    > itself.
    >
    > Kind regads,
    >
    > Steve
    >
    >
    > Karl Seguin [MVP] wrote:
    >> myDropDown.SelectedIndex =
    >> myDropDown.Items.IndexOf(myDropDown.Items.FindByValue("yourDefaultValue"))
    >>
    >> you can also use FindByText which uses the text, instead of the value.
    >>
    >> Karl
    >>
    >> --
    >> http://www.openmymind.net/
    >> http://www.codebetter.com/
    >>
    >>
    >> "Steve" <> wrote in message
    >> news:...
    >> >I have a databound dropdown in my page. I want to make one of the
    >> > values the default value. Any ideas?
    >> >
    >> > Just to explain further, I have also appended one item to the dropdown,
    >> > using the AppendDataBoundItems="True" property of the dropdown.
    >> > Unfortunately the item I have appended to the dropdown has become the
    >> > default value of the dropdown list which is not what I want.
    >> >
    >> > Kind regards,
    >> >
    >> > Steve.
    >> >

    >
     
    Karl Seguin [MVP], Sep 14, 2006
    #4
    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. Simon Harvey
    Replies:
    2
    Views:
    415
    Christopher Reed
    Jan 18, 2006
  2. rodchar
    Replies:
    0
    Views:
    397
    rodchar
    Nov 26, 2007
  3. Manu
    Replies:
    0
    Views:
    170
  4. Replies:
    0
    Views:
    94
  5. Randy Galliano

    Default Value in on Databound Drop Down list

    Randy Galliano, Nov 5, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    275
    Randy Galliano
    Nov 7, 2007
Loading...

Share This Page