2012-03-15 142 views
0
string search= textbox1.text; 

protected void grd_RowDataBound(Object sender, GridViewRowEventArgs e) 
{   
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     foreach(TableCell tc in e.Row.Cells) 
     { 
      tc.Text = tc.Text.Replace(search, "<span style='color:Red;'>" + search + "</span>"); 
     } 
    }    
} 

我使用的代码要突出一个字搜索,但是当我在调试浏览器按钮:编辑,选择,删除不存在的。而如果我删除了事件按钮回来了。GridView控件上的RowDataBound,编辑,删除,选择选项dissappeared

我该怎么做要做到这一点是检查,看看是否单元格中包含控制

回答

0

的一种方式......它看起来像你的网格视图细胞的其余部分只包含文本,并要附加跨度进入单元格以突出显示搜索值。

string search= textbox1.text; 

protected void grd_RowDataBound(Object sender, GridViewRowEventArgs e) 
{   
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     foreach(TableCell tc in e.Row.Cells) 
     { 
      if (tc.Controls.Count == 0){ 
       tc.Text = tc.Text.Replace(search, "<span style='color:Red;'>" + search + "</span>"); 
      } 
     } 
    }    
} 

这将绕过包含选择,编辑和删除控件的单元格。还有文本框和标签以及类似的东西。希望这可以帮助。