Drop down list does not see the selected item!

Discussion in 'ASP .Net' started by =?Utf-8?B?TWVyZGFhZA==?=, Oct 20, 2004.

  1. My drop down list is populated from a static array in my codebehind (c#)
    code.
    I set the selected index based on some known values(from DB), when the
    screen shows up, dropdown list shows that the the first items is selected and
    not the one assigned.

    Please note that if I hardcode the dropdown items inside the .aspx file,
    everything works fine.

    Please point me to examples(infopath examples somehow don't show up for me!).

    Thanks
     
    =?Utf-8?B?TWVyZGFhZA==?=, Oct 20, 2004
    #1
    1. Advertising

  2. =?Utf-8?B?TWVyZGFhZA==?=

    Karl Seguin Guest

    It'd be helpful if you showed us what you have so far, such as how the
    dropdownlist is populated (are you binding, or looping through your array
    and adding items), and how the selected item is being set.

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Merdaad" <> wrote in message
    news:D...
    > My drop down list is populated from a static array in my codebehind (c#)
    > code.
    > I set the selected index based on some known values(from DB), when the
    > screen shows up, dropdown list shows that the the first items is selected

    and
    > not the one assigned.
    >
    > Please note that if I hardcode the dropdown items inside the .aspx file,
    > everything works fine.
    >
    > Please point me to examples(infopath examples somehow don't show up for

    me!).
    >
    > Thanks
     
    Karl Seguin, Oct 20, 2004
    #2
    1. Advertising

  3. Thanks for replying.

    Here is my code:
    String[] usStates;
    usStates = (String[]) Application.Get("states");
    bStDDList.DataSource = usStates;
    bStDDList.DataBind();
    ......
    ...

    bStDDList.SelectedIndex = Convert.ToInt16(DataBinder.Eval(custDataSet,
    "Tables[getCustomerData].DefaultView.[0].bState",""));

    /*debugger shows bStDDList.SelectedIndex to be the correct index*/



    "Karl Seguin" wrote:

    > It'd be helpful if you showed us what you have so far, such as how the
    > dropdownlist is populated (are you binding, or looping through your array
    > and adding items), and how the selected item is being set.
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Merdaad" <> wrote in message
    > news:D...
    > > My drop down list is populated from a static array in my codebehind (c#)
    > > code.
    > > I set the selected index based on some known values(from DB), when the
    > > screen shows up, dropdown list shows that the the first items is selected

    > and
    > > not the one assigned.
    > >
    > > Please note that if I hardcode the dropdown items inside the .aspx file,
    > > everything works fine.
    > >
    > > Please point me to examples(infopath examples somehow don't show up for

    > me!).
    > >
    > > Thanks

    >
    >
    >
     
    =?Utf-8?B?TWVyZGFhZA==?=, Oct 20, 2004
    #3
  4. =?Utf-8?B?TWVyZGFhZA==?=

    Karl Seguin Guest

    Typically, you set the selectedindex via:

    bstDDList.SelectedIndex =
    bstDDList.Items.IndexOf(bstDDList.Items.FindByValue(some string value))

    I imagine bState is the actual state code, which probably doesn't match up
    to the array index of your list item...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/


    "Merdaad" <> wrote in message
    news:...
    > Thanks for replying.
    >
    > Here is my code:
    > String[] usStates;
    > usStates = (String[]) Application.Get("states");
    > bStDDList.DataSource = usStates;
    > bStDDList.DataBind();
    > .....
    > ..
    >
    > bStDDList.SelectedIndex = Convert.ToInt16(DataBinder.Eval(custDataSet,
    > "Tables[getCustomerData].DefaultView.[0].bState",""));
    >
    > /*debugger shows bStDDList.SelectedIndex to be the correct index*/
    >
    >
    >
    > "Karl Seguin" wrote:
    >
    > > It'd be helpful if you showed us what you have so far, such as how the
    > > dropdownlist is populated (are you binding, or looping through your

    array
    > > and adding items), and how the selected item is being set.
    > >
    > > Karl
    > >
    > > --
    > > MY ASP.Net tutorials
    > > http://www.openmymind.net/
    > >
    > >
    > > "Merdaad" <> wrote in message
    > > news:D...
    > > > My drop down list is populated from a static array in my codebehind

    (c#)
    > > > code.
    > > > I set the selected index based on some known values(from DB), when the
    > > > screen shows up, dropdown list shows that the the first items is

    selected
    > > and
    > > > not the one assigned.
    > > >
    > > > Please note that if I hardcode the dropdown items inside the .aspx

    file,
    > > > everything works fine.
    > > >
    > > > Please point me to examples(infopath examples somehow don't show up

    for
    > > me!).
    > > >
    > > > Thanks

    > >
    > >
    > >
     
    Karl Seguin, Oct 20, 2004
    #4
  5. I think the result is the same either way.

    tw. How do you add to a drop down list after it's bound to its datasource.
    I have tried ....items.insert and ..items.add neither one works. I can't
    even modify the items that are already there.

    Thanks

    "Karl Seguin" wrote:

    > Typically, you set the selectedindex via:
    >
    > bstDDList.SelectedIndex =
    > bstDDList.Items.IndexOf(bstDDList.Items.FindByValue(some string value))
    >
    > I imagine bState is the actual state code, which probably doesn't match up
    > to the array index of your list item...
    >
    > Karl
    >
    > --
    > MY ASP.Net tutorials
    > http://www.openmymind.net/
    >
    >
    > "Merdaad" <> wrote in message
    > news:...
    > > Thanks for replying.
    > >
    > > Here is my code:
    > > String[] usStates;
    > > usStates = (String[]) Application.Get("states");
    > > bStDDList.DataSource = usStates;
    > > bStDDList.DataBind();
    > > .....
    > > ..
    > >
    > > bStDDList.SelectedIndex = Convert.ToInt16(DataBinder.Eval(custDataSet,
    > > "Tables[getCustomerData].DefaultView.[0].bState",""));
    > >
    > > /*debugger shows bStDDList.SelectedIndex to be the correct index*/
    > >
    > >
    > >
    > > "Karl Seguin" wrote:
    > >
    > > > It'd be helpful if you showed us what you have so far, such as how the
    > > > dropdownlist is populated (are you binding, or looping through your

    > array
    > > > and adding items), and how the selected item is being set.
    > > >
    > > > Karl
    > > >
    > > > --
    > > > MY ASP.Net tutorials
    > > > http://www.openmymind.net/
    > > >
    > > >
    > > > "Merdaad" <> wrote in message
    > > > news:D...
    > > > > My drop down list is populated from a static array in my codebehind

    > (c#)
    > > > > code.
    > > > > I set the selected index based on some known values(from DB), when the
    > > > > screen shows up, dropdown list shows that the the first items is

    > selected
    > > > and
    > > > > not the one assigned.
    > > > >
    > > > > Please note that if I hardcode the dropdown items inside the .aspx

    > file,
    > > > > everything works fine.
    > > > >
    > > > > Please point me to examples(infopath examples somehow don't show up

    > for
    > > > me!).
    > > > >
    > > > > Thanks
    > > >
    > > >
    > > >

    >
    >
    >
     
    =?Utf-8?B?TWVyZGFhZA==?=, Oct 20, 2004
    #5
    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. Marina
    Replies:
    6
    Views:
    13,638
    KROSS
    Jan 21, 2008
  2. Stephen Adam
    Replies:
    3
    Views:
    12,188
    Stephen Adam
    Nov 30, 2004
  3. weiwei
    Replies:
    0
    Views:
    1,075
    weiwei
    Jan 5, 2007
  4. stephg

    Web User Control Drop Down List does not show selected item

    stephg, Oct 27, 2005, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    370
    Ken Dopierala Jr.
    Oct 30, 2005
  5. Replies:
    0
    Views:
    194
Loading...

Share This Page