Multiple Dropdownlist, selectedindex all the same.

L

Linna

Hi,

I have 3 drop downs and when i try to set default values as below,
they all pre-select to 3

DD1.Databind()
DD2.Databind()
DD3.Databind()
DD1.SelectedIndex = 1
DD2.SelectedIndex = 2
DD3.SelectedIndex = 3

When i switch the statements around, for example as below, then they
all pre-select to 2

DD1.SelectedIndex = 1
DD3.SelectedIndex = 3
DD2.SelectedIndex = 2

SO for some reason, it all pre-selects to the last statement.
Does anyone know how i can fix this?


Thanks!
Linna
 
S

seven

Are you databinding to a table in a dataset?

If that is the case, try to make a new dataview for each drop down. That
way, each one will maintain it's own pointer (rather than all of them
sharing the same one).
 
E

Eliyahu Goldin

Linna,

Looks like the ddls are sharing the same items. When you select an item in
one of them, the item gets marked as selected for all of them. Is this the
case?

Eliyahu
 
L

Linna

Hi,

I am actually binding to an ArrayList as below. The ArrayList stores
arrays of size 2. The thing is it works fine on postbacks. It's just
the first load that it defaults the 3 selected value to the last
selectIndex.

Thanks!
Linna


ArrayList alQuery = new ArrayList();
alQuery = oCust.RetrieveSavedQueryList();
IEnumerator myEnum = alQuery.GetEnumerator();

int i=0;
while ( myEnum.MoveNext() )
{
string[] item = new string[2];
item = (string[])myEnum.Current;
ListItem li = new ListItem(item[1],item[0]);
//default to selected view for first load
ddlView1.Items.Add(li);
ddlView2.Items.Add(li);
ddlView3.Items.Add(li);
if (String.Compare(item[0],_defaultView1,true)==0)
{
i1 = i;
}
if (String.Compare(item[0],_defaultView2,true)==0)
{
i2 = i;
}
if (String.Compare(item[0],_defaultView3,true)==0)
{
i3 = i;
}
i++;
}
ddlView1.DataBind();
ddlView1.SelectedIndex = i1;
ddlView2.DataBind();
ddlView2.SelectedIndex = i2;
ddlView3.DataBind();
ddlView3.SelectedIndex = i3;
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top