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.Configuration;
public partial class samplegrid : System.Web.UI.Page
{
    string conn = ConfigurationManager.ConnectionStrings["connent"].ToString();
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter dap;
    DataSet ds;
    codefile obj= new codefile();
    protected voidPage_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gridbinddata();
        }
    }
    protected voidbtnsubmit_Click(object sender, EventArgs e)
    {
        
        obj.databind1(txtfirstname.Text,txtlastname.Text,txtemailid.Text,txtphoneno.Text,txtaddress.Text);
        gridbinddata();
    }
    private voidgridbinddata()
    {
        GridView1.DataSource = obj.gridbinddata();
        GridView1.DataBind();
        
    }
    public void delete(object sender, CommandEventArgse)
    {
          string str = e.CommandArgument.ToString();
          con = new SqlConnection(conn);
          cmd = new SqlCommand();
          cmd.Connection = con;
          cmd.CommandText = "spdeletedata";
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@spsno", str);
          con.Open();
          cmd.ExecuteNonQuery();
          con.Close();
          gridbinddata();
    }
  
    
}
Class File of aspx file or Ado.net file
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// Summary description for codefile
/// </summary>
public class codefile
{
    string conn = ConfigurationManager.ConnectionStrings["connent"].ToString();
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter dap;
    DataSet ds;
       public codefile()
       {
              //
              // TODO: Add constructor logic here
              //
       }
    public voiddatabind1(string txtfirstname, string txtlastname, stringtxtemailid, string txtphoneno, string txtaddress)
    {
        con = new SqlConnection(conn);
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "spregistrationfrom";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@spfirstname", txtfirstname);
        cmd.Parameters.AddWithValue("@splastname", txtlastname);
        cmd.Parameters.AddWithValue("@spemailid", txtemailid);
        cmd.Parameters.AddWithValue("@spphoneno", txtphoneno);
        cmd.Parameters.AddWithValue("@spaddress", txtaddress);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
    }
    public DataSetgridbinddata()
    {
        con = new SqlConnection(conn);
        cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "spgriddata";
        cmd.CommandType = CommandType.StoredProcedure;
        con.Open();
        dap = new SqlDataAdapter(cmd);
        ds = new DataSet();
        dap.Fill(ds);
        return (ds);
       
      
       
    }