Casting DataGridItem

A

Alan Z. Scharf

agrids on six different pages which are editable. They each
draw from a different SQLServer table.

2. When data is changed in any rows, the Row ID gets added to an array, and
then a Stored Procedure updates the database table by looping through the
array of Row ID's.

I'm using the RowChanged event to add to the array via the function below.

3. The grids populate OK when the paages are opened, so there is no problem
with connection..

4. However, when I edit data and press Save to run the update procedure, I
get 'Specified cast is not valid error 'on the line that is casting the
datagruid item.

5. All editable grids worked for months and then all stopped working at the
same time.


Any idea what would cause this problem?

Thanks.

Alan


Function
---------------------------------------
protected void RowChanged(object sender, System.EventArgs e)
{
// Add changed record ID's to ChangedRecordList for SaveRecord loop
--->> Error line: 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);
}
}

Stack trace
----------------------------------------
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 167: {
Line 168: // Add changed record ID's to ChangedRecordList for SaveRecord
loop
Line 169: DataGridItem dgi = (DataGridItem) (((Control)
sender).NamingContainer);
Line 170: int recordID = int.Parse(dgi.Cells[0].Text);
Line 171:

Source File: d:\inetpub\wwwroot\winfundssql\default.aspx.cs Line: 169

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
NetFunds.Values.RowChanged(Object sender, EventArgs e) in
d:\inetpub\wwwroot\winfundssql\default.aspx.cs:169
System.Web.UI.WebControls.TextBox.OnTextChanged(EventArgs e) +108

System.Web.UI.WebControls.TextBox.System.Web.UI.IPostBackDataHandler.RaisePo
stDataChangedEvent() +26
System.Web.UI.Page.RaiseChangedEvents() +115
System.Web.UI.Page.ProcessRequestMain() +1081
 
A

Alan Z. Scharf

agrids on six different pages which are editable. They each
draw from a different SQLServer table.

2. When data is changed in any rows, the Row ID gets added to an array, and
then a Stored Procedure updates the database table by looping through the
array of Row ID's.

I'm using the RowChanged event to add to the array via the function below.

3. The grids populate OK when the paages are opened, so there is no problem
with connection..

4. However, when I edit data and press Save to run the update procedure, I
get 'Specified cast is not valid error 'on the line that is casting the
datagruid item.

5. All editable grids worked for months and then all stopped working at the
same time.


Any idea what would cause this problem?

Thanks.

Alan


Function
---------------------------------------
protected void RowChanged(object sender, System.EventArgs e)
{
// Add changed record ID's to ChangedRecordList for SaveRecord loop
--->> Error line: 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);
}
}

Stack trace
----------------------------------------
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 167: {
Line 168: // Add changed record ID's to ChangedRecordList for SaveRecord
loop
Line 169: DataGridItem dgi = (DataGridItem) (((Control)
sender).NamingContainer);
Line 170: int recordID = int.Parse(dgi.Cells[0].Text);
Line 171:

Source File: d:\inetpub\wwwroot\winfundssql\default.aspx.cs Line: 169


Stack Trace:
----------------------------
[InvalidCastException: Specified cast is not valid.]
NetFunds.Values.RowChanged(Object sender, EventArgs e) in
d:\inetpub\wwwroot\winfundssql\default.aspx.cs:169
System.Web.UI.WebControls.TextBox.OnTextChanged(EventArgs e) +108

System.Web.UI.WebControls.TextBox.System.Web.UI.IPostBackDataHandler.RaisePo
stDataChangedEvent() +26
System.Web.UI.Page.RaiseChangedEvents() +115
System.Web.UI.Page.ProcessRequestMain() +1081
 
F

Fiaz Ali Saleemi

Hi Alan

You can view the type of DataGridItem in Debug mode by adding to Control
variable to quick watch then change the code to cast the control to the type
quick watch is showing. I think that might help your cause.

Regards
Fiaz Ali Saleemi
 
A

Alan Z. Scharf

ks for your reply.

I will try this and let you know.

The strange thing is that it was working perfectly for months on all
datagrids pulling from different tables!

Alan





Fiaz Ali Saleemi said:
Hi Alan

You can view the type of DataGridItem in Debug mode by adding to Control
variable to quick watch then change the code to cast the control to the type
quick watch is showing. I think that might help your cause.

Regards
Fiaz Ali Saleemi
Alan Z. Scharf said:
agrids on six different pages which are editable. They each
draw from a different SQLServer table.

2. When data is changed in any rows, the Row ID gets added to an array, and
then a Stored Procedure updates the database table by looping through the
array of Row ID's.

I'm using the RowChanged event to add to the array via the function below.

3. The grids populate OK when the paages are opened, so there is no problem
with connection..

4. However, when I edit data and press Save to run the update procedure, I
get 'Specified cast is not valid error 'on the line that is casting the
datagruid item.

5. All editable grids worked for months and then all stopped working at the
same time.


Any idea what would cause this problem?

Thanks.

Alan


Function
---------------------------------------
protected void RowChanged(object sender, System.EventArgs e)
{
// Add changed record ID's to ChangedRecordList for SaveRecord loop
--->> Error line: 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);
}
}

Stack trace
----------------------------------------
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 167: {
Line 168: // Add changed record ID's to ChangedRecordList for SaveRecord
loop
Line 169: DataGridItem dgi = (DataGridItem) (((Control)
sender).NamingContainer);
Line 170: int recordID = int.Parse(dgi.Cells[0].Text);
Line 171:

Source File: d:\inetpub\wwwroot\winfundssql\default.aspx.cs Line: 169


Stack Trace:
----------------------------
[InvalidCastException: Specified cast is not valid.]
NetFunds.Values.RowChanged(Object sender, EventArgs e) in
d:\inetpub\wwwroot\winfundssql\default.aspx.cs:169
System.Web.UI.WebControls.TextBox.OnTextChanged(EventArgs e) +108
System.Web.UI.WebControls.TextBox.System.Web.UI.IPostBackDataHandler.RaisePo
stDataChangedEvent() +26
System.Web.UI.Page.RaiseChangedEvents() +115
System.Web.UI.Page.ProcessRequestMain() +1081
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top