.Selected property for listbox does not work

Discussion in 'ASP .Net Web Controls' started by Vipin Kedia, Feb 11, 2005.

  1. Vipin Kedia

    Vipin Kedia Guest

    Hi
    I have written a code for showing the list boxes as selected using a
    Listitem and the selected property of the items.
    Now I have 2 list boxes in my page. But it shows only the selected values
    of the last list box in both the list boxes.
    If i reverse the calls to the filllistbox methods it shows the value
    selected for the 1st list box in both the listboxes.
    I have the code for my method below. Is there a way I can solve this
    problem?

    The method calls are as follows :-

    this.FillListBox(myModel.CustomerLBUserList, myModel.SelectedPRList,
    this.lstProofreaders);

    this.FillListBox(myModel.CustomerLBUserList, myModel.SelectedRevList,
    this.lstReviewers);


    Thanks in advance
    Vipin Kedia


    -------------------------------------------------

    /// <summary>
    /// This is overloaded method.
    /// This method fills the data as well as preselects item.
    /// Note: This method will throw exception if selection mode is single
    and selection arraylist contains multiple items for selection
    /// </summary>
    /// <param name="alData">The ArrayList of ListItem with which ListBox
    needs to be populated</param>
    /// <param name="alSelectionIds">The ArrayList of Ids which needs to be
    selected</param>
    /// <param name="lstFill">The ListBox</param>
    public void FillListBox(ArrayList alData, ArrayList alSelectionIds,
    ListBox lstFill) {
    ListItem liAdd = null;
    try {
    lstFill.ClearSelection();
    lstFill.Items.Clear();
    for (int i=0; i<alData.Count; i++) {
    liAdd = (ListItem) alData;
    lstFill.Items.Add(liAdd);
    lstFill.Items.Selected = false;
    if (alSelectionIds.Contains(liAdd.Value)) {
    lstFill.Items.Selected = true;
    }
    }


    }
    catch (Exception ex) {
    throw ex;
    }
    finally {
    liAdd = null;
    }
    }

    -------------------------------------------------
     
    Vipin Kedia, Feb 11, 2005
    #1
    1. Advertising

  2. sounds to me that you are having a timing problem. you are creating the the
    list in the wrong spot. Check out this article and that should help:

    http://aspnet.4guysfromrolla.com/articles/092904-1.aspx




    "Vipin Kedia" <Vipin > wrote in message
    news:...
    > Hi
    > I have written a code for showing the list boxes as selected using a
    > Listitem and the selected property of the items.
    > Now I have 2 list boxes in my page. But it shows only the selected
    > values
    > of the last list box in both the list boxes.
    > If i reverse the calls to the filllistbox methods it shows the value
    > selected for the 1st list box in both the listboxes.
    > I have the code for my method below. Is there a way I can solve this
    > problem?
    >
    > The method calls are as follows :-
    >
    > this.FillListBox(myModel.CustomerLBUserList, myModel.SelectedPRList,
    > this.lstProofreaders);
    >
    > this.FillListBox(myModel.CustomerLBUserList, myModel.SelectedRevList,
    > this.lstReviewers);
    >
    >
    > Thanks in advance
    > Vipin Kedia
    >
    >
    > -------------------------------------------------
    >
    > /// <summary>
    > /// This is overloaded method.
    > /// This method fills the data as well as preselects item.
    > /// Note: This method will throw exception if selection mode is single
    > and selection arraylist contains multiple items for selection
    > /// </summary>
    > /// <param name="alData">The ArrayList of ListItem with which ListBox
    > needs to be populated</param>
    > /// <param name="alSelectionIds">The ArrayList of Ids which needs to be
    > selected</param>
    > /// <param name="lstFill">The ListBox</param>
    > public void FillListBox(ArrayList alData, ArrayList alSelectionIds,
    > ListBox lstFill) {
    > ListItem liAdd = null;
    > try {
    > lstFill.ClearSelection();
    > lstFill.Items.Clear();
    > for (int i=0; i<alData.Count; i++) {
    > liAdd = (ListItem) alData;
    > lstFill.Items.Add(liAdd);
    > lstFill.Items.Selected = false;
    > if (alSelectionIds.Contains(liAdd.Value)) {
    > lstFill.Items.Selected = true;
    > }
    > }
    >
    >
    > }
    > catch (Exception ex) {
    > throw ex;
    > }
    > finally {
    > liAdd = null;
    > }
    > }
    >
    > -------------------------------------------------
     
    Sean McKaharay, Feb 14, 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. =?Utf-8?B?VmlwaW4gS2VkaWE=?=

    .Selected property for listbox does not work

    =?Utf-8?B?VmlwaW4gS2VkaWE=?=, Feb 11, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    414
    =?Utf-8?B?VmlwaW4gS2VkaWE=?=
    Feb 11, 2005
  2. K B
    Replies:
    2
    Views:
    698
  3. Nathan Sokalski
    Replies:
    0
    Views:
    650
    Nathan Sokalski
    Oct 5, 2008
  4. Vipin Kedia

    .Selected property for listbox does not work

    Vipin Kedia, Feb 11, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    125
    Vipin Kedia
    Feb 11, 2005
  5. Nathan Sokalski

    Selected ListItem in DropDownList does not appear selected

    Nathan Sokalski, Oct 5, 2008, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    317
    Nathan Sokalski
    Oct 5, 2008
Loading...

Share This Page