i’m trying to delete a record in my gridview. for doing this i added a button field in to gridview.Then i give a command name to button filed. and i wrote codes like this
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "delete")
{
try
{
con.Open();
cmd.CommandText = "Delete from Table where id='" + SelectedRowAndCellValue +"'"
cmd.Connection = con;
cmd.ExecuteNonQuery();
con.Close();
cmd.Dispose();
GridView1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
}
but i cant find SelectedRowAndCellValue. thanks for your helps.
you can try with this code