title: In gridview how to use rowcommand event for a button
body: <p>I am using a gridview in aspx and i have two pages that registration and details.aspx once registration completed it should goto details page in details.aspx i have kept a gridview in that GV i am supposed be use row command event for a button it should show the all the rsults for the students with the edit button as the last column for all the students i used item template for that. but in row command event i dont know the function to write if user clicking edit it should goto the edit page using the userid the id should be noon editable mode and other fields can editable.</p>
  
  <p>details.aspx</p>
  
  <pre><code>   &lt;asp:GridView ID="GridView3" runat="server" CellPadding="3" ForeColor="#333333" GridLines="None" AutoGenerateColumns="false"  OnRowCommand="GridView3_RowCommand" OnSelectedIndexChanged="GridView3_SelectedIndexChanged"&gt;
       &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
           &lt;Columns&gt;
               &lt;asp:BoundField DataField="UserName" HeaderText="UserName" ReadOnly="True"/&gt;
               &lt;asp:BoundField DataField="Password" HeaderText="Password" /&gt;
               &lt;asp:BoundField DataField="FirstName" HeaderText="FirstName" /&gt;
               &lt;asp:BoundField DataField="LastName" HeaderText="LastName" /&gt;
               &lt;asp:BoundField DataField="EMail" HeaderText="Emaid-ID" /&gt;
               &lt;asp:BoundField DataField="PhoneNo" HeaderText="Phone Number" /&gt;
               &lt;asp:BoundField DataField="Location" HeaderText="Location" /&gt;
  
                &lt;asp:TemplateField ShowHeader="False"&gt;
                  &lt;ItemTemplate&gt;
                     &lt;asp:Button ID="btnedit" runat="server" Text="Edit" CommandName="Edit" CommandArgument="UserName"/&gt;
                  &lt;/ItemTemplate&gt;          
               &lt;/asp:TemplateField&gt; 
           &lt;/Columns&gt;
       &lt;EditRowStyle BackColor="#999999" /&gt;
       &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
       &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
       &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
       &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt;
       &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
       &lt;SortedAscendingCellStyle BackColor="#E9E7E2" /&gt;
       &lt;SortedAscendingHeaderStyle BackColor="#506C8C" /&gt;
       &lt;SortedDescendingCellStyle BackColor="#FFFDF8" /&gt;
       &lt;SortedDescendingHeaderStyle BackColor="#6F8DAE" /&gt;
   &lt;/asp:GridView&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>details.aspx.cs</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
   {
      string connection2 = System.Web.Configuration.WebConfigurationManager.ConnectionStrings        ["connection1"].ConnectionString;
      SqlConnection con = new SqlConnection(connection2);
      con.Open();
      SqlCommand cmd = new SqlCommand("select * from User_Information", con);
      SqlDataReader rdr = cmd.ExecuteReader();
      GridView3.DataSource = rdr;
      GridView3.DataBind();
      con.Close();
  }
  protected void GridView3_RowCommand(object sender, GridViewCommandEventArgs e)
  {
  
  }
  
  
  protected void GridView3_SelectedIndexChanged(object sender, EventArgs e)
  {
  
  }
  </code></pre>
  
  <p>} </p>