2011-12-22 169 views
0

我正在用LinkBut​​ton's填充li。但是每个LinkBut​​ton都应该有一个带有ID的commandArgument。在做一个oncommand时,我没有得到它。 代码:传递变量oncommand LinkBut​​ton

<% 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的方法。

的按需方法:

protected void myMethod_Click(object sender, CommandEventArgs e) 
{ 
    Session["sessionTest"] = e.CommandArgument.ToString(); 
} 

任何解决方案?

编辑:人们,我无法运行此代码,因为没有runat =“服务器”。如果我添加这个,那么<%%>不起作用。所以我试图将其转换为中继器。感谢您的回复。

回答

1

那是因为你的格式不对。使用'代替"

<asp:LinkButton OnCommand="myMethod_Click" CommandName="cmdName" CommandArgument='<%= inform.id%>' > 
     <%= inform.content.title%> 
    </asp:LinkButton> 
0

你请尝试以下方法,感谢您的时间。

<% 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> 
<% } %> 
相关问题