【发布时间】:2012-03-16 16:13:32
【问题描述】:
我在 asp.net 中有一个如下所示的表单:
- 不到一年
Age in years[]____________
1,2 是单选按钮列表,其中 2 我有一个文本框,如果选择了 #2,它会接受输入。 此表单可以保存,但我在尝试显示结果时遇到了问题。
我在代码隐藏中创建了这些单选按钮列表和文本框。现在,当我试图显示答案时,我在 Gridview.rowDatabound 中再次创建这些控件,并使用 sqlDataReader 从数据库中检索它们的值。代码如下所示:
Dim txtOther As New TextBox
txtOther.ID = "txtOther"
Dim strOtherTxt As String = "Why the **** this isn't working"
fillResponse(rdoLstOption, txtChildID.Text, intQuestionID, strOtherTxt)
txtOther.Text = strOtherTxt
e.Row.Cells(2).Controls.AddAt(0, rdoLstOption)
e.Row.Cells(2).Controls.AddAt(1, txtOther)
fillResponse 看起来像这样:(这里我正在检查它是单选按钮还是复选框列表 - 我的 checkBoxList 也不起作用)
con.Open()
Dim rdr As SqlDataReader
rdr = cmd.ExecuteReader
If typeCtrlType.Name = "RadioButtonList" Then
fillRdoBtnList(ctrlToFill, rdr, strOtherText)
ElseIf typeCtrlType.Name = "CheckBoxList" Then
fillChckBoxList(ctrlToFill, rdr)
End If
con.Close()
最后 fillRdoBtnList 看起来像这样:
Private Sub fillRdoBtnList(ByRef rdoBtnListToFill As RadioButtonList, rdr As SqlDataReader, ByRef strOtherTxt As String)
While rdr.Read()
rdoBtnListToFill.SelectedValue = rdr.GetInt32(rdr.GetOrdinal("fkLuAnswerID"))
If Not rdr.IsDBNull(rdr.GetOrdinal("strOtherTxt")) Then
strOtherTxt = rdr.GetString(rdr.GetOrdinal("strOtherTxt"))
End If
End While
End Sub
我在 strOtherTxt 中得到了我期望的字符串,但它只是没有出现在我的表单中!我已经调试了我的程序,我发现了 txtOther。文本得到正确的文本,但即使那样它也不会出现在我的表单上!
有什么想法吗?
【问题讨论】: