title: How to capture button click event from asp.net DataList
body: <p>I have a DataList control in asp.net webform, inside this DataLIst I have 2 labels that are bound to database, and one button.
  One of the label represent Id and other one Stock.
  I want to capture the button click event of specific product, and then add that product to the user cart.</p>
  <p>Here is my datalist:</p>
  <pre><code> &lt;asp:DataList ID=&quot;dListProduct&quot; runat=&quot;server&quot; RepeatColumns=&quot;4&quot; OnItemCommand=&quot;dListProduct_ItemCommand&quot;&gt;
              &lt;ItemTemplate&gt;
                  &lt;div&gt;
                      &lt;table class=&quot;table-responsive&quot; border=&quot;1&quot;&gt;                    
                          &lt;tr&gt;
                               &lt;td&gt;
                                    &lt;asp:Label runat=&quot;server&quot; Text=&quot;Available Stock: &quot; &gt;&lt;/asp:Label&gt;&lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;Stock&quot;)%&gt;'&gt;&lt;/asp:Label&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                               &lt;td&gt;
                                    &lt;asp:Label runat=&quot;server&quot; Text=&quot;Id&quot; &gt;&lt;/asp:Label&gt;&lt;asp:Label ID=&quot;lblPId&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;Product_Id&quot;)%&gt;' Visible=&quot;false&quot;&gt;&lt;/asp:Label&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                               &lt;td&gt;
                                   &lt;asp:Button id=&quot;btnAddtoCart&quot; runat=&quot;server&quot; Text=&quot;Add to Cart&quot;/&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/div&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:DataList&gt;
  </code></pre>
  <p>Here is the code I am using in OnItemCommand Event of DataList:</p>
  <pre><code> protected void dListProduct_ItemCommand(object source, DataListCommandEventArgs e)
          {
              Label lbl = (Label)e.Item.FindControl(&quot;lblPId&quot;);
              Response.Write(lbl.Text);
          }
  </code></pre>
  <p>but this code never get executed.
  Can anyone help me out?</p>