title: Getting selected item values in Datalist
body: <p>I am using an ImageButton in Datalist and want to store the selected items value in a varible to process it further. How to get the data upon button click. The data i need are Productid, name,price and so on. Any help?
  Code for Datalist is</p>
  
  <pre><code>&lt;asp:DataList ID="DataList1" runat="server" Width="100%" 
      onselectedindexchanged="DataList1_SelectedIndexChanged" 
      oncancelcommand="DataList1_CancelCommand" oneditcommand="DataList1_EditCommand"&gt;
      &lt;ItemTemplate&gt;
          &lt;table class="style3" style="border: medium solid #000000; width: 100%;"&gt;
              &lt;tr&gt;
                  &lt;td rowspan="3" width="50%" valign="top"&gt;
                     &lt;center style="border-width: thin; border-color: #000000; height: 149px; border-right-style: solid;"&gt; 
                         &lt;asp:HyperLink ID="HyperLink9" runat="server" Height="100px" 
                             NavigateUrl='&lt;%# "~/ProductDetails.aspx?ProductId=" + Eval("Product_id") %&gt;' 
                             Width="100px" style="margin-left: 0px; margin-bottom: 0px"&gt; 
                             &lt;asp:Image ID="img" runat="server" ImageUrl='&lt;%# "images/" + Eval("Category")+"/"+Eval("Sub_category")+"/"+Eval("image") %&gt;'   ToolTip='&lt;%# Eval("Product_name") %&gt;' /&gt;&lt;/asp:HyperLink&gt;
                         &lt;br /&gt;
                         &lt;br /&gt;
                         &lt;asp:Label ID="Label1" runat="server" 
                             Text='&lt;%# "Price : " + Eval("Price") + " Rs." %&gt;'&gt;&lt;/asp:Label&gt;
                     &lt;/center&gt;
                   &lt;/td&gt;
                  &lt;td class="style6" style="width: 50%"&gt;
                     &lt;center style="border-bottom-style: solid; border-width: thin; border-color: #000000"&gt; 
                         &lt;asp:HyperLink ID="HyperLink1" runat="server" 
                             Text='&lt;%# Eval("Product_name") %&gt;' ToolTip='&lt;%# Eval("Product_name") %&gt;'&gt;&lt;/asp:HyperLink&gt;
                     &lt;/center&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style7" valign="top"&gt;
                      &lt;center style="border-width: thin; border-color: #000000; height: auto; border-bottom-style: solid;"&gt;
                          &lt;asp:Label ID="Label2" runat="server" Text='&lt;%# Eval("Product_info") %&gt;'&gt;&lt;/asp:Label&gt;&lt;/center&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td class="style5"&gt;
                      &lt;center&gt;
                          &lt;asp:ImageButton ID="ImageButton3" runat="server" Height="49px" 
                              ImageUrl="~/images/add to cart.jpg" onclick="ImageButton3_Click" 
                              Width="135px" /&gt;
                      &lt;/center&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/ItemTemplate&gt;
  &lt;/asp:DataList&gt;
  </code></pre>
  
  <p>I want that upon Image Button Click the selected Rows Values should get stored in Cart table  and for this i need to store this values to my Backend code to and need atleast Productid value.</p>