동적 웹 사이트를 만들고 싶습니다. 네 개의 라디오 버튼이있는 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
최종 클래스
답장을 보내 주셔서 감사합니다. 당신이 설명했던 것을 시도했지만 여전히 작동하지 않습니다 ... if 문 안에 for 루프를 넣으면 모든 텍스트 상자가 사라집니다. 그러나 for 문 앞에 Else를 추가하면 텍스트 상자가 만들어집니다. 또한 각 라디오 버튼에 모든 텍스트 상자가 나타납니다. – georges619