specified cast is not valid

  • Thread starter Thread starter planet
  • Start date Start date
P

planet

Hi,

I wish I can solve this problem not having recode the sub. Here is
goes: I got this error' specified cast is not valid' at the second
line. from the code

Sub ChkDelete_OnCheckedChanged(ByVal sender As Object, ByVal e As
EventArgs)
DataGrid1_DeleteCommand(sender, e)

What I was trying to do is in the checkbox oncheckChanges event calls
the datagrid's deleteCommand. The linkbutton is set visible =false.
So the user click the checkbox, the linkbutton is triggered. But I
think the problem is the 'sender' I put at the second line. Because
the first argument in the DataGrid1_deleteCommand is (ByVal source As
Object,)

How to cast it? I think is the question. If anyone knows, please help!


Stack Trace:


[InvalidCastException: Specified cast is not valid.]
Query.Query.ChkDelete_OnCheckedChanged(Object sender, EventArgs e)
in c:\inetpub\wwwroot\Query\stock1.aspx.vb:475
System.Web.UI.WebControls.CheckBox.OnCheckedChanged(EventArgs e)

System.Web.UI.WebControls.CheckBox.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
System.Web.UI.Page.RaiseChangedEvents()
System.Web.UI.Page.ProcessRequestMain()
 
DataGrid's DeleteCommand takes CommandEventArgument as param but you are
passing sender which is nothing but checkbox itself.

What you can to create an instance of CommandEventArgument and inside set
all the required properties and also set source object to checkbox (if
needed).
 
Back
Top