我们有一个在线投票箱,为选民提供选择领导者的选择。
选民可以选择任何列出的候选人。
或者他们可以写出自己选择的候选人。
为了做到这一点,我们想在检查写入候选单选按钮时向选民提交一个文本框。
我该怎么做?
下面的RadiobuttonList代码是从数据库中动态填充的。
<asp:RadioButtonList ID="RadioButtonList1" runat="server" align="center" style="width:20px;height:20px;zoom:150%; white-space:nowrap;">
</asp:RadioButtonList>
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
Dim anstype As HiddenField = e.Item.FindControl("HiddenField1")
'Dim positionid As Label = e.Item.FindControl("Label3")
Dim positionid As HiddenField = e.Item.FindControl("HiddenField2")
Dim rbl As RadioButtonList = e.Item.FindControl("RadioButtonList1")
Dim cbl As CheckBoxList = e.Item.FindControl("CheckBoxList1")
Dim txt As TextBox = e.Item.FindControl("TextBox1")
Dim ds As DataSet = GetDataSet(positionid.Value)
Select Case anstype.Value
Case "S"
rbl.Visible = True
cbl.Visible = False
txt.Visible = False
rbl.DataSource = ds
rbl.DataTextField = "CandidateName"
rbl.DataValueField = "CandidateId"
rbl.DataBind()
Case "M"
rbl.Visible = False
cbl.Visible = True
txt.Visible = False
cbl.DataSource = ds
cbl.DataTextField = "CandidateName"
cbl.DataValueField = "CandidateId"
cbl.DataBind()
End Select
End If
End Sub
//来自VIEW SOURCE的代码
<tr>
<td><input id="DataList1_RadioButtonList1_5_2_5" type="radio" name="DataList1$ctl06$RadioButtonList1" value="27" /><label for="DataList1_RadioButtonList1_5_2_5">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl06$writeIn" type="text" id="DataList1_writeIn_5" />
<tr>
<td><input id="DataList1_RadioButtonList1_6_2_6" type="radio" name="DataList1$ctl07$RadioButtonList1" value="28" /><label for="DataList1_RadioButtonList1_6_2_6">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl07$writeIn" type="text" id="DataList1_writeIn_6" />
<tr>
<td><input id="DataList1_RadioButtonList1_7_1_7" type="radio" name="DataList1$ctl08$RadioButtonList1" value="29" /><label for="DataList1_RadioButtonList1_7_1_7">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl08$writeIn" type="text" id="DataList1_writeIn_7" />
<tr>
<td><input id="DataList1_RadioButtonList1_8_4_8" type="radio" name="DataList1$ctl09$RadioButtonList1" value="30" /><label for="DataList1_RadioButtonList1_8_4_8">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl09$writeIn" type="text" id="DataList1_writeIn_8" />
<tr>
<td><input id="DataList1_RadioButtonList1_9_1_9" type="radio" name="DataList1$ctl10$RadioButtonList1" value="31" /><label for="DataList1_RadioButtonList1_9_1_9">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl10$writeIn" type="text" id="DataList1_writeIn_9" />
<tr>
<td><input id="DataList1_RadioButtonList1_10_1_10" type="radio" name="DataList1$ctl11$RadioButtonList1" value="32" /><label for="DataList1_RadioButtonList1_10_1_10">Write In Candidate</label></td>
</tr>
<input name="DataList1$ctl11$writeIn" type="text" id="DataList1_writeIn_10" />
以下是截图。
答案 0 :(得分:0)
protected void RadioButtonList1_CheckedChanged(object sender, EventArgs e)
{
if (RadioButton1.Checked)
{
//if Radio Button is Checked the Textbox is visible
TextBox.Visible = true;
}
else if (!RadioButton1.Checked)
{
//if Radio Button is not Checked the Textbox is In-visible
TextBox.Visible = false;
}
...
//and show on for other checkbox
答案 1 :(得分:0)
尝试将其放在填充RadioButtonList的代码之后。
Dim rbWriteIn As New RadioButton()
rbWriteIn.Text = "Write in Candidate"
RadioButtonList1.Items.Add(rbWriteIn)
Dim tbCandidate As New TextBox()
RadioButtonList1Container.Controls.Add(tbCandidate) 'the container of RBL1
tbCandidate.Visible = False
Private Sub showTextBox(ByVal s as Object, ByVal e as EventArgs) _
Handles RadioButtonList1.CheckedChanged
If rbWriteIn.Checked Then
tbCandidate.Visible = True
Else
tbCandidate.Visible = False
End If
End Sub