Look at given point:

CommandName is used to differentiate two button type controls within Gridveiw as shown below.

Observe the following snippet:

code

For the above code we will get the following design:

design

Code:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data.SqlClient;
  8. using System.Data;
  9. namespace WebApplication1
  10. {
  11. public partial class WebForm2 : System.Web.UI.Page
  12. {
  13. SqlConnection con = new SqlConnection("server=.;database=abc;trusted_connection=true");
  14. protected void Page_Load(object sender, EventArgs e)
  15. {
  16. if (!IsPostBack)
  17. {
  18. bind();
  19. }
  20. }
  21. public void bind()
  22. {
  23. SqlCommand cmd = new SqlCommand("select * from employee", con);
  24. SqlDataAdapter da = new SqlDataAdapter(cmd);
  25. DataSet ds = new DataSet();
  26. da.Fill(ds, "con");
  27. GridView1.DataSource = ds;
  28. GridView1.DataBind();
  29. }
  30. protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
  31. {
  32. if (e.CommandName == "comdel")
  33. {
  34. int l = Convert.ToInt32(e.CommandArgument);
  35. con.Open();
  36. SqlCommand cmd = new SqlCommand("delete from employee where eno=@a", con);
  37. cmd.Parameters.AddWithValue("@a", l);
  38. int i = cmd.ExecuteNonQuery();
  39. if (i == 1)
  40. {
  41. Response.Write("Record deleted");
  42. bind();
  43. }
  44. else
  45. {
  46. Response.Write("Recodrd not deleted...");
  47. }
  48. Page_Load(sender, e);
  49. }
  50. }
  51. }
  52. }
Explanation on e.commandargument:

In the above code I used the following line in rowcommand event.
  1. if (e.CommandName == "comdel")
  2. {
  3. int l = Convert.ToInt32(e.CommandArgument);
  4. …..
  5. }
e.commandargument specifies the employee number. Observe the following aspx code snippet.

commandargument
If still any doubts plzz feel free to ask.

Thank you.