Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Casting DataGridItem

Reply
Thread Tools

Casting DataGridItem

 
 
Alan Z. Scharf
Guest
Posts: n/a
 
      07-08-2005
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(Ev entArgs e) +108

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



 
Reply With Quote
 
 
 
 
Alan Z. Scharf
Guest
Posts: n/a
 
      07-11-2005
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(Ev entArgs e) +108

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




 
Reply With Quote
 
 
 
 
Fiaz Ali Saleemi
Guest
Posts: n/a
 
      07-12-2005
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" <> wrote in message
news:...
> 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(Ev entArgs e) +108
>
>

System.Web.UI.WebControls.TextBox.System.Web.UI.IP ostBackDataHandler.RaisePo
> stDataChangedEvent() +26
> System.Web.UI.Page.RaiseChangedEvents() +115
> System.Web.UI.Page.ProcessRequestMain() +1081
>
>
>
>



 
Reply With Quote
 
Alan Z. Scharf
Guest
Posts: n/a
 
      07-12-2005
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" <> wrote in message
news:...
> 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" <> wrote in message
> news:...
> > 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(Ev entArgs e) +108
> >
> >

>

System.Web.UI.WebControls.TextBox.System.Web.UI.IP ostBackDataHandler.RaisePo
> > stDataChangedEvent() +26
> > System.Web.UI.Page.RaiseChangedEvents() +115
> > System.Web.UI.Page.ProcessRequestMain() +1081
> >
> >
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Up casting and down casting Sosuke C++ 2 12-20-2009 03:24 PM
Problem with depracated casting method (down casting) Wally Barnes C++ 3 11-20-2008 05:33 AM
Another question about inheritance (up-casting and down-casting) kevin Java 11 01-08-2005 07:11 PM
DataGrid Built In Paging and DataGridItem Problem Paul Perot ASP .Net 0 12-12-2003 01:17 AM
Problems with casting DataGridItem.findcontrol and DataGridItem.cells(0).control(1) to checkbox Samuel Chowdhuri ASP .Net Datagrid Control 1 10-20-2003 07:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57