2016-06-03 2 views
0

동적 웹 사이트를 만들고 싶습니다. 네 개의 라디오 버튼이있는 RadioButton List를 만들었습니다. 또한 11 개의 텍스트 상자를 만든 후 "If"함수를 만든 루프를 만들었습니다. 나는 6 개의 다른 텍스트 상자로 같은 루프를 만들었다. 내 목표는 하나의 라디오 버튼을 클릭하면 11 개의 텍스트 박스를 표시하고 다른 라디오 버튼을 클릭하면 6 개의 다른 텍스트 박스를 표시하는 것입니다. 대신 각 라디오 버튼을 클릭하면 모든 것이 나타납니다. 제 질문은하나의 라디오 버튼을 클릭하면 어떻게해야합니까? 11 개의 텍스트 박스가 나타납니다. 다른 라디오 버튼을 클릭하면 6 개의 다른 텍스트 박스가 나타납니다.라디오 버튼이있는 동적 컨트롤

도움 주셔서 감사합니다.

나는

Public Class WebForm1 
Inherits System.Web.UI.Page 


Protected MonRadioButton As New System.Web.UI.WebControls.RadioButtonList 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    MonRadioButton.RepeatDirection = RepeatDirection.Horizontal 
    MonRadioButton.Width = Unit.Pixel(400) 
    MonRadioButton.DataSource = Split("Click,OnChanged,Clicked,Changed", ",") 
    MonRadioButton.DataBind() 
    MonRadioButton.SelectedIndex = 0 

    MonRadioButton.AutoPostBack = True 

    PlaceHolder1.Controls.Add(MonRadioButton) 

    Dim MonTextBox As TextBox 

    For i As Integer = 0 To 10 

     MonTextBox = New TextBox 
     MonTextBox.ID = "TonTextbox" & i 
     MonTextBox.Text = MonTextBox.ID 

     If MonRadioButton.SelectedValue = "OnChanged" Then 

      MonTextBox.AutoPostBack = True 

      AddHandler MonTextBox.TextChanged, AddressOf MonTextBox_TextChanged 
     End If 

     PlaceHolder1.Controls.Add(MonTextBox) 
     PlaceHolder1.Controls.Add(New LiteralControl("<br>")) 

    Next 

    MonTextBox.Dispose() 

    If MonRadioButton.SelectedValue = "Click" Then 
     Dim LeBouton As New Button 
     LeBouton.Text = "valider" 

     AddHandler LeBouton.Click, AddressOf LeBouton_Click 
     PlaceHolder1.Controls.Add(LeBouton) 

    End If 
    PlaceHolder1.Controls.Add(New LiteralControl("<br>")) 
    PlaceHolder1.Controls.Add(New LiteralControl("<br>")) 

    Dim MonTextBox1 As TextBox 
    For i As Integer = 0 To 5 

     MonTextBox1 = New TextBox 
     MonTextBox1.ID = "TxtBox" & i 
     MonTextBox1.Text = MonTextBox1.ID 

     If MonRadioButton.SelectedValue = "Clicked" Then 
      MonTextBox1.AutoPostBack = True 
      AddHandler MonTextBox1.TextChanged, AddressOf MonTextBox1_TextChanged 
     End If 

     PlaceHolder1.Controls.Add(MonTextBox1) 
     PlaceHolder1.Controls.Add(New LiteralControl("<br>")) 

    Next 

    MonTextBox1.Dispose() 

    If MonRadioButton.SelectedValue = "Changed" Then 

    End If 
End Sub 

Private Sub MonTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) 

    Dim LeTextBox As New TextBox 
    LeTextBox = CType(sender, TextBox) 

    Response.Write("Vous venez de modifié : " & LeTextBox.ID & " avec la valeure : " & LeTextBox.Text) 

End Sub 

Private Sub MonTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) 
    Dim Txtbox As New TextBox 
    Txtbox = CType(sender, TextBox) 
    Response.Write("Vous venez de modifié : " & Txtbox.ID & " avec la valeure : " & Txtbox.Text()) 
End Sub 

Private Sub LeBouton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 

    Dim LeTextBox As TextBox 
    For i As Integer = 0 To 10 
     Try 

      LeTextBox = New TextBox 
      LeTextBox = CType(Page.FindControl("TonTextbox" & i), TextBox) 

      Response.Write("Texbox N°" & i & " : " & LeTextBox.Text & "<br>") 
     Catch ex As Exception 

     End Try 
    Next 

End Sub 

최종 클래스

답변

0

다음은 텍스트 상자의 생성에 영향을 미치는 당신의 둥근 버튼 나던의 선택된 값을 확인하는 조건이 모두가 당신이하고있는 경우 아래의 코드를 표시 roundbuttons는 텍스트 박스의 행동과 프로퍼티를 수정합니다. 이것은 당신은 아무것도에 생성 조절하지, 그래서 당신은 당신의 if 문 내부 루프에 대한 귀하의 배치해야합니다, 당신이 보는대로

If roundbutton=something then 
    'Here you change the behaviour of the textbox(postback, text, etc.) 
Else 

For i = 0 to 5 
    'Here you add the textboxes 
Next 

을 것입니다. 예 :

If MonRadioButton.SelectedValue = "Clicked" Then 
     MonTextBox1.AutoPostBack = True 
     AddHandler MonTextBox1.TextChanged, AddressOf MonTextBox1_TextChanged 

     For i As Integer = 0 To 5 

      MonTextBox1 = New TextBox 
      MonTextBox1.ID = "TxtBox" & i 
      MonTextBox1.Text = MonTextBox1.ID 

      PlaceHolder1.Controls.Add(MonTextBox1) 
      PlaceHolder1.Controls.Add(New LiteralControl("<br>")) 
     Next 
    End If 
+0

답장을 보내 주셔서 감사합니다. 당신이 설명했던 것을 시도했지만 여전히 작동하지 않습니다 ... if 문 안에 for 루프를 넣으면 모든 텍스트 상자가 사라집니다. 그러나 for 문 앞에 Else를 추가하면 텍스트 상자가 만들어집니다. 또한 각 라디오 버튼에 모든 텍스트 상자가 나타납니다. – georges619

관련 문제