当前位置:编程学习 > C#/ASP.NET >>

求教关于关键字模糊查询,查询结果的关键字变色问题!大家帮帮忙啊!

我想在查询结果中把我查询的模糊关键字变色显示,比方说 在前台页面输入fd,在前一个页面把包含fd的所有数据字段(标题 ,内容)变色显示,但是现在有一个问题,如果是 fd连在一起的话,就能变色显示。但 f d中间有一个空格的话,就不能变色显示。 代码如下:


public void fillDataList()
{
OleDbConnection cn=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data source="+Server.MapPath("../data/Wenda.mdb"));

cn.Open();

TextBox2.Text=Request.QueryString["suo"];
string   str=TextBox2.Text.Replace(" ","|");

string[] arrStr=str.Split('|');
string   mysql="select Wid,problem, content  from   problems   where   1=1";   
for(int   i=0;i<arrStr.Length;i++)   
{   
mysql   +=   "   And   problem   like   '%"   +  arrStr[i]   +   "%'";   
}   
    

OleDbDataAdapter da=new OleDbDataAdapter(mysql,cn);
DataSet ds=new DataSet();

da.Fill(ds,"problems");   

            
for(int i=0;i<ds.Tables["problems"].Rows.Count;i++)   
{

if(SerchKey !=null)
{
ds.Tables["problems"].Rows[i]["problem"]=(string)ds.Tables["problems"].Rows[i]["problem"].ToString().Replace(SerchKey,"<font color='#FF0000'>"+SerchKey+"</font>"); 
ds.Tables["problems"].Rows[i]["content"]=(string)ds.Tables["problems"].Rows[i]["content"].ToString().Replace(SerchKey,"<font color='#FF0000'>"+SerchKey+"</font>");  
}
}

this.DataList1.DataSource =ds;
this.DataList1.DataBind ();
cn.Close ();

}


Request.QueryString["suo"] 从上一个页面传来的值 

 表名 problems  数据字段 Wid,problem,content  


希望大家能帮我解决这个难题!谢谢大家了!   
--------------------编程问答-------------------- DataList1绑定数据时使用Replace("","<font color='red'</font>");替换数据
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Replace(“”, " <span style='color:red'>" + keyWord + " </span>"); 

或 <ItemTemplate> 
        <%# Eval("Title").ToString().Replace("", " <font color='red'></font>") %> 
    </ItemTemplate> 
--------------------编程问答-------------------- 每天回帖即可获得10分可用分! --------------------编程问答-------------------- 每天回帖即可获得10分可用分! --------------------编程问答-------------------- f d中间有个空格的话, 要用正则表达式 --------------------编程问答-------------------- 就是要替换
还有如果要分词的话,还需要分词技术
比如
招聘机遇
应该把所有包含招聘,还有所有包含机遇的都显示出来
考虑分词和全文索引 --------------------编程问答-------------------- DataList1绑定数据时使用Replace(""," <font color='red' </font>");替换数据 
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Replace(“”, " <span style='color:red'>" + keyWord + " </span>"); 

或 <ItemTemplate> 
        <%# Eval("Title").ToString().Replace("", " <font color='red'> </font>") %> 
    </ItemTemplate> 

说的这个我就不明白啦 
DataList1绑定数据时使用Replace(""," <font color='red' </font>");替换数据 
e.Row.Cells[0].Text = e.Row.Cells[0].Text.Replace(“”, " <span style='color:red'>" + keyWord + " </span>"); 
要写那呀 是写在那的类呀

还有就是 
这个<ItemTemplate> 
        <%# Eval("Title").ToString().Replace("", " <font color='red'> </font>") %> 
    </ItemTemplate>
报错 字符串的长度不能为零。
参数名: oldValue 
 
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,