0
<asp:repeater id="rpt" run="server">
<ItemTemplate>
<asp:LinkButton id="Delete" runat="server" OnCommand="Delete_Command"></asp:linkButton>
<asp:label id="lblMessage" run="server">
</ItemTemplate>
</asp:repeater>

代码背后:

protected void Delete_Command(object sender, CommandEventArgument e)
{

}

如何在 Delete_Command 中获得对“lblMessage”的引用?

4

2 回答 2

0

I would recommend reorganize your code a little bit, which will allow you to perform such operations easily using FindControl. Basically my suggestion boils down to handling Command event not of the link button, but of the repeater itself:

<asp:repeater id="rpt" run="server" OnItemCommand="rpt_ItemCommand">

Then access to item contents is extremely easy:

protected void rpt_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
    Label label = e.Item.FindControl("lblMessage");
    LinkButton linkButton = e.Item.FindControl("Delete");
}
于 2013-07-09T09:33:52.953 回答
0

你可以试试这个:

页 :

<asp:Repeater ID="rpt" runat="server" OnItemCommand="rpt_ItemCommand">
<ItemTemplate>
    <asp:LinkButton ID="Delete" runat="server" CommandName="Delete"></asp:LinkButton>
    <asp:Label ID="lblMessage" runat="server"/>
</ItemTemplate>

代码背后:

protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
        Label lblMessage = e.Item.FindControl("lblMessage") as Label;
    }
}
于 2013-07-09T09:39:41.123 回答