I keep getting the following error when trying to access the value of a TextBox in a EditTemplate in a DataGrid. The errors occurs when trying to send the edited value to the database.
Here is the error:
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.
This is the code in question:
public void DataGrid1_Update(Object sender, DataGridCommandEventArgs e)
{
SqlParameter[] prams =
{
objDataAccess.MakeInParam("@oncallid" ,SqlDbType.Int, 4, DataGrid1.DataKeys[e.Item.ItemIndex]),
objDataAccess.MakeInParam("@startdate" ,SqlDbType.DateTime, 8, ((TextBox)e.Item.Cells[2].Controls[0]).Text),
objDataAccess.MakeInParam("@enddate" ,SqlDbType.DateTime, 8, ((TextBox)e.Item.Cells[3].Controls[0]).Text)
};
objDataAccess.RetValProcPrams("usp_EditOnCallSchedule", prams);
DataGrid1.EditItemIndex = -1;
BindData();
lblMessage.Text = "Entry updated!";
}
This code was working until I used TemplateColumns.
Any help would be appreciated.
Here is the error:
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.
This is the code in question:
public void DataGrid1_Update(Object sender, DataGridCommandEventArgs e)
{
SqlParameter[] prams =
{
objDataAccess.MakeInParam("@oncallid" ,SqlDbType.Int, 4, DataGrid1.DataKeys[e.Item.ItemIndex]),
objDataAccess.MakeInParam("@startdate" ,SqlDbType.DateTime, 8, ((TextBox)e.Item.Cells[2].Controls[0]).Text),
objDataAccess.MakeInParam("@enddate" ,SqlDbType.DateTime, 8, ((TextBox)e.Item.Cells[3].Controls[0]).Text)
};
objDataAccess.RetValProcPrams("usp_EditOnCallSchedule", prams);
DataGrid1.EditItemIndex = -1;
BindData();
lblMessage.Text = "Entry updated!";
}
This code was working until I used TemplateColumns.
Any help would be appreciated.