Delete Selected Row in GridView Without Using SQL Database Connection GridView RowDeleting in Asp.Net C#

Delete Selected Row in GridView Without Using Database

Gridview  Selected Row Delete Gridview RowDeleting  Without DataBase Connection  for Temporary Table  Gridview in Asp.Net C#.


                      HTML CODING

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView2_RowDeleting" >
            <AlternatingRowStyle BackColor="#FF9966" />
              <asp:BoundField DataField="Sno" HeaderText="SNO" />
               <asp:BoundField DataField="Name" HeaderText="NAME" />
               <asp:BoundField DataField="City" HeaderText="CITY" />
               <asp:TemplateField HeaderText="Delete">
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="delete">Delete</asp:LinkButton>
             <HeaderStyle BackColor="#CC3300" />
            <RowStyle BackColor="Silver" />

                          C# CODING

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;

public partial class RemoveRow : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    protected void Bind()
        DataTable dt = new DataTable();
        dt.Columns.Add("Sno", typeof(string));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("City", typeof(string));

        dt.Rows.Add("1", "AAA", "Mumbai");
        dt.Rows.Add("2", "BBB", "New Delhi");
        dt.Rows.Add("3", "CCC", "Kolkata");
        dt.Rows.Add("4", "DDD", "Chennai");
        dt.Rows.Add("5", "EEE", "Bangalore");

        Session["Remove"] = dt;
        DataTable dt1 = (DataTable)Session["Remove"];
        GridView2.DataSource = dt;
    protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
        DataTable dt1 = (DataTable)Session["Remove"];
       // DataTable dt = new DataTable();
        if (dt1.Rows.Count > 0)
            GridView2.DataSource = dt1;

First  - Add New Web Form - Select GridView From ToolBox & Bind The Fields

Next - Add  Column & Row To DataTable  & Pass Another DataTable

Next - GridView Deleting Row -  Delete Selected Row 

Next - Run[F5] - Delete GridView Selected Row


Post a Comment