vendredi 24 juin 2016

Generate Response from Checkbox

I have my checkbox bound to a gridview and when I check those values, I hit the submit button to save the values and display them. The method I am using for this is Response.Write() Is there anyway I can deliver outputs by this method without using an array?

    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 = ""


        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 tempField = New TemplateField
        'GridView1.Columns.Add(tempField)
        'GridView1.Columns.Item(GridView1.Columns.Count - 1).HeaderText = "Column Header"
        'Dim CheckBox1 As CheckBox


        'Dim checkBoxColumn As New GridViewCheckBoxColumn()
        'checkBoxColumn.DataType = GetType(Integer)
        'checkBoxColumn.HeaderText = "Check Data"
        'checkBoxColumn.Width = 30
        'checkBoxColumn.Name = "CheckBoxColumn"
        'GridView1.Columns.Insert(0, checkBoxColumn)

        'Dim dr As DataRow

        'For i As Integer = 0 To GridView1.Rows.Count - 1
        '    CheckBox1 = New CheckBox
        '    CheckBox1.ID = "chkBxId"
        '    'AddHandler CheckBox1.CheckedChanged, AddressOf CheckBox1
        '    CheckBox1.AutoPostBack = True
        '    GridView1.Rows(i).Cells(GridView1.Columns.Count - 1).Controls.Add(CheckBox1) 'arguments are out of range
        'Next

        'GridView1.DataBind()

        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 Save(sender As Object, e As EventArgs) Handles Button6.Click



    Response.Write("ReportID")
    Response.End()

    'Dim sConstr As String = ConfigurationManager.ConnectionStrings("ds17701ConnectionString").ConnectionString
    'Dim Conn As New SqlConnection(sConstr)
    'Dim valsql As String = ""
    'Using Conn
    '    Conn.Open()
    '    Dim comm As New SqlCommand(valsql, Conn)
    '    comm.CommandText = "UPDATE sspCompanyReportList SET [CompanyID] = @CompanyID WHERE ReportId=@ReportId"
    '    'comm.Connnection = Conn
    '    For Each row As GridViewRow In GridView1.Rows
    '        'Get the HobbyId from the DataKey property.
    '        Dim ReportId As Integer

    '        'Get the checked value of the CheckBox.
    '        Dim Assigned As Integer = TryCast(row.FindControl("CheckBox1"), CheckBox).Checked

    '        'Save to database
    '        comm.Parameters.Clear()
    '        comm.Parameters.AddWithValue("@ReportID", ReportId)
    '        comm.Parameters.AddWithValue("@CompanyID", Assigned)
    '        'comm.ExecuteNonQuery()

    '    Next
    '    Conn.Close()
    '    Response.Redirect(Request.Url.AbsoluteUri)
    'End Using
End Sub




Aucun commentaire:

Enregistrer un commentaire