2010-11-19 2 views
1

Я хочу вставить этот флажок только в том случае, если они отмечены. .. как это сделать ..Как добавить только отмеченные флажки, добавленные в список массивов?

Protected Sub Page_Load (ByVal отправитель As Object, ByVal е Как System.EventArgs) Ручки Me.Load TextBox1.Text = Request.QueryString (".txt") Dim расщепляется As String() = TextBox1.Text.Split (" ") Для каждого идентификатора As String In расщепляется Dim Ctrl As Control = Page.FindControl (" флажок" & ид)

 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 

Этот код добавит все галочки проверяется или нет!

Может ли тело сделать это ... так, что только проверенные флажки будут добавлены в список массива

ответ

3

это то, что вы ожидаете?

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 
Смежные вопросы