473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Datagrid Item - Invalid Cast

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()

Nov 17 '05 #1
0 1670

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Daniel Walzenbach | last post by:
Hi, I want to display a Label in a DataGrid according to some condition. I therefore check whether the condition is true in the ItemDateBound EventHandler of the DataGrid. Unfortunately the...
2
by: mystical_potato | last post by:
From VS.NET 03 AND VB.NET I added a dropdown list to a data grid control in response to the EditCommand event to force users to pick values from a list and not type them in. I used the...
9
by: Paul | last post by:
Hi I have a data grid with a hyperlink column. the colum has numbers like 00001,000002, ect. Just wondering how to get the text value of the cell as tempstring =...
5
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated...
2
by: Fabrice | last post by:
Hello, First, thanks to felix for his answer. But :-( , I'm feeling newbie :! I' don't understand all the situation. The trouble : Always in the road whith my Datagrid and my ItemTemplate...
5
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design...
2
by: Rajani | last post by:
Hello, <asp:DataGrid ID="dg1" AllowPaging="True" AllowSorting="True" AlternatingItemStyle-BackColor="#ccccff" AlternatingItemStyle-Font-Name="arial" AlternatingItemStyle-ForeColor="#333366"...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.