0

我有一个 ASP.NET 中继器,它的 ItemTemplate 是一个名为 ProviderControl 的 WebUsercontrol。

<asp:Repeater ID="rep" runat="server" OnItemDataBound="rep_ItemDataBound">
    <ItemTemplate>
        <custom:ProviderControl ID="row" runat="server" />
    </ItemTemplate>
</asp:Repeater>

ItemDataBound我正在使用事件中的数据填充自定义控件。

在提供程序控件中,我有两个按钮,我希望能够在包含的页面上对其做出反应。我知道有命令和命令参数,但我该怎么做呢?

或者有比使用命令更简单的方法吗?

4

2 回答 2

1

您必须处理ItemCommand“中继器”事件。

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Button btn = e.CommandSource as Button;
        Response.Write(btn.ID);
    }
于 2012-02-16T12:06:55.743 回答
0

最好的方法是UserControl为每个按钮单击事件提供自定义事件。将UserControl引发并且页面可以处理它们。

http://www.codeproject.com/Articles/8797/Mastering-Page-UserControl-Communication#4.3

于 2012-02-16T11:55:35.490 回答