Listview中的图像按钮

时间:2013-02-18 13:25:05

标签: asp.net listview imagebutton

我的listview中有一个Imagebutton,但是我无法在Imagebutton1.Click中输入我的代码(aspx.cs):

<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>

我该如何解决这个问题?

1 个答案:

答案 0 :(得分: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
        }
    }