This is a migrated thread and some comments may be shown as answers.

Determine the index of the checked items in a databound listbox

3 Answers 61 Views
DataBoundListBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
GJ Kuz
Top achievements
Rank 1
GJ Kuz asked on 28 Nov 2011, 01:59 PM
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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Deyan
Telerik team
answered on 28 Nov 2011, 03:17 PM
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 >>

0
GJ Kuz
Top achievements
Rank 1
answered on 29 Nov 2011, 02:08 AM
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
0
Deyan
Telerik team
answered on 30 Nov 2011, 02:07 PM
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 >>

Tags
DataBoundListBox
Asked by
GJ Kuz
Top achievements
Rank 1
Answers by
Deyan
Telerik team
GJ Kuz
Top achievements
Rank 1
Share this question
or