Click here to Skip to main content
15,908,661 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

When i clickthe image button i cant redirecthe website.The datalist onitemclick event does not work.How can i fix this?

ASP.NET
<asp:DataList ID="dlstUrun" runat="server" RepeatColumns="3" DataKeyField="Id" SeparatorStyle-Width="0px" RepeatDirection="Vertical" OnItemCommand="dlstUrun_ItemCommand" EnableViewState="true">
                                    <ItemTemplate>
                                        <div class="col-md-4 col-sm-6">
                                            <div class="product-box" style="width:300px; padding-left: 0px; padding-right: 0px;">
                                                <div class="imagebox style8">
                                                    <div class="box-image owl-carousel-1">
                                                        <a href="#" title="">
                                                            <asp:ImageButton ID="ImageButtonMain" runat="server" AlternateText='<%#Eval("Adi") %>' ImageUrl='<%# string.Format("~/images/product/other/{0}",Eval("PictureMain"))%>' CommandName="detay" CommandArgument='<%#Eval("Id") %>' />
                                                        </a>
                                                        <a href="#" title="">
                                                            <asp:ImageButton ID="ImageButton1" runat="server" AlternateText='<%#Eval("Adi") %>' ImageUrl='<%# string.Format("~/images/product/other/{0}",Eval("Picture1"))%>' CommandName="detay" CommandArgument='<%#Eval("Id") %>' />
                                                        </a>
                                                        <a href="#" title="">
                                                            <asp:ImageButton ID="ImageButton2" runat="server" AlternateText='<%#Eval("Adi") %>' ImageUrl='<%# string.Format("~/images/product/other/{0}",Eval("Picture2"))%>' CommandName="detay" CommandArgument='<%#Eval("Id") %>' />
                                                        </a>
                                                    </div>
                                                    <!-- /.box-image -->
                                                    <div class="box-content">
                                                         <div class="cat-name">
                                            <a href="#" title="">
                                                <asp:Label ID="Label3" runat="server" Text='<%#Eval("GrupAdi") %>'></asp:Label></a>

                                        </div>
                                        <div class="product-name">
                                            <a href="#" title="">
                                                <asp:Label ID="Label1" runat="server" Text='<%#Eval("Adi") %>'></asp:Label></a>
                                        </div>
                                        <div class="price">
                                            <span class="sale">
                                                <asp:Label ID="Label2" runat="server" Text='<%#Eval("Fiyat", "{0:N}") %>'></asp:Label></span>
                                        </div>
                                                    </div>
                                                    <!-- /.box-content -->
                                                    <div class="box-bottom">
                                                        <div class="btn-add-cart">
                                                            <a title="">
                                                                 <asp:ImageButton ID="ImageButtonGo" runat="server" AlternateText='<%#Eval("Adi") %>' ImageUrl="images/icons/add-cart.png" CommandName="detay"  CommandArgument='<%#Eval("Id") %>' />
                                                                <%--<img src="images/icons/add-cart.png" alt="">Add to Cart--%>
                                                            </a>
                                                        </div>
                                                        <div class="compare-wishlist" hidden>
                                                            <a href="#" class="compare" title="">
                                                                <img src="images/icons/compare.png" alt="">Compare
                                                            </a>
                                                            <a href="#" class="wishlist" title="">
                                                                <img src="images/icons/wishlist.png" alt="">Wishlist
                                                            </a>
                                                        </div>
                                                    </div>
                                                    <!-- /.box-bottom -->
                                                </div>
                                                <!-- /.imagebox style8 -->
                                            </div>
                                            <!-- /.product-box -->
                                        </div>
                                        <!-- /.col-md-4 col-sm-6 -->
                                    </ItemTemplate>
                                </asp:DataList>



C#
protected void dlstUrun_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "detay")
            {
                int ID = Convert.ToInt32(e.CommandArgument);
                Response.Redirect("Product.aspx?id=" + ID);
            }


        }


What I have tried:

Datalist item click does not work.
Posted
Comments
Bryian Tan 18-Mar-18 14:29pm    
What do you mean by "does not work"?
Member 10525430 18-Mar-18 14:35pm    
Sorry for confiliction

When i push the add cart image button. Normally it redirect me to product.aspx?id= page how ever when i press the button datalist itemcommand event didnt work and it diidnt forward me to the pruduct.aspx?id= page
Bryian Tan 18-Mar-18 16:25pm    
Judging by the code, everything seem fine. Did you debug and see if ItemCommand get trigger when clicking on the image button?
Not sure if this will help, try to make the button simple for the time being to eliminate other potential interferences.
<a href="#" title="">
    <asp:ImageButton ID="ImageButton2" runat="server"
        ImageUrl='/images/usesomestaticImage.jpg' CommandName="detay" CommandArgument='<%#Eval("Id") %>' />
</a>
Richard Deeming 19-Mar-18 10:46am    
Start by removing the <a href="#" title="">...</a> tags currently wrapping the buttons.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900