Win Server 2003
VS.Net 2003
---------------
1. I'm having the same problem below on all six of my pages with a
datagrid
item.
2. These pages all worked fine for months until problem started.
3. Same problem on two different computers running Win 2003.
Problem
---------
1. Have six pages having datagrids with editable rows. All coded the same
way.
2. When user changes values in a row, RowChanged function adds recordID of
row to an array.
3. When press Save, loops through array and issues a SQLServer update for
each recordID listed in array.
4. NOW getting "Specified cast is invalid", vs. working fine for months.
Error coming from statement in my code. (Full code at end of message.)
"DataGridItem dgi = (DataGridItem) (((Control) sender).NamingContainer);
5. I know what Invalid Casts are, because in development I had to cure a
lot
of these against SQLServer.
6. I can't figure out why this problem would start after many months on
all
pages on two computers.
A Windows Update maybe?
Any help would be appreciated.
Thanks.
Alan
My Code where problem occurs
---------------------------------
protected void RowChanged(object sender, System.EventArgs e)
{
// Add changed record ID's to ChangedRecordList for SaveRecord loop
DataGridItem dgi = (DataGridItem) (((Control) sender).NamingContainer);
int recordID = int.Parse(dgi.Cells[0].Text);
// Add to list if not already there
if(!ChangedRecordIDList.Contains(recordID))
{
ChangedRecordIDList.Add(recordID);
}
}
Web Page Error message
---------------------------------------
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 168: {
Line 169: // Add changed record ID's to ChangedRecordList for SaveRecord
loop
** Red Highlighted Line 170: DataGridItem dgi = (DataGridItem)
(((Control)
sender).NamingContainer);
Line 171:
Line 172: int recordID = int.Parse(dgi.Cells[0].Text);
Source File: d:\inetpub\wwwroot\winfundssql\default.aspx.cs Line: 170
Stack Trace:
[InvalidCastException: Specified cast is not valid.]
NetFunds.Values.RowChanged(Object sender, EventArgs e) in
d:\inetpub\wwwroot\winfundssql\default.aspx.cs:170
System.Web.UI.WebControls.TextBox.OnTextChanged(Ev entArgs e)
System.Web.UI.WebControls.TextBox.System.Web.UI.IP ostBackDataHandler.Raise
Po
stDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()