我有一個單選按鈕,它從數據庫中動態獲取它的值。當用戶檢查「其他」按鈕時,使textboxt可見
其中一個數據庫值稱爲「其他」。
如果用戶檢查此Other
單選按鈕,使文本框可見,以便用戶可以鍵入它。
有誰知道如何做到這一點?
下面的代碼不起作用。
<tr>
<td>
<asp:RadioButtonList ID="RadioButtonList1" runat="server"></asp:RadioButtonList>
<asp:TextBox ID="txtOther" runat="server" Visible="false" Font-Bold="False"></asp:TextBox>
<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
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
我也將要補充的是,其他的單選按鈕的值是33。
換句話說,<input id="DataList1_RadioButtonList1_5_2_5" type="radio" name="DataList1$ctl06$RadioButtonList1" value="33" />
由於多
好從你再次聽到並非常感謝您的幫助。 首先,我得到錯誤,TextBox1和RadioButton1沒有聲明。 我在TextBox1_OncTextChanged子上得到這個錯誤。 – Tairoc