title: Unable to cast object of type System.Web.UI.WebControls.Label to type System.IConvertible
body: <p>This is the gridview code</p>
  
  <pre><code>&lt;asp:GridView ID="gvwSearch" runat="server" 
      AutoGenerateColumns="False" 
      BackColor="White"
      BorderColor="#999999" 
      BorderStyle="Solid" 
      BorderWidth="1px" 
      CellPadding="3" 
      DataSourceID="SearchSqlDataSource"
      ForeColor="Black" 
      GridLines="Vertical" 
      Width="100%" 
      Visible="False" 
      AllowSorting="True"
      AllowPaging="True" 
      OnSelectedIndexChanged="gvwSearch_SelectedIndexChanged" 
      OnPageIndexChanging="gvwSearch_PageIndexChanging"&gt;
      &lt;AlternatingRowStyle BackColor="#CCCCCC" /&gt;
      &lt;Columns&gt;
          &lt;asp:TemplateField&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:LinkButton ID="lnkbtnEdit" runat="server" OnClick="lnkbtnEdit_Click"&gt;
                      Edit&lt;/asp:LinkButton&gt;
                  &amp;nbsp;|
                      &lt;asp:LinkButton ID="nkbtnView" runat="server" OnClick="nkbtnView_Click"&gt;
                          View&lt;/asp:LinkButton&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
          &lt;asp:TemplateField HeaderText="Employee Code" SortExpression="Employee Code"&gt;
              &lt;EditItemTemplate&gt;
                  &lt;asp:TextBox ID="TextBox1" DataField="EmployeeCode" runat="server" 
                      Text='&lt;%# Bind("[Employee Code]") %&gt;'&gt;
                  &lt;/asp:TextBox&gt;
              &lt;/EditItemTemplate&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:Label ID="lblCode" DataField="EmployeeCode" runat="server" 
                      Text='&lt;%# Bind("[Employee Code]") %&gt;'&gt;
  
                  &lt;/asp:Label&gt;
              &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;
  
          &lt;asp:BoundField DataField="Full Name" HeaderText="Full Name" SortExpression="Full Name" /&gt;
          &lt;asp:BoundField DataField="CPR" HeaderText="CPR" SortExpression="CPR" /&gt;
          &lt;asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" /&gt;
          &lt;asp:BoundField DataField="Designation" HeaderText="Designation" SortExpression="Designation" /&gt;
          &lt;asp:BoundField DataField="Nationality" HeaderText="Nationality" SortExpression="Nationality" /&gt;
          &lt;asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" /&gt;
          &lt;asp:BoundField DataField="Joining Date" HeaderText="Joining Date" SortExpression="Joining Date" /&gt;
          &lt;asp:BoundField DataField="Local Phone" HeaderText="Local Phone" SortExpression="Local Phone" /&gt;
          &lt;asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" /&gt;
          &lt;asp:BoundField DataField="End of Service" HeaderText="End of Service" ReadOnly="True"
              SortExpression="End of Service" /&gt;
      &lt;/Columns&gt;
      &lt;FooterStyle BackColor="#CCCCCC" /&gt;
      &lt;HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /&gt;
      &lt;PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /&gt;
      &lt;SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#F1F1F1" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="Gray" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#CAC9C9" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#383838" /&gt;
      &lt;SortedAscendingCellStyle BackColor="#F1F1F1" /&gt;
      &lt;SortedAscendingHeaderStyle BackColor="Gray" /&gt;
      &lt;SortedDescendingCellStyle BackColor="#CAC9C9" /&gt;
      &lt;SortedDescendingHeaderStyle BackColor="#383838" /&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>This is my c# code:</p>
  
  <pre><code>protected void lnkbtnEdit_Click(object sender, EventArgs e)
  {
      GridViewRow gridViewRow = (GridViewRow)(sender as Control).Parent.Parent;
      int index = gridViewRow.RowIndex;
  
      Label Code_Label = (Label)(gvwSearch.Rows[index].FindControl("lblCode"));
  
      int CodeLabel = Convert.ToInt32(Code_Label);//At thiline error occurs.
      New_Employee Selected_Employee = new New_Employee(CodeLabel);
      Session["Selected_Employee"] = Selected_Employee;
      Response.Redirect("~/Forms/New_Employee/Employees/Edit_Employee.aspx");
  }
  </code></pre>
  
  <p>Yes, I have tried by changing this line</p>
  
  <pre><code>int CodeLabel =Convert.ToInt32(Code_Label);
  </code></pre>
  
  <p>to</p>
  
  <pre><code>int CodeLabel =Convert.ToInt32(Code_Label.Text);
  </code></pre>
  
  <p>This removes the error but no data of the employee is carried from this page to <code>Edit_Employee.aspx</code> When the <code>Edit</code> button clicked in the GridView
  Any help would be appreciated. Thanks in Advance.</p>