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