0

I have a repeater and it has an Asp button. I want to get repeater item which contains clicked button.

Here is a part of my repeater:

     ...
       <td>
           <asp:Button runat="server" ID="btnSaveStock" OnClick="btnSaveStock_OnClick" Text="Save" />
       </td>
    </tr>
  </ItemTemplate>

I want to access repeater item in here :

 protected void btnSaveStock_OnClick(object sender, EventArgs e)
    {
        try
        {
            Button btnSaveStock = (Button)sender;

            Repeater rptProductChance = (Repeater)btnSaveStock.Parent;

        }
        catch (Exception)
        {

            throw;
        }
    }

What should I do expect loop as check all items of repeater?

4

2 回答 2

1

这是你可以做的。您可以RepeaterItem通过投射按钮来访问NamingContainer

protected void btnSaveStock_OnClick(object sender, EventArgs e)
{
    try
    {
        Button btnSaveStock = (Button)sender;
        RepeaterItem item = (RepeaterItem)btnSaveStock.NamingContainer;
        //....

    }
    catch (Exception)
    {
        throw;
    }
}
于 2013-04-18T13:53:29.243 回答
0

由于有很多按钮(不仅仅是一个),如果您想处理按钮单击〜在转发器的当前“行”的上下文中〜,您可能想要连接到转发器,而不是按钮“模板定义”。

http://www.developer.com/net/asp/article.php/3609466/ASPNET-Tip-Responding-to-the-Repeater-Controls-ItemCommand-Event.htm

于 2013-04-18T13:44:08.063 回答