我一直在試圖突出顯示在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