Triggerring ItemCommand to trigger a button click inside a Datalist

Posted on 2011-05-07
Last Modified: 2012-05-11
I have a datalist contorl inside which I have a button. I want to trigger the button click and do some server side code. I have the following code in the seerver side and client side. But I am not able to trigger this event at all. Please help. Am I using the right event to trigger the button click or should I use a diff. one. Please help thanks

Private Sub dlProduct_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlProduct.ItemCommand
If e.CommandName = "AddCart" Then
'some code
End Sub

<asp:DataList ID="dlProduct" runat="server" OnItemCommand ="dlProduct_ItemCommand">
                                    <ItemStyle Font-Bold="True" />
<asp:ImageButton  ID="imgTopAddtoCart" runat="server" ImageAlign="Right" ImageUrl="/Assets/Images/Products/AddtoCart.jpg"  CommandName="AddCart" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ItemID")%>' />                                                        
Question by:TrialUser
    LVL 13

    Accepted Solution


    Make sure that the following line exists in the IntializeComponent() of your page and if not, add it.

    this.dlProduct.ItemCommand += new System.Web.UI.WebControls.DataListCommandEventHandler(this.dlProduct_ItemCommand);
    LVL 83

    Expert Comment

    > I want to trigger the button click and do some server side code.
    Programmatically? From client side or server side?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now