GridView绑定中将搜索的关键字颜色设置为红色!怎么做?

ygnmn 2013-07-23 10:14:05
GridView绑定中将搜索的关键字颜色设置为红色!怎么做?
在线等!
...全文
203 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
ygnmn 2013-07-23
  • 打赏
  • 举报
回复
搞定了 多谢各位
逍遥卐梦 2013-07-23
  • 打赏
  • 举报
回复
前段写JS 页面加载时调用
ygnmn 2013-07-23
  • 打赏
  • 举报
回复
要是就让关键字变红色怎么改写
ygnmn 2013-07-23
  • 打赏
  • 举报
回复
引用 4 楼 Chinajiyong 的回复:
可以在GridView1_RowDataBound事件里写 大概这样

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
string str = e.Row.Cells[0].Text; //Cells[0]为第一列 
//查找关键字 
if (str.Contains("keyWord")) 
{ 
string newStr = "<font color='red'>" + str + "</font>"; 

e.Row.Cells[0].Text = str.Replace("keyWord", newStr); 
} 

} 

}
版主方法用了 好用
  • 打赏
  • 举报
回复
$("").html().Replace(key, "<font color='red'>"+key+"</font>");
  • 打赏
  • 举报
回复
static MarkRed(this string src, string key) { return string.IsNullOrEmpty(src) ? src : src.Replace(key, "<font color='red'>"+src+"</font>"); }
  • 打赏
  • 举报
回复
写个扩展方法 static MarkRed(this string src, string key) { return string.IsNullOrEmpty(src) ? src : src.Replay(key, "<font color='red'>"+src+"</font>"); } <%# (Eval("title") as string).MarkRed(keyword)%>
EnForGrass 2013-07-23
  • 打赏
  • 举报
回复
e.Row.RowType == DataControlRowType.DataRow e.Row.RowType 是指当前行的类型 DataControlRowType 是GridView的行的类型集合 其中的DataRow是数据绑定行 这个判断语句的意思就是判断当前行是不是数据绑定行 是绑定时候用来过滤标题行和序号行等等非数据绑定行的 更多详情参考http://hi.baidu.com/xiaozha87/item/c65c61f06e5824c5a935a2cc str.Contains("keyWord") 就是判断str中是否包含keyWord
ygnmn 2013-07-23
  • 打赏
  • 举报
回复
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) //请注释 { string str = e.Row.Cells[0].Text; //Cells[0]为第一列 //查找关键字 if (str.Contains("keyWord")) //请注释 { string newStr = "<font color='red'>" + str + "</font>"; e.Row.Cells[0].Text = str.Replace("keyWord", newStr); //这个是替代能看懂 } } } RowDataBound事件就是数据榜定之后对Gridview的一些自定义操作,可以改变颜色 版主请具体说明一下每行的意识 有几行不明白
全栈极简 2013-07-23
  • 打赏
  • 举报
回复
可以在绑定后台中给Key赋值,类似于4楼的做法。
  • 打赏
  • 举报
回复
引用 3 楼 ygnmn 的回复:
key 为关键字 现在 datatable 有了 gridview1.datasource=datatable this.gridview1.datad 之后怎么把关键字变红色 能具体点么 我基础差
绑定这么写 <%# "<span style='color:Red'>"+Convert.ToString(Eval("key"))+"</span>"%>
persuit666 2013-07-23
  • 打赏
  • 举报
回复
表达不清楚,你是想关键字段颜色变红色还是有个搜索框,搜索到的列数据中对应的字变红色?
EnForGrass 2013-07-23
  • 打赏
  • 举报
回复
可以在GridView1_RowDataBound事件里写 大概这样

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
if (e.Row.RowType == DataControlRowType.DataRow) 
{ 
string str = e.Row.Cells[0].Text; //Cells[0]为第一列 
//查找关键字 
if (str.Contains("keyWord")) 
{ 
string newStr = "<font color='red'>" + str + "</font>"; 

e.Row.Cells[0].Text = str.Replace("keyWord", newStr); 
} 

} 

}
ygnmn 2013-07-23
  • 打赏
  • 举报
回复
key 为关键字 现在 datatable 有了 gridview1.datasource=datatable this.gridview1.datad 之后怎么把关键字变红色 能具体点么 我基础差
se7en 2013-07-23
  • 打赏
  • 举报
回复
写个css样式 ,然后搜索出来的结果引用这个样式
杰子 2013-07-23
  • 打赏
  • 举报
回复
jquery,过滤关键字。总之,用前段技术

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧