【发布时间】:2020-02-28 11:25:52
【问题描述】:
如何在 aspx 页面的 CommandName 属性中传递 c# 变量
当我尝试这样做时,我想在 CommandName 属性中传递 idCategory 使用 div 之类的 html 元素或任何可以使用的元素,但使用 像 asp:button 这样的 asp.net 元素没有。 有什么办法可以解决!谢谢!
<tbody ID="tbody">
<%
DAL.InventoryEntities Ie = new DAL.InventoryEntities();
foreach (DAL.Category category in Ie.Categories) {
%>
<tr>
<td><%: category.idCategory %></td>
<td><%: category.name %></td>
<td>
<asp:LinkButton runat="server"
CommandName='<%= category.idCategory %>'
CssClass="btn btn-info btn-block btn-md"
Text="Select"
OnCommand="Select_Command"></asp:LinkButton>
</td>
</tr>
<% } %>
</tbody>
> code behind:
protected void Select_Command(object sender, CommandEventArgs e)
{
Response.Write("Hello " + e.CommandName);
}
output: Hello <%= category.idCategory %>
【问题讨论】:
-
尝试在
CommandName='<%= category.idCategory %>'中将=替换为# -
> 编译错误
ton>