Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net gridview不突出显示搜索项_Asp.net_Vb.net - Fatal编程技术网

Asp.net gridview不突出显示搜索项

Asp.net gridview不突出显示搜索项,asp.net,vb.net,Asp.net,Vb.net,我设置了一个gridview在网页上显示搜索结果 我有下面的代码,“应该”用该词的粗体版本替换搜索词的任何实例 我试过很多不同的版本,但都不管用 Private Sub gvSearchResults_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSearchResults.RowDataBound If e.Row.RowType = D

我设置了一个gridview在网页上显示搜索结果

我有下面的代码,“应该”用该词的粗体版本替换搜索词的任何实例

我试过很多不同的版本,但都不管用

    Private Sub gvSearchResults_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvSearchResults.RowDataBound
    If e.Row.RowType = DataControlRowType.DataRow Then
        For Each cell As TableCell In e.Row.Cells
            If cell.Text.Contains(searchTerm) Then
                cell.Text = cell.Text.Replace(Session("SearchTerm"), "<span style='font-weight: bold;'>" & Session("SearchTerm") & "</span>")
            End If
        Next
    End If
End Sub
Private子gvSearchResults\u RowDataBound(发送者作为对象,e作为System.Web.UI.WebControl.GridViewRowEventArgs)处理gvSearchResults.RowDataBound
如果e.Row.RowType=DataControlRowType.DataRow,则
对于e.Row.Cells中的每个单元格作为TableCell
如果cell.Text.Contains(searchTerm)则
cell.Text=cell.Text.Replace(Session(“SearchTerm”)、“”&Session(“SearchTerm”)和“”)
如果结束
下一个
如果结束
端接头
我的逻辑有什么遗漏吗


谢谢

代码中有一个可疑的
searchTerm
变量

请注意,您在代码中使用的是
searchTerm
变量以及
会话(“searchTerm”)

我会这样做:

searchTerm = Session("SearchTerm")

If cell.Text.Contains(searchTerm) Then
     cell.Text = cell.Text.Replace(searchTerm , "<span style='font-weight: bold;'>" & searchTerm  & "</span>")
End If
searchTerm=会话(“searchTerm”)
如果cell.Text.Contains(searchTerm)则
cell.Text=cell.Text.Replace(searchTerm,“&searchTerm&”)
如果结束

如果
单元格.Text
为空,则gridview可能正在
单元格.Controls
集合中放置文字控件。你应该把这样的东西放在:

If e.Row.RowType = DataControlRowType.DataRow Then
    For Each cell As TableCell In e.Row.Cells
        If cell.Controls.Count > 0 Then
            Dim ltl as Literal = CType(cell.Controls(0), Literal)
            If ltl.Text.Contains(searchTerm) Then
                cell.Text = cell.Text.Replace(Session("SearchTerm"), "<span style='font-weight: bold;'>" & Session("SearchTerm") & "</span>")
            End If
        End If
    Next
End If
如果e.Row.RowType=DataControlRowType.DataRow,则
对于e.Row.Cells中的每个单元格作为TableCell
如果cell.Controls.Count>0,则
Dim ltl as Literal=CType(cell.Controls(0),Literal)
如果ltl.Text.Contains(searchTerm)则
cell.Text=cell.Text.Replace(Session(“SearchTerm”)、“”&Session(“SearchTerm”)和“”)
如果结束
如果结束
下一个
如果结束

是否已运行调试以验证该单元格。文本不是空的?很多时候gridviews会将这种性质的文本放入文本控件中。嗨,Joel,谢谢……我刚刚做了。出于某种原因,我所有的cell.text都是空的…即使它们在网页上都是全文是的,我试过了…我把变量放在那里,希望能有所帮助。那么,你是否按照Joel在评论中建议的那样运行调试?您是否已验证该单元格。文本包含值?您的断点是否指向
cell.Text=
code?我输入了一些断点,它显示为单元格。文本始终为空…这没有意义,因为我在页面上看到了所有结果ltl。文本也为空…但我在页面上的gridview中看到了结果…当我在Chrome开发工具中查看单元格时,HTML如下所示:Cardiac@999cm999:是的,我以前见过。这意味着集合中有多个控件。您也应该尝试使用1和2来查看它的去向。@999cm999:对不起,我指的是控件索引<代码>单元格控件(1)和
单元格控件(2)