title: Checked in Gridview, Button Click for Assign Value to textbox
body: <p>I try to complete the action for Button click to achieve checked row in gridview,  below is my asp.net code</p>
  
  <p>If i click the Edit button , i want to assign gridview row ,column values into their textboxes .. how is it possible explain with code`</p>
  
  <pre><code> &lt;form id="form1" runat="server"&gt;
  &lt;div&gt;
      &amp;nbsp;&lt;/div&gt;
      &lt;asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Width="505px" OnSelectedIndexChanged="GridView_SelectedIndexChanged" &gt;
          &lt;Columns&gt;
              &lt;asp:TemplateField&gt;
                  &lt;ItemTemplate&gt;
                      &lt;asp:CheckBox ID="CheckBox1" runat="server"  /&gt;
                  &lt;/ItemTemplate&gt;
                  &lt;EditItemTemplate&gt;
                      &amp;nbsp;
                  &lt;/EditItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField&gt;
                  &lt;EditItemTemplate&gt;
                      &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;/EditItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
              &lt;asp:TemplateField&gt;
                  &lt;EditItemTemplate&gt;
                      &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;/EditItemTemplate&gt;
              &lt;/asp:TemplateField&gt;
          &lt;/Columns&gt;
          &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
          &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt;
          &lt;EditRowStyle BackColor="#999999" /&gt;
          &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
          &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
          &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
          &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
      &lt;/asp:GridView&gt;
      &amp;nbsp;&lt;br /&gt;
      &lt;br /&gt;
      &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
      &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
      &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;asp:Button ID="Button1" runat="server" Text="Delete" OnClick="Button1_Click" /&gt;
      &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
      &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;br /&gt;
      &lt;br /&gt;
      &amp;nbsp;
      &lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:TextBox ID="TextBox2" runat="server"&gt;&lt;/asp:TextBox&gt;
      &lt;asp:TextBox ID="TextBox3" runat="server"&gt;&lt;/asp:TextBox&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>c#</p>
  
  <pre><code>public partial class _Default : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          SqlConnection con = new SqlConnection("Data source =;Database = ;Integrated security =true");
          SqlCommand cmd = new SqlCommand("select * from Empdetails", con);
          con.Open();
  
      GridView1.DataSource = cmd.ExecuteReader();
      GridView1.DataBind();
      con.Dispose();
      con.Close();
  
  
  
  }
  protected void GridView_SelectedIndexChanged(object sender, EventArgs e)
  {
  
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
      {
          foreach (GridViewRow row in GridView1.Rows)
          {
              if ((row.FindControl("CheckBox1") as CheckBox).Checked)
              {
                  TextBox1.Text = row.Cells[0].Text;
                  TextBox2.Text = row.Cells[1].Text;
                  TextBox3.Text = row.Cells[2].Text;
              }
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>Here using Empid is primary and 2 other columns .. but its doesn't execute correctly</p>