title: How to change GridView Column type from TextBox to LinkButton
body: <p>I need to know how to allow Gridview column to accept LinkButton. By default, GridView Column is set to accept TextBox controls but I need to have a LinkButton control. My code is: </p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data;
  using System.Data.SqlClient;
  using System.Data.OleDb;
  using System.IO;
  using System.Data.Common;
  using System.Globalization;
  
  
      namespace GridView_Tutorial
      {
          public partial class GridView : System.Web.UI.Page
          {
              protected void Page_Load(object sender, EventArgs e)
              {
  
              }
  
              protected void Button1_Click(object sender, EventArgs e)
              {
                  SqlConnection con = new SqlConnection("Data Source=Mehdi-PC\\SqlExpress; Initial Catalog=PIMS; Integrated Security=true");
                  con.Open();
                  SqlDataAdapter da = new SqlDataAdapter("SELECT cat_id, cat_name FROM quest_categories", con);
                  DataTable dt = new DataTable();
                  da.Fill(dt);
                  //add a blank row to returned DataTable 
                  DataRow dr = dt.NewRow();
                  dt.Rows.InsertAt(dr, 0);
                  //creating the first row of Gridview to be editable
                  GridView1.EditIndex = 0;
  
                  //Data Sourcing and binding
                  GridView1.DataSource = dt;
                  GridView1.DataBind();
                  //Changing the Text for Inserting a New Record
                  ((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text = "Insert";
                  if (con != null)
                  {
                      con.Close();
                  }
              }
          }
      }
  </code></pre>
  
  <p>Following line of code is throwing error: </p>
  
  <pre><code>((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text = "Insert"; 
  </code></pre>
  
  <p>Error Message is:</p>
  
  <pre><code>InvalidCastException is unhandled by the user.
  Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.Web.UI.WebControls.LinkButton'.
  </code></pre>
  
  <p>When I change the code from: </p>
  
  <pre><code>((LinkButton)GridView1.Rows[0].Cells[0].Controls[0]).Text = "Insert"; 
  </code></pre>
  
  <p>to</p>
  
  <pre><code>((TextBox)GridView1.Rows[0].Cells[0].Controls[0]).Text = "Insert"; 
  </code></pre>
  
  <p>Error goes away, and code inserts a textbox in datatable. </p>
  
  <p>Please help me to insert a LinkButton instead of a TextBox.</p>
  
  <p>Regards</p>