您好我有以下aspx代码,当ItemTemplate
内的按钮被cliked时,我需要将Item.BookID传递给后面的代码,我不确定如何做到这一点,因为视图中可能有多个项目。谢谢你的帮助将不胜感激。
<asp:ListView runat="server" ID="UserDetailBooks" DefaultMode="ReadOnly" ItemType="WebApplication1.Models.Borrowed" SelectMethod="GetBorrow" DeleteMethod="ReturnBook">
<EmptyDataTemplate>
<h3>No borrowed books!</h3>
</EmptyDataTemplate>
<LayoutTemplate>
<div style="margin-left: auto; margin-right: auto; width: 50%;">
<h4>Books in possesion:</h4>
<table style="border-spacing: 2px;">
<tr id="groupPlaceholder" runat="server">
</tr>
</table>
</div>
</LayoutTemplate>
<GroupTemplate>
<tr>
<td id="itemPlaceholder" runat="server"></td>
</tr>
</GroupTemplate>
<ItemTemplate>
<td><asp:Button runat="server" Text="Return" OnClick="ReturnBook" />
<a href="BookDetail.aspx?BookID=<%#:Item.BookID %>"><%#:Item.BookTitle %></a>
</td>
</ItemTemplate>
</asp:ListView>
答案 0 :(得分:0)
你可以在按钮属性中传递id吗?
<asp:Button runat="server" Text="Return" BookID="<%#:Item.BookID %>" OnClick="ReturnBook" />
<a href="BookDetail.aspx?BookID=<%#:Item.BookID %>"><%#:Item.BookTitle %></a>
void ReturnBook(object sender, EventArgs e) {
Button b = sender;
string BookId = b.Attributes["BookID"];
}