I have a property in my code that sends back the information in a usercontrol that is a repeater. rptOwners is the repeater I am using. The information inside the repeater has to be parsed manually to xml and sent back through a property in the code. The problem is that I can’t seem to get access to the values of the controls inside the repeater.
When debugging, I am able to see that there are the 2 items I expected in rptOwners.DataSource and that the rptOwners.Items.Count = 2. I can then see in the watch window that the information I want is there but I can’t get access to it.
I have been trying rptOwners.DataSource[0].Name etc but it says that “cannot apply indexing to an expression of type object.
public string xmlString
{
get
{
var _builder = new StringBuilder();
var rpt = rptOwners.DataSource;
IList<string> ownersRepeater = new List<string>();
foreach (var item in rpt )
{
_builder.Append("<Owners>");
_builder.Append("<Owner>");
_builder.Append(String.Format("<item>{0}</item>", name));
_builder.Append(String.Format("<item>{0}</item>", address));
_builder.Append(String.Format("<item>{0}</item>", age));
_builder.Append("</Owner>");
_builder.Append("</Owners>");
}
return _builder.ToString();
}
Thanks for the help. Let me know if this was not clear enough.
Here is more of what I mean…

Here is the answer:
foreach (RepeaterItem item in rptOwners.Items)
{
var lblOwnerName = (Label)item.FindControl("lblOwnerName");
_builder.Append("<Owners>");
_builder.Append("<Owner>");
_builder.Append(String.Format("<item>{0}</item>", lblOwnerName));
_builder.Append(String.Format("<item>{0}</item>", item));
_builder.Append(String.Format("<item>{0}</item>", item));
_builder.Append(String.Format("<item>{0}</item>", item));
_builder.Append(String.Format("<item>{0}</item>", item));
_builder.Append(String.Format("<item>{0}</item>", item));
_builder.Append(String.Format("<item>{0}</item>", item));
_builder.Append("</Owner>");
_builder.Append("</Owners>");
}
return _builder.ToString();
Try this (i only added a cast):