Ive got an image button on a grid...then i have this code: Private Sub dgActionItems_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgActionItems.ItemCommand ' Check to see if the user selected the pager. If not, then this must be ' a command button If (e.Item.ItemType <> ListItemType.Pager) Then Select Case e.CommandName Case "Edit" 'edit action item Case "Delete" 'delete the action item Dim f As New Functions f.DeleteActionItem(CType(e.Item.Cells(0).Text, Long)) Case "Task" 'send the task here End Select Else ' This section would be where any page control stuff goes End If End Sub
The CType(e.Item.Cells(0).Text) never gets the value ... it always errors out saying cannot convert "" to type integer...If I change and debug it to e.Item.Cells(4).Text I see the other field which is a date...But whenever I try e.Item.Cells(0).Text or e.Item.Cells(1).Text the debug shows "" even though in reality these are numbers. My grid shows the number when I view it but in debug no luck...All Im trying to do is delete a record...I cant even get it to pass that ID number to the function: Public Function DeleteActionItem(ByVal lngID As Long) Dim conMyData As SqlConnection Dim cmdDelete As SqlCommand Try conMyData = New SqlConnection(ConfigurationSettings.AppSettings("strConn")) cmdDelete = New SqlCommand("delete_action_item_by_action_item_id", conMyData) With cmdDelete .CommandType = CommandType.StoredProcedure 'add the parameters .Parameters.Add("@ActionItemID", SqlDbType.BigInt).Value = lngID conMyData.Open() 'open a connection .ExecuteNonQuery() 'execute it End With Catch ex As Exception Response.Write("An Error Occurred: " & ex.ToString()) 'clean up and close resources Finally cmdDelete = Nothing conMyData.Close() conMyData = Nothing End Try End Function
The code to delete should be fine (fairly simple). But I cannot seem to pass that ID number from the grid.Any help is appreciated.Thanks,Jon