title: how to delete a row from the gridview by using a button outside the gridview
body: <p>This seems like a repeated question but i'm not able to get my answer.</p>
  
  <p>I have a grid view and I need to delete a particular row, when I click on a button outside the gridview.</p>
  
  <pre><code> protected void btnDelete_Click(object sender, EventArgs e)
        {
              dtable = (DataTable)Session["data"];
              DataRow row = dtable.Rows[DataGV1.SelectedIndex];
              dtable.Rows.Remove(row);
              DataGV1.DataSource = dtable;
              DataGV1.DataBind();
              Session["data"] = dtable;
          }
  </code></pre>
  
  <p>The session variable has the previous state of datatable.</p>
  
  <pre><code>protected void DataGV1_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          GridView _gridView = (GridView)sender;
  
          // Get the selected index 
           _selectedIndex = int.Parse(e.CommandArgument.ToString());
       }
  </code></pre>
  
  <p>Gridview controls</p>
  
  <p>
  
  <pre><code>        onselectedindexchanged="DataGV1_SelectedIndexChanged" 
          OnRowCommand="DataGV1_RowCommand" OnRowDeleting="DataGV1_RowDeleting"
          AutoGenerateSelectButton="False" DataKeyNames="Role,Last_name"&gt;
          &lt;Columns&gt;
              &lt;asp:ButtonField DataTextField="last_name" HeaderText="Last_name" CommandName="SingleClick"
                  SortExpression="last_name" Text="Button" /&gt;
              &lt;asp:BoundField DataField="role" HeaderText="role" SortExpression="role" /&gt;
               &lt;asp:BoundField DataField="role" HeaderText="role"                      HeaderText="Frist_name" 
                   SortExpression="first_name" Text="First_name" /&gt;
          &lt;/Columns&gt;
      &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>This doesn't seem to work.
  Can u please tell me where I am going wrong?</p>