mercredi 22 juin 2016

Checkbox not showing next to GridView

I have a webform that when a someone selects a company from a dropdown menu, a gridview appears, showing the reports of each company. Right now, I just want to create a simple checkbox that will be added next to the GridView. However, there seems to be no definition of a GridViewCheckBoxColumn/DataGridViewCheckBoxColumn that would be needed to show a checkbox next to the GridView. Should I place it inside my Using Statement? Also, if anyone needs my HTML markup, please let me know.

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

Partial Class companydropdown
Inherits System.Web.UI.Page

Private 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("")

    'DropDownList2.Items.Add("")
    'DropDownList3.Items.Add("")
End Sub


Private Sub BindDropDownList(DropdownList1 As DropDownList, query As String, text As String, value As String, defaultText As String)

    'If Not IsPostBack Then
    '    ' Read sql server connection string from web.config file

    '    Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
    '    Dim Conn As New SqlConnection(sConstr)
    '    Dim cmd As SqlCommand = New SqlCommand("sspCompanyReportList", Conn)
    '    Dim ds As New DataSet()
    '    Dim ret As String = String.Empty


    '    'Set up Connection object and Connection String for a SQL Client

    '    'Try
    '    '    Using Conn
    '    '        Conn.Open()
    '    '        Dim comm As New SqlCommand("SELECT CompanyName FROM CompanyList ORDER BY CompanyName", Conn)
    '    '        cmd.CommandType = CommandType.StoredProcedure 'Setup Command Type
    '    '        cmd.CommandText = "sspCompanyReportList" ' Stored Procedure to Call
    '    '        cmd.CommandType = CommandType.StoredProcedure
    '    '        cmd.Connection.Open()
    '    '        Dim da As New SqlDataAdapter(comm)
    '    '        cmd.Parameters.Add("@CompanyID", SqlDbType.Text).Value = sConstr
    '    '        da.Fill(ds)
    '    '        ret = cmd.ExecuteScalar()
    '    '        cmd.Connection.Close()

    '    '    End Using

    '    'Catch ex As SqlClient.SqlException
    '    '    sConstr = "<SQL Exception>"
    '    'End Try


    '    'DropdownList1.DataSource = ds
    '    'DropdownList1.DataTextField = "CompanyName"
    '    'DropdownList1.DataValueField = "CompanyID"
    '    'DropdownList1.DataBind()

    'End If


End Sub

Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
    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
        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 = ""
        Dim message As String = String.Empty


        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

        'Add a CheckBox Column to the DataGridView at the first position.
        Dim checkBoxColumn As New GridViewCheckBoxColumn()
        checkBoxColumn.HeaderText = ""
        checkBoxColumn.Width = 30
        checkBoxColumn.Name = "CheckBoxColumn"
        GridView1.Columns.Insert(0, checkBoxColumn)

        'Dim dr As DataRow

        For Each dr As GridViewRow In GridView1.Rows
            Dim chkRow As CheckBox = TryCast(dr.Cells(0).FindControl("ReportID"), CheckBox)
        Next


        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




            'If DropDownList2.DataValueField = "1" Then
            '    TextBox1.Text = DropDownList2.SelectedValue
            '    TextBox1.Text = "M"
            '    'MsgBox(ds.Tables(0).Rows(i).Item(0))
            '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 DropdownList2_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

'    If DropDownList1.SelectedIndex > 0 Then
'        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 [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.Fill(ds)
'        End Using


'        'DropDownList1.Items.Add(New ListItem(""))


'        DropDownList2.DataTextField = "MemberTypeID"
'        DropDownList2.DataValueField = "MembershipStatus"
'        DropDownList3.DataTextField = "GroupID"
'        DropDownList3.DataValueField = "GroupID"
'        TextBox1.Text = DropDownList2.SelectedValue
'        'TextBox1.Text = Convert.ToString(DropDownList2.SelectedItem.Value)

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

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



'End Sub


'Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

'End Sub
End Class




Aucun commentaire:

Enregistrer un commentaire