473,848 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

"DataGridIt em dgi = (DataGridItem) (((Control) sender).NamingC ontainer);

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(obje ct sender, System.EventArg s e)
{
// Add changed record ID's to ChangedRecordLi st for SaveRecord loop
DataGridItem dgi = (DataGridItem) (((Control) sender).NamingC ontainer);

int recordID = int.Parse(dgi.C ells[0].Text);

// Add to list if not already there
if(!ChangedReco rdIDList.Contai ns(recordID))
{
ChangedRecordID List.Add(record ID);
}
}

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.InvalidC astException: Specified cast is not
valid.

Source Error:

Line 168: {
Line 169: // Add changed record ID's to ChangedRecordLi st for SaveRecord
loop
** Red Highlighted Line 170: DataGridItem dgi = (DataGridItem)
(((Control)
sender).NamingC ontainer);
Line 171:
Line 172: int recordID = int.Parse(dgi.C ells[0].Text);
Source File: d:\inetpub\wwwr oot\winfundssql \default.aspx.c s Line: 170

Stack Trace:

[InvalidCastExce ption: Specified cast is not valid.]
NetFunds.Values .RowChanged(Obj ect sender, EventArgs e) in
d:\inetpub\wwwr oot\winfundssql \default.aspx.c s:170
System.Web.UI.W ebControls.Text Box.OnTextChang ed(EventArgs e)

System.Web.UI.W ebControls.Text Box.System.Web. UI.IPostBackDat aHandler.Raise
Po
stDataChangedEv ent()
System.Web.UI.P age.RaiseChange dEvents()
System.Web.UI.P age.ProcessRequ estMain()

Nov 17 '05 #1
0 1688

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

Similar topics

12
2017
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 conversion is extremely costly in performance. Does anybody know how I could set the label (of the whole content of the TableCell) to .Visible = False without converting e.Item.Controls(2) to a System.Web.UI.WebControls.Label?
2
1784
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 following code: 'Hide the existing txt box Dim txt As TextBox txt = CType(e.Item.Cells(0).Controls(0), TextBox) txt.Visible = False
9
15037
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 = datagrid.Items(rownumber).Cells.Item(column number).Text returns a blank string. It seems to work ok for the other columns that are just regular datagrid columns, not hyperlink types. Thanks. -- Paul G Software engineer.
5
2046
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 one row, all of them were updated so i immediatelly figured out that i have to include the id of every entry in the update statement. This is where the problem is raised. My database is an Access database. The table i am updating contains a Date...
2
1844
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 with a Control HyperLink. I would like to fix many properties of this Control Hyperlink in the Code
5
2059
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 time property of causevalidation. How can I keep them from causing validation? Thanks, T
2
3252
by: Rajani | last post by:
Hello, <asp:DataGrid ID="dg1" AllowPaging="True" AllowSorting="True" AlternatingItemStyle-BackColor="#ccccff" AlternatingItemStyle-Font-Name="arial" AlternatingItemStyle-ForeColor="#333366" CellPadding="3" DataKeyField="empid" OnPageIndexChanged="chgpage" OnSortCommand="sortdg" PageSize="10" PagerStyle-Mode="NumericPages" Runat="server" PagerStyle-HorizontalAlign="Center" OnSelectedIndexChanged="chgsel"...
15
3141
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 OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
0
2922
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 strDataValueField; string strDataTextField; public CreateEditItemTemplateDDL(string DDLName,string DataValueField,string
0
9892
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9735
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10997
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10347
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7067
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5731
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4134
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3172
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.