Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP ASP.NET VB.NET
I am trying to insert data into a table using a formview and listview. i have a formview with just a dropdownlist and an insert button. i have a listview that displays 50 products at a time each with a checkbox next to it.
 
what i want to do is select an item from the formview dropdownlist, and check one, or multiple products from the listview and insert the values into a table.
 
Table example after making your selections and inserting:
 
formview DDL1 value2, listview value1
formview DDL1 value2, listview value25
formview DDL1 value2, listview value38
 

I get the error: object reference not set to instance of an object. I know what the error is but i dont know how to fix my code. It's blowing up at the insert section of my code.
 
can anyone help?
Here is my formview inserting code:
 
Protected Sub LitFormView_ItemInserting(sender As Object, e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles LitFormView.ItemInserting
    Dim cmd As New SqlCommand
    Dim con As New SqlConnection
    Dim label1 As Label = CType(LitFormView.FindControl("Label1"), Label)
    Dim Literature As DropDownList = CType(LitFormView.FindControl("DropDownList1"), DropDownList)
    Dim prodcheckbox As CheckBox = CType(ProdListView.FindControl("CheckBox1"), CheckBox)
    Dim catcheckbox As CheckBox = CType(CatListView.FindControl("CheckBox1"), CheckBox)
    Dim subcheckbox As CheckBox = CType(SubListView.FindControl("CheckBox1"), CheckBox)
    Dim PRDProdIDLabel As Label = CType(ProdListView.FindControl("PRDProdIDLabel"), Label)
    Dim PRDProdNameLabel As Label = CType(ProdListView.FindControl("PRDProdNameLabel"), Label)
 
    con.ConnectionString = SqlDataSource1.ConnectionString
    con.Open()
    cmd.Connection = con
 
    If Literature.SelectedValue = "" Then
        e.Cancel = True
        label1.Visible = True
        label1.Text = "You must select a Literature."
    Else
        label1.Visible = False
        If e.Cancel = False Then
            If prodcheckbox Is Nothing And catcheckbox Is Nothing And subcheckbox Is Nothing Then
                e.Cancel = True
                label1.Visible = True
                label1.Text = "You must Check at least 1 Product, or a Category, or a Sub-Category."
            Else
                label1.Visible = False
                If e.Cancel = False Then
 
'THIS IS WHERE I AM GETTING THE ERROR - I don't know how to get the listview row id or which row is being checked in the checkboxes.
                    'For Each ListItem In ProdListView.Items

                    If prodcheckbox.Checked Then
                        cmd.CommandText = "INSERT INTO LITProdData(LITProdLITID, LITProdName, LITProdPRDProdID, LITProdPRDProdName, LITUser) values('" & Trim(Literature.SelectedValue) & "', '" & Trim(Literature.SelectedItem.Text) & "', '" & Trim(PRDProdIDLabel.Text) & "', '" & Trim(PRDProdNameLabel.Text.Replace("'", "")) & "', '" & Session("UserInfo") & "')"
                        cmd.ExecuteNonQuery()
                    End If
                    'Next
                End If
                End If
            End If
        End If
 
End Sub
Posted 14-Oct-12 4:18am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 404
1 OriginalGriff 379
2 CPallini 145
3 Sergey Alexandrovich Kryukov 142
4 Hard_Rockz 115
0 OriginalGriff 5,634
1 Sergey Alexandrovich Kryukov 4,763
2 Peter Leow 2,954
3 Maciej Los 2,614
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid