Multiple Dropdownlist, selectedindex all the same but should be different

  • Thread starter Thread starter Linna
  • Start date Start date
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;
 
Linna,

As I said, the problem is in sharing the same items between several ddls.
When you make an item selected in one ddl, it becomes also selected in the
others. Make separate instances of ArrayList for every ddl.

Eliyahu
 
Back
Top