Determine the index of the checked items in a databound listbox

4 posts, 1 answers
  1. GJ Kuz
    GJ Kuz avatar
    29 posts
    Member since:
    May 2011

    Posted 28 Nov 2011 Link to this post

    Hi,

    I have a databound listbox with 10 list items. Out of the 10 items, let's say items 5,7,9 are checked. Is there a way to find out the index of the checked items? In other words, I need to get the values 5,7,9 and pass in to the next page so that I can pull up the info from the DB. There is an indexof property on the checkeditems, but that only returns the index of the items within the checked items collections. In my case the values will be 0,1,2 since I have three items in the checkeditems collection.

    foreach(object checkedItem in lstLoans.CheckedItems)
    {
    queryString += (cnt == 1 ? "?" : "&" ) + "loan" + cnt + "=" + lstLoans.CheckedItems.IndexOf(checkedItem);
    cnt += 1;
    }

    Really appreciate some help on this matter.

    thanks.
  2. Answer
    Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 28 Nov 2011 Link to this post

    Hi Gilles,

    Thanks for contacing us and for your question.

    In your scenario there are two approaches you could use to find the index of the checked item:

    1. Use the IndexOf method on your source collection for each item in the CheckedItems collection, or
    2. Use the GetDataSourceItemForDataItem exposed by RadDataBoundListBox and pass each object from the CheckedItems collection to it as an argument. This method will return an object that implements the IDataSourceItem interface which has an Index property.

    Let me know if you need further assistance here.

    Kind regards,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. GJ Kuz
    GJ Kuz avatar
    29 posts
    Member since:
    May 2011

    Posted 28 Nov 2011 Link to this post

    Deyan,

    As always, thank you for your prompt response. I couldn't figure out how to get the source collection. I couldn't find anything that exposes the source collection on the listbox. But option 2) worked like a charm. If you don't mind I am curious to know how to access the source collection.

    thanks,
    Gilles
  5. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 30 Nov 2011 Link to this post

    Hello Gilles,

    Thanks for writing back and for your questions.

    The source collection is actually the one you used to bind the control. the ItemsSource property on RadDataBoundListBox is used to set or get the source collection.

    I hope this helps.

    Regards,
    Deyan
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top