如何知道中继器中的哪个按钮被按下? [英] How can I tell which button in a repeater got pressed?
问题描述
我在.aspx文件中具有以下标记:
I have the following markup in an .aspx file:
<asp:Repeater ID="ListOfAssignments" runat="server" OnItemDataBound="ListOfAssignments_ItemDataBound">
<ItemTemplate>
<asp:Label ID="AssignmentID" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="PathToFile" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="RemoveAssignment" runat="server" Text="Remove" OnClick="RemoveAssignment_Click"/>
</ItemTemplate>
</asp:Repeater>
在相当标准的中继器控件中,有两个标签和一个按钮.中继器绑定到数据库,并使用数据库中的记录填充标签.
There are two labels and a button in a fairly standard repeater control. The repeater is bound to a database, and populates the labels with records from the database.
这是我的问题:对于中继器中的每个按钮,我都有一个click事件.当用户单击任何按钮时,将调用RemoveAssignment_Click方法.在click事件中,我想知道与用户单击的任何按钮相关联的两个标签的文本.
Here's my problem: I have a click event for each button in the repeater. The RemoveAssignment_Click method is called when the user clicks any of the buttons. In the click event, I want to know the text of the two labels associated with whatever button the user clicked.
我的意思是,用这种方法:
What I mean is, in this method:
protected void RemoveAssignment_Click(object sender, EventArgs e)
{
//code goes here
}
我希望能够知道与单击的按钮相邻的标签的文本.我该怎么办?
I want to be able to know the text of the labels that are adjacent to the button that was clicked. How do I do that?