Drop down list does not see the selected item!

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
 
K

Karl Seguin

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
 
G

Guest

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*/
 
K

Karl Seguin

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!).
 
G

Guest

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top