How to delete the specific row from gridview.Using builtin delete command button of gridview
<p>hi i am adding data from textboxes to my gridview locally not from database. its like a salepage where a salesman is saling a product. now i want to delete a row from that gridview but i always got exception while deleting. kindly help me with that. here is my code where i m getting the data and storing that in gridview. thanks.</p>

<pre><code>DataTable dt1 = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            gridVIEWData();
            GridView1.DataSource = dt1;
            GridView1.DataBind();
        }
private void gridVIEWData()
    {

        dt1.Columns.Add("pName", typeof(string));
        dt1.Columns.Add("pCategory", typeof(string));
        dt1.Columns.Add("price", typeof(string));
        dt1.Columns.Add("pQuantity", typeof(string));
        dt1.Columns.Add("totalPrice", typeof(string));
        Session["dtInSession"] = dt1;   //Saving Datatable To Session
    }
protected void Button3_Click(object sender, EventArgs e)
    {
        if (Session["dtInSession"] != null)
            dt1 = (DataTable)Session["dtInSession"]; //Getting datatable from session 


            Int32 total = Convert.ToInt32(txt_quantity.Text) * Convert.ToInt32(txt_price.Text);
            DataRow dr = dt1.NewRow();
            dr["pName"] = DropDownList2.SelectedItem;
            dr["pCategory"] = DropDownList1.SelectedItem;
            dr["price"] = txt_price.Text;
            dr["pQuantity"] = txt_quantity.Text;
            dr["totalPrice"] = total;
            dt1.Rows.Add(dr);


            Session["dtInSession"] = dt1;     //Saving Datatable To Session 

            GridView1.DataSource = dt1;
            GridView1.DataBind();

        }
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

       // string value = GridView1.DataKeys[e.RowIndex].Values["price"].ToString();
        //GridView1.DeleteRow(Convert.ToInt32(value));
        //GridView1.DeleteRow(GridView1.SelectedIndex);

           // dt1.Rows.RemoveAt(GridView1.SelectedIndex);
        Int32 index = GridView1.SelectedIndex;
        GridView1.DeleteRow(index);
    }
</code></pre>
