By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,733 Members | 846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,733 IT Pros & Developers. It's quick & easy.

Datagrid Item - Invalid Cast

P: n/a
Win Server 2003
VS.Net 2003
1. I'm having the same problem below on all six of my pages with a

2. These pages all worked fine for months until problem started.

3. Same problem on two different computers running Win 2003.

1. Have six pages having datagrids with editable rows. All coded the same
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
of these against SQLServer.
6. I can't figure out why this problem would start after many months on
pages on two computers.

A Windows Update maybe?

Any help would be appreciated.



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

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

Source Error:

Line 168: {
Line 169: // Add changed record ID's to ChangedRecordList for SaveRecord
** Red Highlighted Line 170: DataGridItem dgi = (DataGridItem)
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
System.Web.UI.WebControls.TextBox.OnTextChanged(Ev entArgs e)

System.Web.UI.WebControls.TextBox.System.Web.UI.IP ostBackDataHandler.Raise

Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.