title: How to send data from Datalist using button to different pages in asp.net?
body: <p>This is the design page that contains my datalist. Also a button within datalist which will pass data to another page on clicking.</p>
  
  <p><strong>Product.aspx</strong></p>
  
  <pre><code>    &lt;%@ Page Title="" Language="C#" MasterPageFile="~/Home.Master" AutoEventWireup="true" CodeBehind="Products.aspx.cs" Inherits="GasBookingPortal.Products" %&gt;
      &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"&gt;
          &lt;style type="text/css"&gt;
          &lt;/style&gt;
      &lt;/asp:Content&gt;
      &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
        &lt;asp:DataList ID="DataListProduct" ItemStyle-Width="500px" ItemStyle-BorderStyle="Solid" runat="server" RepeatColumns="2" RepeatDirection="Horizontal" RepeatLayout="Table" EnableViewState="false"&gt;
      &lt;ItemStyle BorderStyle="Solid" Width="500px"&gt;&lt;/ItemStyle&gt;
              &lt;ItemTemplate&gt;
                  &lt;table&gt;
                      &lt;tr&gt;
                          &lt;td style="border-width: 1px"&gt;
             &lt;img width="100" src='Product_Images/&lt;%# Eval("Product_Image") %&gt;' /&gt;
  
                      &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="border-width: 1px"&gt;
                              Product Name
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;%# Eval("Product_Name") %&gt;
                          &lt;/td&gt;
                          &lt;tr&gt;
                          &lt;td style="border-width: 1px"&gt;
                              Product ID
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;%# Eval("P_ID") %&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="border-width: 1px"&gt;
                              Product Price
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;%# Eval("Product_Price") %&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="border-width: 1px"&gt;
                              Product Category
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;%# Eval("Product_Category") %&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="border-width: 1px"&gt;
                              Product Description
                          &lt;/td&gt;
                          &lt;td&gt;
                              &lt;%# Eval("Product_Description") %&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td style="border-width: 1px"&gt;
     &lt;asp:Button ID="btnBook" runat="server" Text="BOOK" OnClick="btnBook_Click"/&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:DataList&gt;  
      &lt;/asp:Content&gt;
  </code></pre>
  
  <p>This is the code behind. Here I want to write button click event for redirection. Also want to pass few data. I don't know what exactly I have to use for example <code>datalist_itemcommand</code> event or <code>button_click</code> event to redirect into another page and to pass data from datalist. </p>
  
  <p><strong>Product.aspx.cs</strong></p>
  
  <pre><code>    using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Data;
      using System.Data.SqlClient;
      using System.Web.Configuration;
  
      namespace GasBookingPortal
      {
          public partial class Products : System.Web.UI.Page
          {
              SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["gbpcon"].ToString());
              protected void Page_Load(object sender, EventArgs e)
              {
  
                  if (!IsPostBack)
                  {
                      GetDataFromTable();
                      BindDataToDataList();
                  }
  
              }
  
              public void GetDataFromTable()
              {
                  SqlDataAdapter da = new SqlDataAdapter("select Product_Image,Product_Name,Product_Price,P_ID,Product_Category,Product_Description from Product", con);
                  DataSet ds = new DataSet();
                  da.Fill(ds, "table_product");
                  DataTable dt = ds.Tables["table_product"];
  
                  //Session["Product_Category"] = dt.Rows[0]["Product_Category"].ToString();
                  Session["da"] = da;
                  Session["dt"] = dt;
              }
              public void BindDataToDataList()
              {
                  DataListProduct.DataSource = (DataTable)Session["dt"];
                  DataListProduct.DataBind();
              }
  
              protected void btnBook_Click(object sender, EventArgs e)
              {
                  Response.Redirect("PaymentGateway.aspx");
              }
          }
      }
  </code></pre>
  
  <p>Question: I want to send <code>Product_ID</code>, <code>Product_Name</code>, <code>Product_Price</code> to another page <code>Payment.aspx</code> whenever someone will click on BOOK button within datalist. On clicking BOOK button the Product page should redirect into Payment page alongwith few data. The button within datalist can be any button like normal button, or image button or link button. Please guide me how to do this. Trying to solve this problem since last 4 days.</p>
  
  <p>Please tell me how to do this. Will be very grateful.
  I have tried with all possible ways from google and youtube but none of them worked.</p>