Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
RowAdding event - VB advice required urgently
posted

Hi, I'm trying to write some code which inserts the values of a row inserted into the WebDataGrid into another table.  However, the code I've leveraged from a previous application isn't quite working.  Could someone take a look and get back to me?   The two lines which are causing me trouble are those which declare "insertedItem" and "parentItem" (I've bolded and underlined the errors).  I'm not entirely sure I'm using the correct event argument.  Perhaps that has something to do with the issue?  I need to resolve this today, as I'm giving a demo to our board tomorrow (who will be making a choice on which third-party control provider to use).

Protected Sub wdgResourceGroup_RowAdding(ByVal sender As Object, ByVal e As Infragistics.Web.UI.GridControls.RowAddingEventArgs) Handles wdgResourceGroup.RowAdding

Dim insertedItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
Dim parentItem As GridDataItem = e.Item.OwnerTableView.ParentItem

Dim datakey As String = parentItem.OwnerTableView.DataKeyValues(parentItem.ItemIndex)("FacilityID").ToString()
Dim contactId As Integer = CType(insertedItem("colContactId").FindControl("cboContactID"), DropDownList).SelectedValue

Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("BRAVA_ConnectionString").ConnectionString)

    Try
            conn.Open()


            Dim cmd As New SqlCommand("FacilityContactAdd", conn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.Add(New SqlParameter("FacilityID", datakey))
            cmd.Parameters.Add(New SqlParameter("ContactID", contactId))

            'Dim insertQuery As String = "INSERT into FacilityContacts(FacilityId, ContactID) values('" & datakey & "','" & contactId & "')"
            'Dim cmd As New SqlCommand(insertQuery, conn)
            cmd.ExecuteNonQuery()
            conn.Close()

        Catch ex As Exception
            wdgResourceGroup.Controls.Add(New LiteralControl("Unable to insert contact. Reason: " + ex.Message))
            e.Cancel = True
        Finally
        End Try

    End Sub

Parents
No Data
Reply
  • 37874
    posted

    Hi MartinWright6

    I have been researching both GridEditFormInsertItem and GridDataItem classes but it seems to me that they are not part of the Infragistics libraries. Most probably they are part of any other third party control provider and I am not familiar with them. I would suggest that you insert the desired values from the WebDataGrid to the other table's data source directly, if at all possible.

     

    Please let me know if you have any further questions.

Children
No Data