我一直在试图突出显示在DataTable中的搜索结果。首先,我遍历DataTable行并调用一个函数来查找匹配关键字以突出显示这些单词,然后使用带有突出显示的关键字的新字符串更新DataTable行。错误 - 标签显示System.Data.DataRow
我将DataTable dtResult绑定到DataList。直到我加入这个代码块SearchDemo功能突出关键字它工作得很好:
For i = 0 To dtResult.Rows.Count - 1 Step 1
Dim strTemp As String = dtResult.Rows(i).ToString
strVerse = blHelper.Highlight(s, strTemp)
dtResult.Rows(i)("verse") = strVerse
Next
DataList控件内的标签束缚,这“诗”一栏显示的System.Data.DataRow。其余显示正确的数据。
请参阅下面的代码块:
.........................
Public Shared Function SearchDemo(ByVal s As String) As DataTable
Dim dtResult As New DataTable
dtResult = SearchDetail(s)
Dim i As Integer = dtResult.Rows.Count
For i = 0 To dtResult.Rows.Count - 1 Step 1
Dim strTemp As String = dtResult.Rows(i).ToString
strVerse = blHelper.Highlight(s, strTemp)
dtResult.Rows(i)("verse") = strVerse
Next
Return dtResult
End Function
... .................................................. ...
下面这两个函数工作正常。
'Highlight the keywords in the returned result
Public Shared Function Highlight(ByVal Search_Str As String, ByVal InputTxt As String) As String
' Setup the regular expression and add the Or operator.
Dim RegExp As Regex = New Regex(Search_Str.Replace(" ", "|").Trim(), RegexOptions.IgnoreCase)
' Highlight keywords by calling the MatchEvaluator delegate each time a keyword is found.
Highlight = RegExp.Replace(InputTxt, New MatchEvaluator(AddressOf ReplaceKeyWords))
' Set the Regex to nothing.
RegExp = Nothing
End Function
Public Shared Function ReplaceKeyWords(ByVal m As Match) As String
Return "<b>" & m.Value & "</b>"
End Function
DataTable中dtResul的每个其他行正常显示,只是我想强调的关键词列“诗”的行。如果我在SearchDemo中删除循环(以突出显示关键字),它将正常工作。 任何人都可以看看这些代码,请指点我正确的方向吗?
谢谢..啊..我的眼睛..不介意告诉我如何调试某事像这样还,如果可能的话 – 2009-03-05 07:50:41