title: How to remove Session datatable row on click of a Button inside Datalist
body: <p><strong>How to delete data from session datatable using button inside datalist?</strong><br /></p>
  
  <p>This code is to display product added inside shopping cart and bremove button is used to remove that item from datalist</p>
  
  <p><em>Front End Code</em></p>
  
  <pre><code>&lt;asp:DataList ID="DataList1" runat="server" Width="100%" HorizontalAlign="Center"&gt;
    &lt;ItemStyle BorderStyle="Double" /&gt;
    &lt;ItemTemplate&gt;
      &lt;center&gt;
        &lt;table class="table" style="border-style: dashed; top: 211px; left: 23px; height: auto; table-layout: fixed; width: 100%;"&gt;
          &lt;tr&gt;
            &lt;td&gt;
              &lt;asp:Image ID="Pimg" runat="server" ImageUrl='&lt;%# Eval("Pimg") %&gt;' CssClass="img img-responsive" Height="140px" Width="240px" /&gt;
            &lt;/td&gt;
            &lt;td&gt;
              &lt;asp:Label ID="Pname" runat="server" Text='&lt;%# Eval("Pname") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/td&gt;
            &lt;td&gt;
              &lt;asp:Label ID="Pqty" runat="server" Text='&lt;%# Eval("Pqty") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/td&gt;
            &lt;td&gt;
              &lt;asp:Label ID="Price" runat="server" Text='&lt;%# Eval("Price") %&gt;'&gt;&lt;/asp:Label&gt;
            &lt;/td&gt;
            &lt;td&gt;
              &lt;asp:Button ID="bremove" runat="server" Text="Remove" OnClick="bremove_Click" /&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
        &lt;/table&gt;
      &lt;/center&gt;
    &lt;/ItemTemplate&gt;
  &lt;/asp:DataList&gt;
  </code></pre>
  
  <p><em>Back End Code</em></p>
  
  <pre><code> protected void bremove_Click(object sender, EventArgs e)
      {
          int index = DataList1.SelectedIndex;
          DataTable dt = Session["AddToCard"] as DataTable;
          dt.Rows[index].Delete();
          porductlist = dt;
          BindData();
          Response.Redirect("Default.aspx");
      }
   public void BindData()
      {
          DataList1.DataSource = porductlist;
          DataList1.DataBind();
      }
  </code></pre>