第一个计时器。请给我一些殴打。
我有一个荒谬的要求。
我们有一组从sql server数据库动态生成的单选按钮。
例如,有一个Questions表,其中一列是ChoiceType。
ChoiceType有3个值,S表示单选(单选按钮); M为多种选择(复选框);和文本框的T。
这是标记:
然后是codebehind片段
<tr>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
<asp:TextBox ID="TextBox1" runat="server" Columns="30" Font-Bold="False" Rows="5"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
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 questionid As Label = e.Item.FindControl("Label3")
Dim questionid 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(questionid.Value)
Select Case anstype.Value
Case "S"
rbl.Visible = True
cbl.Visible = False
txt.Visible = False
rbl.DataSource = ds
rbl.DataTextField = "Choice"
rbl.DataValueField = "ChoiceID"
rbl.DataBind()
Case "M"
rbl.Visible = False
cbl.Visible = True
txt.Visible = False
cbl.DataSource = ds
cbl.DataTextField = "Choice"
cbl.DataValueField = "ChoiceID"
cbl.DataBind()
Case "T"
rbl.Visible = False
cbl.Visible = False
txt.Visible = True
End Select
End If
End Sub
我的问题:是否可以将文本框(T)作为RadiobuttonList选项的一部分呈现,以便用户需要做的是使用带有文本框值的单选按钮选中该框并在文本框中输入一些文本?
下面是截图,希望能说明我的观点。
抱歉,可以立即发布图片。
感谢您的耐心等待。
答案 0 :(得分:1)
这就是你需要的。
我假设您正在使用datalist
<ItemTemplate>
<table>
<tr>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
<asp:TextBox ID="TextBox1" runat="server" Columns="30" Font-Bold="False" Rows="5"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TextBoxOptional" runat="server" Visible="false" Columns="30" Font-Bold="False" Rows="5" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
</table>
</ItemTemplate>
现在在项目数据绑定中,如果是M
Case "M"
rbl.Visible = False
cbl.Visible = True
txt.Visible = False
cbl.DataSource = ds
cbl.DataTextField = "Choice"
cbl.DataValueField = "ChoiceID"
cbl.DataBind()
TextBoxOptional.Visible = true// assuming that you will find control on above lines.
答案 1 :(得分:0)
如果所选的radiobutton文本为&#34;其他&#34;将一个带有可见false的文本框放在radiututton OnCheckedChanged事件上。然后使文本框Visible True。
试试这个......
Protected Sub RadioButton1_OnCheckedChanged(sender As Object, e As EventArgs)
Dim RadioButton1 As RadioButton = TryCast(sender, RadioButton)
Dim datalistrow As DataList = TryCast(RadioButton1.NamingContainer, DataList)
Dim TxtOther As TextBox = TryCast(datalistrow.FindControl("TxtOther"), TextBox)
TxtOther.Visible = True
End Sub
<tr>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
<asp:TextBox ID="TextBox1" runat="server" Columns="30" Font-Bold="False" Rows="5"
TextMode="MultiLine"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="TxtOther" runat="server" Visible="False" Columns="30" Font-Bold="False" Rows="5"
TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
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 questionid As Label = e.Item.FindControl("Label3")
Dim questionid 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(questionid.Value)
Select Case anstype.Value
Case "S"
rbl.Visible = True
cbl.Visible = False
txt.Visible = False
rbl.DataSource = ds
rbl.DataTextField = "Choice"
rbl.DataValueField = "ChoiceID"
rbl.DataBind()
Case "M"
rbl.Visible = False
cbl.Visible = True
txt.Visible = False
cbl.DataSource = ds
cbl.DataTextField = "Choice"
cbl.DataValueField = "ChoiceID"
cbl.DataBind()
Case "T"
rbl.Visible = False
cbl.Visible = False
txt.Visible = True
End Select
End If
End Sub
答案 2 :(得分:0)
Protected Sub RadioButton1_OnCheckedChanged(sender As Object, e As EventArgs)
Dim RadioButton1 As RadioButtonList = TryCast(sender, RadioButtonList)
If RadioButton1 IsNot Nothing Then
If RadioButton1.SelectedValue = "Other" Then
Dim datalistrow As DataList = TryCast(RadioButton1.NamingContainer, DataList)
Dim TxtOther As TextBox = TryCast(datalistrow.FindControl("TxtOther"), TextBox)
TxtOther.Visible = True
End If
End If
End Sub