asp.net中高亮显示搜索关键字

来源:百度知道 编辑:UC知道 时间:2024/05/20 00:44:18
比如我已经做好了搜索页面,并且已经在DataGrid中将搜索出来的标题绑定了,现在我想让标题中和输入的关键子相同的文字显示为红色!该怎么弄?
private void databind()
{
OleDbConnection con = new OleDbConnection("Provider = Microsoft.jet.OLEDB.4.0; Data Source =" + Server.MapPath("/jszg/database/jszg.mdb"));
string selec = "select * from info where info_title like '%" + Session["keywords"].ToString() + "%'and info_typeid="+Session["typeid"]+" order by info_id desc";
OleDbDataAdapter da = new OleDbDataAdapter(selec, con);
DataSet ds = new DataSet();
da.Fill(ds, "news");
this.DataGrid1.DataSource = ds.Tables["news"].DefaultView;
this.DataGrid1.DataBind();
}
具体怎么绑定!!

Replace(Session["keywords"].ToString() ,"<font color='red'>"+Session["keywords"].ToString()+"</font>")

在绑定的时候替换 如 Replace("关键字","<font color='red'>关键字</font>")

上面的回答,也是我常用的做法,呵呵;