2015-05-26 55 views
1

您好,我有以下aspx代碼,當ItemTemplate內的按鈕被粘連時,我需要將Item.BookID傳遞到後面的代碼中,並且我不確定如何執行此操作,因爲可能有多個項目視圖。謝謝你的幫助,將不勝感激。ListView字符串從aspx到代碼隱藏

<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

你可以通過按鈕屬性中的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"]; 
} 
+0

完美的作品intently。 –