DropDown List Default Selected Item

Discussion in 'ASP .Net' started by Kris Rockwell, Apr 11, 2004.

  1. Hello (again),

    I have gotten the dropdown list functionality to work through a few tricks
    (probably not the most efficient, but it works) but I am not sure how to set
    the default selected value. I have tried setting various values to represent
    the default value with little success. Essentially I am looking to have the
    first item in the list be the default selected item. I noticed in the
    properties for a dtat grid you could set a default selected index
    (DataGrid.SelectedIndex =). Is there a similiar property for the Dropdown
    list that I am just not seeing?

    DropDownList.SelectedIndex = 0 does not seem to work.

    Regards,
    Kris
    Kris Rockwell, Apr 11, 2004
    #1
    1. Advertising

  2. Kris Rockwell

    Dan Brussee Guest

    What does not work about setting the list's selectedindex property?

    On Sun, 11 Apr 2004 14:25:13 -0400, "Kris Rockwell"
    <> wrote:

    >Hello (again),
    >
    >I have gotten the dropdown list functionality to work through a few tricks
    >(probably not the most efficient, but it works) but I am not sure how to set
    >the default selected value. I have tried setting various values to represent
    >the default value with little success. Essentially I am looking to have the
    >first item in the list be the default selected item. I noticed in the
    >properties for a dtat grid you could set a default selected index
    >(DataGrid.SelectedIndex =). Is there a similiar property for the Dropdown
    >list that I am just not seeing?
    >
    >DropDownList.SelectedIndex = 0 does not seem to work.
    >
    >Regards,
    >Kris
    >
    Dan Brussee, Apr 11, 2004
    #2
    1. Advertising

  3. Well, it seems although I set the property as follows:

    DropDownList.SelectedIndex = 0

    the selected value is not passed. If I try to get the value after setting
    this I no return (although I do see the associsted text in the DDList).
    However, if I select a different value and then select the initial value it
    does retuen the index.

    Regards,
    Kris

    "Dan Brussee" <> wrote in message
    news:...
    > What does not work about setting the list's selectedindex property?
    >
    > On Sun, 11 Apr 2004 14:25:13 -0400, "Kris Rockwell"
    > <> wrote:
    >
    > >Hello (again),
    > >
    > >I have gotten the dropdown list functionality to work through a few

    tricks
    > >(probably not the most efficient, but it works) but I am not sure how to

    set
    > >the default selected value. I have tried setting various values to

    represent
    > >the default value with little success. Essentially I am looking to have

    the
    > >first item in the list be the default selected item. I noticed in the
    > >properties for a dtat grid you could set a default selected index
    > >(DataGrid.SelectedIndex =). Is there a similiar property for the Dropdown
    > >list that I am just not seeing?
    > >
    > >DropDownList.SelectedIndex = 0 does not seem to work.
    > >
    > >Regards,
    > >Kris
    > >

    >
    Kris Rockwell, Apr 11, 2004
    #3
  4. Kris Rockwell

    Dan Brussee Guest

    Just being sure. You mention checking the value. The SelectedValue is
    quite different than the SelectedIndex. Setting the SelectedIndex to 0
    will select the first item in the dropdown list. It will have both a
    Value and Text property as well.


    On Sun, 11 Apr 2004 18:29:17 -0400, "Kris Rockwell"
    <> wrote:

    >Well, it seems although I set the property as follows:
    >
    >DropDownList.SelectedIndex = 0
    >
    >the selected value is not passed. If I try to get the value after setting
    >this I no return (although I do see the associsted text in the DDList).
    >However, if I select a different value and then select the initial value it
    >does retuen the index.
    >
    >Regards,
    >Kris
    >
    >"Dan Brussee" <> wrote in message
    >news:...
    >> What does not work about setting the list's selectedindex property?
    >>
    >> On Sun, 11 Apr 2004 14:25:13 -0400, "Kris Rockwell"
    >> <> wrote:
    >>
    >> >Hello (again),
    >> >
    >> >I have gotten the dropdown list functionality to work through a few

    >tricks
    >> >(probably not the most efficient, but it works) but I am not sure how to

    >set
    >> >the default selected value. I have tried setting various values to

    >represent
    >> >the default value with little success. Essentially I am looking to have

    >the
    >> >first item in the list be the default selected item. I noticed in the
    >> >properties for a dtat grid you could set a default selected index
    >> >(DataGrid.SelectedIndex =). Is there a similiar property for the Dropdown
    >> >list that I am just not seeing?
    >> >
    >> >DropDownList.SelectedIndex = 0 does not seem to work.
    >> >
    >> >Regards,
    >> >Kris
    >> >

    >>

    >
    Dan Brussee, Apr 12, 2004
    #4
  5. Following what you have said, setting the code as follows should produce the
    correct results.

    ...Omitted Connection, data adapter and Dataset info...

    DropDownList.DataBind()
    DropDownList.SelectedIndex = 0

    In this instance the first item in the list should be selected by default
    without any user interaction.

    Is that a correct assumption?

    Regards,
    Kris

    "Dan Brussee" <> wrote in message
    news:...
    > Just being sure. You mention checking the value. The SelectedValue is
    > quite different than the SelectedIndex. Setting the SelectedIndex to 0
    > will select the first item in the dropdown list. It will have both a
    > Value and Text property as well.
    >
    >
    > On Sun, 11 Apr 2004 18:29:17 -0400, "Kris Rockwell"
    > <> wrote:
    >
    > >Well, it seems although I set the property as follows:
    > >
    > >DropDownList.SelectedIndex = 0
    > >
    > >the selected value is not passed. If I try to get the value after setting
    > >this I no return (although I do see the associsted text in the DDList).
    > >However, if I select a different value and then select the initial value

    it
    > >does retuen the index.
    > >
    > >Regards,
    > >Kris
    > >
    > >"Dan Brussee" <> wrote in message
    > >news:...
    > >> What does not work about setting the list's selectedindex property?
    > >>
    > >> On Sun, 11 Apr 2004 14:25:13 -0400, "Kris Rockwell"
    > >> <> wrote:
    > >>
    > >> >Hello (again),
    > >> >
    > >> >I have gotten the dropdown list functionality to work through a few

    > >tricks
    > >> >(probably not the most efficient, but it works) but I am not sure how

    to
    > >set
    > >> >the default selected value. I have tried setting various values to

    > >represent
    > >> >the default value with little success. Essentially I am looking to

    have
    > >the
    > >> >first item in the list be the default selected item. I noticed in the
    > >> >properties for a dtat grid you could set a default selected index
    > >> >(DataGrid.SelectedIndex =). Is there a similiar property for the

    Dropdown
    > >> >list that I am just not seeing?
    > >> >
    > >> >DropDownList.SelectedIndex = 0 does not seem to work.
    > >> >
    > >> >Regards,
    > >> >Kris
    > >> >
    > >>

    > >

    >
    Kris Rockwell, Apr 12, 2004
    #5
  6. Kris Rockwell

    Dan Brussee Guest

    Looks right to me.

    On Sun, 11 Apr 2004 22:01:58 -0400, "Kris Rockwell"
    <> wrote:

    >Following what you have said, setting the code as follows should produce the
    >correct results.
    >
    >..Omitted Connection, data adapter and Dataset info...
    >
    >DropDownList.DataBind()
    >DropDownList.SelectedIndex = 0
    >
    >In this instance the first item in the list should be selected by default
    >without any user interaction.
    >
    >Is that a correct assumption?
    >
    >Regards,
    >Kris
    >
    >"Dan Brussee" <> wrote in message
    >news:...
    >> Just being sure. You mention checking the value. The SelectedValue is
    >> quite different than the SelectedIndex. Setting the SelectedIndex to 0
    >> will select the first item in the dropdown list. It will have both a
    >> Value and Text property as well.
    >>
    >>
    >> On Sun, 11 Apr 2004 18:29:17 -0400, "Kris Rockwell"
    >> <> wrote:
    >>
    >> >Well, it seems although I set the property as follows:
    >> >
    >> >DropDownList.SelectedIndex = 0
    >> >
    >> >the selected value is not passed. If I try to get the value after setting
    >> >this I no return (although I do see the associsted text in the DDList).
    >> >However, if I select a different value and then select the initial value

    >it
    >> >does retuen the index.
    >> >
    >> >Regards,
    >> >Kris
    >> >
    >> >"Dan Brussee" <> wrote in message
    >> >news:...
    >> >> What does not work about setting the list's selectedindex property?
    >> >>
    >> >> On Sun, 11 Apr 2004 14:25:13 -0400, "Kris Rockwell"
    >> >> <> wrote:
    >> >>
    >> >> >Hello (again),
    >> >> >
    >> >> >I have gotten the dropdown list functionality to work through a few
    >> >tricks
    >> >> >(probably not the most efficient, but it works) but I am not sure how

    >to
    >> >set
    >> >> >the default selected value. I have tried setting various values to
    >> >represent
    >> >> >the default value with little success. Essentially I am looking to

    >have
    >> >the
    >> >> >first item in the list be the default selected item. I noticed in the
    >> >> >properties for a dtat grid you could set a default selected index
    >> >> >(DataGrid.SelectedIndex =). Is there a similiar property for the

    >Dropdown
    >> >> >list that I am just not seeing?
    >> >> >
    >> >> >DropDownList.SelectedIndex = 0 does not seem to work.
    >> >> >
    >> >> >Regards,
    >> >> >Kris
    >> >> >
    >> >>
    >> >

    >>

    >
    Dan Brussee, Apr 12, 2004
    #6
    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. rohith
    Replies:
    3
    Views:
    5,982
    rohith
    Aug 29, 2003
  2. Moe Sizlak
    Replies:
    1
    Views:
    391
    stefano mostarda
    Jul 7, 2004
  3. Replies:
    6
    Views:
    587
  4. SSP

    dropdown list does not change selected item?

    SSP, Oct 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    1,132
  5. SA SA
    Replies:
    5
    Views:
    2,461
    Ray Costanzo [MVP]
    Oct 19, 2006
Loading...

Share This Page