传递变量oncommand LinkButton
本文关键字:LinkButton oncommand 变量 | 更新日期: 2023-09-27 18:18:31
我正在用LinkButton填充li
。但是每个LinkButton都应该有一个带ID的commandArgument。当执行oncommand时,我没有得到它。代码:
<% foreach (be.absi.ibge.data.Informer inform in this.GetIncludedItems(tax.id, true))
{ %>
<li>
<asp:LinkButton OnCommand="myMethod_Click" CommandName="cmdName" CommandArgument="<%= inform.id%>" >
<%= inform.content.title%>
</asp:LinkButton>
</li>
<% } %>
但是在myMethod_Click
方法中,我得到了<%= inform。id%>为参数cmdName
。
oncommand方法:
protected void myMethod_Click(object sender, CommandEventArgs e)
{
Session["sessionTest"] = e.CommandArgument.ToString();
}
解决方案吗?
编辑:各位,我不能运行这段代码,因为没有runat="server"。如果我加上这个,那么<%%>
就不起作用了。所以我试着把它转换成一个中继器。谢谢你的回复。
那是因为你的格式错误。用'
代替"
<asp:LinkButton OnCommand="myMethod_Click" CommandName="cmdName" CommandArgument='<%= inform.id%>' >
<%= inform.content.title%>
</asp:LinkButton>
您可以尝试以下方法,谢谢您的时间。
<% foreach (be.absi.ibge.data.Informer inform in this.GetIncludedItems(tax.id, true))
{ %>
<li>
<asp:LinkButton OnCommand="myMethod_Click" CommandName="cmdName"
CommandArgument='<%= inform.id%>' Text='<%= inform.content.title %>' >
</asp:LinkButton>
</li>
<% } %>