• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 965
  • Last Modified:

Triggerring ItemCommand to trigger a button click inside a Datalist

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")%>' />                                                        
1 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);
> I want to trigger the button click and do some server side code.
Programmatically? From client side or server side?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now