【发布时间】:2021-02-04 08:20:45
【问题描述】:
我得到了如下所示的预期输出,但我怎么知道用户点击了哪个按钮? enter image description here
下面是我在 asp.net 中的代码,或者我应该使用 asp:Repeater 来执行此操作?
<table style="width: auto">
<% int count = 1;
for (int i = 0; i < (No_of_Bed / 2); i++){%>
<tr>
<% for (int j = 0; j < 2; j++) { %>
<td>
Position <%=count %> :
</td>
<td>
<asp:ImageButton ID="bed" runat="server" ImageUrl="~/img.png" />
</td>
<% count++; }%>
</tr>
<% } %>
<tr>
</table>
【问题讨论】:
-
您可以使用commandargument或commandname将值传递给后端。
-
CommandName="",我是这样弄的,但它无法获取变量的值
-
你如何获得变量的值?我在您的按钮中没有看到 onclick 事件。
-
对不起,我刚刚添加了它。我在后端做了这个:- ImageButton btn = (ImageButton)(sender);点击的字符串 = btn.CommandArgument; testing.Text = 点击;
标签: c# asp.net imagebutton