2013-02-18 72 views
0

我有我的列表視圖的ImageButton的,但我不能在Imagebutton1.Click鍵入我的代碼(aspx.cs):的ImageButton

<asp:ListView ID="lvFotos" runat="server" 
      GroupItemCount="6" InsertItemPosition="LastItem" align="center"> 
      <LayoutTemplate> 
       <table border="0"> 
        <tr ID="groupPlaceholder" runat="server"> 
        </tr> 
       </table> 
      </LayoutTemplate> 
      <GroupTemplate> 
       <tr> 
        <td ID="itemPlaceholder" runat="server"> 
        </td> 
       </tr> 
      </GroupTemplate> 
      <ItemTemplate> 
       <td align="center" height="150px" 
        style="background-color: #ffffff;color: #ffffff; border:none;" width="142px"> 

        <asp:ImageButton ID="ImageButton1" ImageUrl="<%# Container.DataItem %>" runat="server" Width="142" Height="142" />      

       </td> 
      </ItemTemplate> 
      <InsertItemTemplate> 

      </InsertItemTemplate> 
     </asp:ListView> 

我怎樣才能解決這個問題?

+0

檢查:http://stackoverflow.com/questions/8327665/how-to-know-which-linkbutton-in-a-listview-was-clicked/8327761# 8327761 – 2013-02-18 13:31:06

回答

1

你可以使用listview ItemCommand事件。

<asp:ImageButton ID="ImageButton1" ImageUrl="<%# Container.DataItem %>" runat="server" Width="142" Height="142" CommandName="Fire_click_event" />  

public void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e) 
    { 
     if(e.CommandName != "Fire_click_event") 
     { 
      // Do what you want in click event 
     } 
    }