title: How to cast LiteralControl to LinkButton in C#
body: <pre><code>protected void gvDispMsg_RowCreated(object sender, GridViewRowEventArgs e)
  {
      if (e.Row.RowType == DataControlRowType.Header)
      {
          GridView hGrid = (GridView)sender;
          GridViewRow gvrRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
  
          TableHeaderCell tcCellSub1 = new TableHeaderCell();
          tcCellSub1.Controls.Add(lblDDLBlank);
          gvrRow.Cells.Add(tcCellSub1);
  
          gvDispMsg.Controls[0].Controls.AddAt(0, gvrRow);
  
          LinkButton btnSort;
          System.Web.UI.WebControls.Image image;
          //iterate through all the header cells
          foreach (TableCell cell in e.Row.Cells)
          {
              //check if the header cell has any child controls
              if (cell.HasControls())
              {
                  //get reference to the button column
                  btnSort = (LinkButton)cell.Controls[0];
                  image = new System.Web.UI.WebControls.Image();
                  if (ViewState["sortExp"] != null)
                  {
                      //Do something
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>I am getting the following error in line <code>btnSort = (LinkButton)cell.Controls[0];</code>:</p>
  
  <pre><code>Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.LinkButton'.
  </code></pre>
  
  <p>How can I resolve the error.</p>