Multiple Dropdownlist, selectedindex all the same but should be different

Discussion in 'ASP .Net' started by Linna, Jan 24, 2005.

  1. Linna

    Linna Guest

    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;




    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Linna, Jan 24, 2005
    #1
    1. Advertising

  2. 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

    "Linna" <> wrote in message
    news:...
    >
    > 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;
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
     
    Eliyahu Goldin, Jan 24, 2005
    #2
    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. David Austin via .NET 247
    Replies:
    2
    Views:
    562
    =?Utf-8?B?VHJldm9yIEJlbmVkaWN0IFI=?=
    Jun 7, 2004
  2. Linna
    Replies:
    3
    Views:
    2,543
    Linna
    Jan 24, 2005
  3. keithb
    Replies:
    1
    Views:
    12,026
    shauns1
    Nov 1, 2006
  4. S_K
    Replies:
    5
    Views:
    776
    Eliyahu Goldin
    Nov 14, 2007
  5. Christopher Brewster
    Replies:
    5
    Views:
    349
    John Machin
    Nov 14, 2008
Loading...

Share This Page