使用子RepeaterItem以编程方式访问Repeater

时间:2017-08-16 18:30:12

标签: c# asp.net webforms

我有一堆需要类似处理的中继器。但是处理程序不仅需要访问作为命令主题的RepeaterItem,还需要访问包含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.
}

基本上我在问<???>中的内容。我怎样才能获得转发器?

1 个答案:

答案 0 :(得分:1)

在ItemCommand中,源是Repeater本身,而不是按钮。因此,将源码转换回Repeater。

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

private void GenericHandler(RepeaterCommandEventArgs e, Repeater repeater)
{
}