Drop down list does not see the selected item!

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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*/
 
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 said:
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 said:
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/


selected
and for
me!).
 
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 said:
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 said:
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 said:
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/


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
 
Back
Top