Datagrid update command error
-
I am getting the following error when I attempt to update a row of data in my datagrid using the update command inline with each row available in the datagrid property builder: Server Error in '/GP' Application. -------------------------------------------------------------------------------- Specified cast is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Specified cast is not valid. Source Error: Line 129: int CurrentHealthID = (int) CurrentHealthListDataGrid.DataKeys[(int) e.Item.ItemIndex]; Line 130: Line 131: string nino = ((TextBox)e.Item.Cells[1].Controls[0]).Text; Line 132: string height = ((TextBox)e.Item.Cells[2].Controls[0]).Text; Line 133: string weight = ((TextBox)e.Item.Cells[3].Controls[0]).Text; Source File: c:\inetpub\wwwroot\gp\currenthealthlist.aspx.cs Line: 131 Stack Trace: [InvalidCastException: Specified cast is not valid.] GP.CurrentHealthList.CurrentHealthListDataGrid_UpdateCommand(Object source, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\gp\currenthealthlist.aspx.cs:131 System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs e) +109 System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source, EventArgs e) +507 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source, EventArgs e) +106 System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +121 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +115 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +138 System.Web.UI.Page.ProcessRequestMain() +1277 -------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573 The following is my code:
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; usi