How to reach the object connected to repeater

  • Thread starter Karl-Inge Reknes
  • Start date
K

Karl-Inge Reknes

Hi

I have a repeater that is connected to an objectdatasource. I can reach the
item control like this.

foreach (RepeaterItem item in Repeater1.Items)
{
CheckBox c= (CheckBox)i.FindControl("checkbox1");
Label l = (Label)i.FindControl("label1");
}

The objectdatasource have information that i don’t want to show, but i need
to reach. One solution is to use controll with Visible set to false, but I
don’t like this solution.

Is it posible to reach the RepeaterItem dataobject?

I have tried this code with no sucsess:

foreach (RepeaterItem item in Repeater1.Items)
{
CheckBox c= (CheckBox)i.FindControl("checkbox1");
Label l = (Label)i.FindControl("label1");
CustomerClass c = (CustomerClass)i.DataItem;
}

Is there anybody how have an suggestion?

Regard
Karl-Inge Reknes
 
P

Phillip Williams

You can access the dataitem through the repeater items only before the
repeater is rendered during the ItemDataBound event like this:
void repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.SelectedItem)
{
//assuming the repeater is bound to a class named CustomerClass
//each DataItem can be cast to that class and then the properties
//can be accessed
string FirstName = ((CustomerClass)e.Item.DataItem).FirstName;
}
}

But if you want to update the data after some user entries are done on the
repeater-rendered controls, e.g. the user changed the checkboxes state, then
you will have to retrieve the data records from the data store and locate the
individual rows using their primary keys.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,278
Latest member
BuzzDefenderpro

Latest Threads

Top