Can I iterate over a data source?

I have a control and I want to interact through its data source, is this possible?

The control is bound to a repeater, but I also want to scroll through the elements using the inline code at the top of the .ascx control page.

Is it possible?


I am binding to a relay and the item related to the relay is a List collection.

I tried:



And I am not getting anything through intellisense, casting in doesnt List<UserPRofile>

work either.


source to share

2 answers

Of course, just refer to the DataSource control and it will return whatever you originally bound to the control. You need to assign the return value to the appropriate type.

var dataSource = (List<MyClass>)myRepeater.DataSource; // your control


Keep in mind that if you plan on making changes to it and want it reflected in the control, you should use an appropriate data source that supports two-way binding, such as BindList .



As I understand it, you want to access the repeater data source that is inside the custom control. I recommend that you provide the data source as a property and use it to cycle out of the custom control and also to bind your relay.

Also you can use the Repeater.Items collection and get each associated row as a RepeaterItem instance.

foreach (RepeaterItem repeaterItem in myRepeater.Items)
    lblResult.Text += " " + repeaterItem.Text;




All Articles