带有正则表达式错误的单选按钮列表值
我正在尝试删除所有 html 标签,主要是从单选按钮列表项的值部分删除。如果没有正则表达式,它可以工作,但会导致其他错误。这是我所拥有的,但它给出的错误是:对象引用未设置到对象的实例。 System.NullReferenceException:未将对象引用设置为对象的实例。
rad.DataValueField = myStr.stripHTML(ds.Tables("session_name").ToString)
任何建议赞赏。
这是我的代码:
Dim rad As RadioButtonList = New RadioButtonList()
rad.ID = "rad" + i.ToString()
rad.DataSource = ds.Tables("conSessions")
rad.DataTextField = ds.Tables("conSessions").Columns("session_name").ToString
rad.DataValueField = myStr.stripHTML(ds.Tables("session_name").ToString)
rad.DataBind()
rad.DataBind()
rad.SelectedIndex = 0
phConcurrent.Controls.Add(rad)
Public Function stripHTML(ByVal e As String) As String
If (e = String.Empty) Or (IsDBNull(e) = True) Then
Return ""
Else
Return System.Text.RegularExpressions.Regex.Replace(e, "<[^>]*>", "", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
End If
End Function
I'm trying to remove any html tags, mainly from the value piece of a radiobuttonlist item. Without the regex, it works, but causes other errors. Here's what I have, but the error it gives is: Object reference not set to an instance of an object. System.NullReferenceException: Object reference not set to an instance of an object.
rad.DataValueField = myStr.stripHTML(ds.Tables("session_name").ToString)
Any advice appreciated.
Here's my code:
Dim rad As RadioButtonList = New RadioButtonList()
rad.ID = "rad" + i.ToString()
rad.DataSource = ds.Tables("conSessions")
rad.DataTextField = ds.Tables("conSessions").Columns("session_name").ToString
rad.DataValueField = myStr.stripHTML(ds.Tables("session_name").ToString)
rad.DataBind()
rad.DataBind()
rad.SelectedIndex = 0
phConcurrent.Controls.Add(rad)
Public Function stripHTML(ByVal e As String) As String
If (e = String.Empty) Or (IsDBNull(e) = True) Then
Return ""
Else
Return System.Text.RegularExpressions.Regex.Replace(e, "<[^>]*>", "", RegexOptions.IgnoreCase Or RegexOptions.Multiline)
End If
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想问题不在于正则表达式。可能您试图在这里获取错误的表:
您确定需要具有此名称而不是名称“conSessions”的表吗?
I suppose the problem is not in regex. Possibly you're trying to get wrong table here:
Are you sure that you need table with this name and not with name "conSessions" ?