1

I want to insert checkbox text only if they are checked. How to do that?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    TextBox1.Text = Request.QueryString("txt")
    Dim splitted As String() = TextBox1.Text.Split(",")
    For Each id As String In splitted
        Dim ctrl As Control = Page.FindControl("checkbox" & id)

        If Not ctrl Is Nothing Then
            Dim chkbox As CheckBox = DirectCast(ctrl, CheckBox)
            chkbox.Enabled = False
            Dim arrList As New ArrayList()
            'populate the list with some temp values
            arrList.Add(CheckBox1.Text)
            arrList.Add(CheckBox2.Text)

            'databind the list to our repeater
            Repeater1.DataSource = arrList
            Repeater1.DataBind()
        End If
    Next
End Sub

This code will add all checkboxes whether it is checked or not !

Can any body do that... so that only checked checkboxes would be added in array list

1 Answer 1

3

is this is what you are expecting?

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

TextBox1.Text = Request.QueryString("txt") 
Dim splitted As String() = TextBox1.Text.Split(",") 

For Each id As String In splitted 
    Dim ctrl As Control = Page.FindControl("checkbox" & id)

        If Not ctrl Is Nothing Then 
            Dim chkbox As CheckBox = DirectCast(ctrl, CheckBox) 
            chkbox.Enabled = False 
            Dim arrList As New ArrayList() 
            'populate the list with some temp values 
            if chkbox.Checked then
                  arrList.Add(chkbox.Text) 
            end if

            'databind the list to our repeater 
            Repeater1.DataSource = arrList 
            Repeater1.DataBind() 
        End If 
    Next 
End Sub 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.