2011-12-22 170 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> 
<% } %> 
相關問題