오류 - lable shows 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 내부의 레이블은이 "구절"열에 묶여 있습니다. 나머지는 올바른 데이터를 보여줍니다.
다음 코드 블록을 참조하십시오.
.........................
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
키워드를 강조하려고 시도한 "구절"열의 행을 제외하고 데이터 가능한 dtresul의 다른 모든 행은 제대로 표시됩니다. SearchDemo 내부에서 루프 (키워드를 강조 표시)를 제거하면 잘 작동합니다. 누구 든지이 코드를 살펴보고 올바른 방향을 알려 주시겠습니까?
해결책
입력 텍스트는 dtresult.rows (i) .ToString 인 "System.Data.Datarow"입니다.
이 선을 변경하십시오 :
Dim strTemp As String = dtResult.Rows(i).ToString
에게:
Dim strTemp As String = dtResult.Rows(i)("verse").ToString
제휴하지 않습니다 StackOverflow