日期:2014-05-19  浏览次数:20484 次

[求救]关键字高亮显示
我用的语言是C#,语句如下:
string   connStr,selectCmd;
connStr= "Provider=Microsoft.Jet.OLEDB.4.0;Data   Source= "   +   Server.MapPath( "Query_system_Database.mdb ");
selectCmd= "SELECT   index_Id   AS   指标代码,index_Name   AS   指标名称,index_Paraphrase   AS   指标名称解释   FROM     [Database] ";
OleDbConnection   conn;
OleDbDataAdapter   myAdapter;
DataSet   myDataSet=new   DataSet();
conn=new   OleDbConnection(connStr);
myAdapter=new   OleDbDataAdapter(selectCmd,conn);
myAdapter.Fill(myDataSet);
DataTable   myDataTable=myDataSet.Tables[0];
DataView   myDataView=new   DataView(myDataTable);
myDataView.RowFilter= "指标名称   Like   '% "+keyStr+ "% ' ";

                        if(myDataView.Count==0)
{
lblCount.Text= "对不起!没有找到你想要的相关记录! ";
}


我想实现在.aspx的网页显示搜索的数据记录(此功能已实现),现在想实现关键字keyStr在网页中的高亮显示,谢谢大家的帮助!!请打家在我的代码基础上进行修改,不要利用其他方法,除非在我的方法基础上不可以实现关键字高亮显示。。。谢谢了

------解决方案--------------------
for(int i=0;i <datagrid.Items.Count;i++)
{
string str=datagrid.Items[i].Cells[指标名称 's Index].Text;
datagrid.Items[i].Cells[指标名称 's Index].Text=str.Replace(ViewState[ "searchKey "].ToString(), " <font color=\ "red\ "> "+ViewState[ "searchKey "].ToString()+ " </font> ");

}
ViewState[ "searchKey "]=搜索关键字;