Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2005, 10:02 AM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default Fun times with a datagrid.

Hi there,

I am having some fun problems with my datagrid and the edit/ update button.

If the edit button is:
Code:
Sub dgNewsEdit_Click(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)
        dgNews.EditItemIndex = e.Item.ItemIndex
    End Sub


then this error comes up.

Server Error in '/mywebsite' Application.
--------------------------------------------------------------------------------

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 95:
Line 96: Dim NewsId As Integer = Int32.Parse(e.Item.Cells(0).Text)
Line 97: Dim strTitle As String = CType(e.Item.Cells(1).Controls(0), TextBox).Text
Line 98: Dim strArticle As String = MyCstr(CType(e.Item.Cells(2).Controls(0), TextBox).Text)
Line 99:


Source File: c:\inetpub\wwwroot\MYWEBSITE\admin_news.aspx.vb Line: 97

Stack Trace:


[InvalidCastException: Specified cast is not valid.]
   MYWEBSITE.admin_news.dgNewsUpdate_Click(Object Sender, DataGridCommandEventArgs e) in c:\inetpub\wwwroot\MYWEBSITE\admin_news.aspx.vb:97
   System.Web.UI.WebControls.DataGrid.OnUpdateCommand (DataGridCommandEventArgs e)
   System.Web.UI.WebControls.DataGrid.OnBubbleEvent(O bject source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.DataGridItem.OnBubbleEve nt(Object source, EventArgs e)
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args)
   System.Web.UI.WebControls.LinkButton.OnCommand(Com mandEventArgs e)
   System.Web.UI.WebControls.LinkButton.System.Web.UI .IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData)
   System.Web.UI.Page.ProcessRequestMain()


On the update button!!!

If the edit button is set to...
Code:
Sub dgNewsEdit_Click(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)
        dgNews.EditItemIndex = dgNews.DataKeys(e.Item.ItemIndex)
    End Sub


Then the edit button works, but it doesnt open up update boxes on the right section. then click the update button on the wrong section it throws out the error above.... I have looked around with no solution.... i have been basing it on the 4guysfromrolla extensive datagrid examples.

David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521
__________________
David Jenkins
 
Old June 7th, 2005, 11:16 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Where are you rebinding the grid after you set EditItemIndex in that event handler?

I'd recommend that you call the edit controls by name instead of relying on their expected position index:

Dim strTitle As String = CType(e.Item.FindControl("txtTitle"), TextBox).Text

-Peter
 
Old June 7th, 2005, 12:10 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

hi peter,

i wasn't binding the dgNews - i am now. The find control command works a treat!!!
I only have one problem now. That is that:

Code:
Dim strArticle As String = MyCstr(CType(e.Item.FindControl("edtNewsArticle"), TextBox).Text)
MyCstr is a function for enabling me to put html into the database but its not putting it in ie. <br/> is just a space.... i know the function is setup correctly as it does it correctly in the insert command.

Am i calling the function correctly there??



David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521
 
Old June 7th, 2005, 12:48 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What exactly does that function do? How are you checking that the data is ok?

-Peter
 
Old June 7th, 2005, 01:01 PM
Friend of Wrox
 
Join Date: Apr 2004
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Sorry peter - i forgot to put ,True ,True after .Text so that MyCstr will run it checks.... doofus! it all works now.

David Jenkins
-------------------------------------------------------------
Do you want to make extra money around your commitments?
Credit cards, bills, loans and a mortgage - all getting you down?
Is your pension going to be enough when you retire?
There is a solution visit http://www.1stmillion.co.uk
or call 01772 489521





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to passed an xsl parameter to a javascript fun jadeite100 XSLT 1 June 22nd, 2007 02:51 PM
A fun topic: Key Ascii Apocolypse2005 Beginning VB 6 1 February 9th, 2007 01:44 PM
Divs, Gridviews and Javascript != fun mikeymikey ASP.NET 2.0 Professional 1 January 26th, 2007 02:10 PM
Make fun of my AJAX Site SomeGuy3 BOOK: Professional Ajax ISBN: 978-0-471-77778-6 0 July 13th, 2006 02:54 PM
What I think will be fun? hyfbeetle BOOK: ASP.NET Website Programming Problem-Design-Solution 1 June 27th, 2005 08:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.