Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am working on code that when someone selects a company from a dropdownlist, the first grid of the company will display. I have checkboxes next to the grid. Where I am stuck is that I need to check one or more rows that will call a table from a database and display as a grid of reports. In that table, there is a column that shows checkboxes of what is visible in that company or not. In essence, how do I display results to a different gridview what I have checked from the previous/company gridview? Here is my code:

VB.NET
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.UI.WebControls

Partial Class companydropdown

    Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        DropDownList1.Items.Add("")

    End Sub




    Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
        Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
        Dim Conn As New SqlConnection(sConstr)
        Dim ds As New DataSet()
        Dim dt As New DataTable
        Dim valsql As String = ""

        DropDownList2.Items.Clear()

        'DropDownList2.Enabled = False
        'DropDownList3.Enabled = False
        'TextBox1.Enabled = False

        If DropDownList1.SelectedIndex > 0 Then
            'Dim query As String = String.Format("CompanyName", DropDownList1.SelectedIndex)
            'DropDownList3.Enabled = True
            'DropDownList2.Enabled = True
            'DropDownList1.Enabled = True
            'TextBox1.Enabled = True



            valsql = "SELECT [CompanyID], [CompanyName], [MemberTypeID], [MembershipStatus], [GroupID]  FROM CompanyList WHERE COMPANYID = " & DropDownList1.SelectedValue




            Using Conn
                Conn.Open()
                Dim comm As New SqlCommand(valsql, Conn)
                Dim da As New SqlDataAdapter(comm) 'da serves as the new sqldataadapter for my sqlcommand
                da.Fill(ds)
                da.Fill(dt)
                Conn.Close() 'added to close connection
            End Using


            For i = 0 To ds.Tables(0).Rows.Count - 1
                If ds.Tables(0).Rows(i).Item(3).ToString = "M" Then
                    DropDownList2.Items.Insert(0, "Member")
                    DropDownList2.Items.Insert(1, "Non-Member")
                    TextBox1.Text = "M"
                Else
                    DropDownList2.Items.Insert(0, "Non-Member")
                    DropDownList2.Items.Insert(1, "Member")
                    TextBox1.Text = "NM"
                End If

            Next




            'Bind sql server data into the Dropdown List
            'DropDownList2.DataBind()
            'DropDownList3.DataBind()
            'TextBox1.DataBind()

        Else

            DropDownList2.Items.Clear()
            DropDownList3.Items.Clear()
            TextBox1.Text.ToString()
            DropDownList1.Items.Clear()
        End If
    End Sub

    Protected Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click

        Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
        Dim Conn As New SqlConnection(sConstr)
        Dim ds As New DataSet()
        Dim valsql As String = ""


        'valsql = "SELECT * FROM [ReportList] WHERE ReportVisible = " & True
        valsql = "SELECT * FROM [ReportList] ORDER BY [ReportID]"

        Using Conn
            Conn.Open()
            Dim comm As New SqlCommand(valsql, Conn)
            Dim da As New SqlDataAdapter(comm) 'da serves as the new sqldataadapter for my sqlcommand
            da.Fill(ds)
            Conn.Close() 'added to close connection
        End Using




    End Sub


    
End Class


What I have tried:

To set a for loop or create an array that will read what rows have been checked in gridview NOT datagridview, to output results. I have created a button that captures the checked rows.
Posted

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900