【问题标题】:How to add only checked checkboxes added in array list?如何仅添加在数组列表中添加的选中复选框?
【发布时间】:2011-05-12 14:22:03
【问题描述】:

我只想在选中复选框时插入复选框文本。该怎么做?

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

此代码将添加所有复选框,无论是否选中!

任何机构都可以这样做...这样只有选中的复选框才会添加到数组列表中

【问题讨论】:

    标签: asp.net vb.net


    【解决方案1】:

    这是你所期待的吗?

    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 
    

    【讨论】:

      猜你喜欢
      • 2014-03-03
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多