[RESOLVED]imagebutton commandname in listview not respond

<asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>

        <div class="slip-background">
            <asp:ListView ID="ListView1"  runat="server" DataKeyNames="Stake, StakeSum" OnItemDataBound="ListView1Slip_ItemDataBound"  OnItemCommand="ListView1_ItemCommand" >
                <ItemTemplate>
                    <div class="slipbet-data">
                        <div style="float:left; margin-left:-4px; margin-top:2px;"><asp:Image ID="Image1" runat="server" ImageUrl="~/images/datetime-icon.png" ImageAlign="AbsBottom" ToolTip='<%# Eval("DateOfEvent") %>'  /></div><div style="margin-left:15px;"><asp:Label ID="lblNameOfEventLabel" runat="server" Text='<%# Eval("NameOfEvent") %>'></asp:Label></div>
                        <asp:ImageButton ID="ImageButton1" CommandName="DeleteEvent" AlternateText="2" runat="server" />
                        <div style="margin-left:15px;"><asp:Label ID="lblTypeOfBets" runat="server" Text='<%# Eval("TypeOfBets") %>'></asp:Label></div>
                        <div style="float:left; margin-left:15px;"><asp:Label ID="lblPickLabel" runat="server" Font-Bold="true" Text="Pick:"> </asp:Label> <asp:Label ID="lblPick" runat="server" Font-Bold="true" Text='<%# Eval("Pick") %>'></asp:Label></div>
                        <div style="float:right"><asp:Label ID="lblOddsLabel" runat="server" Text='<%# Eval("Odds") %>'></asp:Label></div><br />
                        <div id="DivStake" runat="server">
                        <div style="float:left;margin-left:15px; margin-top:2px;">Stake <asp:TextBox ID="txtStake" Text='<%# (Convert.ToString(Eval("Stake"))) == "" ? "0.00" : Eval("Stake") %>'  runat="server" class="staketext" Height="12px" Width="50px" ></asp:TextBox></div>
                        <div style="float:right;"><asp:Label ID="lblStake" class="stake" Text='<%# (Convert.ToString(Eval("StakeSum"))) == "" ? "0.00" : Eval("StakeSum") %>'  runat="server" ></asp:Label></div><br /></div>
                    </div>
                </ItemTemplate>
                <EmptyDataTemplate>No bet has been selected. To select a new bet, please click on the respective odds.</EmptyDataTemplate>

            </asp:ListView>
        </div>
    protected void ListView1_ItemCommand(object source, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteEvent")
        {
         /*   ListViewItem item = ((Control)e.CommandSource).NamingContainer as ListViewItem;

            string EventDelete = ListView1.DataKeys[item.DataItemIndex].ToString();

            Session["DelId"] = EventDelete;

       

            Response.Redirect(Request.Url.ToString());*/

            Response.Redirect("22");


        }

What is problem with my example?

Hi,

Maybe you have to refill the ListView on each PostBack.

Here are some similar threads, please try to refer to:

http://stackoverflow.com/questions/11992450/asp-net-editing-item-from-listview-using-an-imagebutton .

http://stackoverflow.com/questions/5329002/imagebutton-within-listview-problem .

Hope it helps.

Best Regards,
Amy Peng

Leave a Reply