mac9416 mac9416 - 6 months ago 31
ASP.NET (C#) Question

Programmatically access Repeater using child RepeaterItem

I have a bunch of repeaters which require similar handling. But the handler requires access, not only to the RepeaterItem which is a subject of the command, but also its containing Repeater.

protected void SpecificRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
GenericHandler(e);
}

private void GenericHandler(RepeaterCommandEventArgs e)
{
RepeaterItem row = e.Item;
// Do things with the item.

Repeater table = e.<???>;
// Do things with the repeater.
}


Basically I'm asking what goes in
<???>
. How can I get the repeater?

Answer Source

In the ItemCommand, the source is the Repeater itself, not the button. So cast the source back to a Repeater.

protected void SpecificRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    Repeater repeater = source as Repeater;
    GenericHandler(e, repeater);
}

private void GenericHandler(RepeaterCommandEventArgs e, Repeater repeater)
{
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download