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

SQL全文检索 打开搜索到的文件让关键字显示红色怎么做

c#和SQL2000做的全文检索,现在想让搜索打的文件打开以后,关键字显示红色怎么做,请各位大侠指较,   
这是我的搜索文件程序   
using       System;   
using       System.Data;   
using       System.Configuration;   
using       System.Web;   
using       System.Web.Security;   
using       System.Web.UI;   
using       System.Web.UI.WebControls;   
using       System.Web.UI.WebControls.WebParts;   
using       System.Web.UI.HtmlControls;   
using       System.Data.Sql;   
using       System.Data.SqlClient;   
using       System.IO;   

public       partial       class       _Default       :       System.Web.UI.Page       
{   
                
                protected       void       Page_Load(object       sender,       EventArgs       e)   
                {   
                                if       (!IsPostBack)   
                                {   
                                            


                                }   

                }   
         protected       void       Button1_Click(object       sender,       EventArgs       e)   
                {   
                                SqlConnection       myConn       =       new       SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");   
                                string       seletc       =       "select       *       from       search1       where       contains(MyImage,       '"       +TextBox1.Text       +       "')";   
                            
                                SqlDataAdapter       da       =       new       SqlDataAdapter(seletc,       myConn);   
                                DataSet       ds       =       new       DataSet();   
                                da.Fill(ds,       "search");   
                                DataGrid1.DataSource       =       ds.Tables["search"].DefaultView;   
                                DataGrid1.DataBind();   

                }   
                protected       void       Button2_Click(object       sender,       EventArgs       e)   
                {   
                                TextBox1.Text       =       "";   
                }   
                protected       void       DataGrid1_ItemDataBound(object       sender,       DataGridItemEventArgs       e)   
                {   
                                string       str;   
                                if       (e.Item.ItemType       ==       ListItemType.AlternatingItem       ¦   ¦       e.Item.ItemType       ==       ListItemType.Item)   
                                {   
                                                str       =       e.Item.Cells[4].Text.ToString();   
                                                str.Replace("+       TextBox1.Text       +",       "   <font       color=red>   +TextBox1.Text+   </font>   ");   

                                }   
                }   
}   
这是我打开文件的程序   
using       System;   
using       System.Collections;   
using       System.Configuration;   
using       System.Data;   
using       System.Linq;   
using       System.Web;   
using       System.Web.Security;   
using       System.Web.UI;   
using       System.Web.UI.HtmlControls;   
using       System.Web.UI.WebControls;   
using       System.Web.UI.WebControls.WebParts;   
using       System.Xml.Linq;   
using       System.Data.Sql;   
using       System.Data.SqlClient;   
using       System.IO;   

public       partial       class       showfile       :       System.Web.UI.Page   
{   
                protected       void       Page_Load(object       sender,       EventArgs       e)   
                {   
                                if       (!IsPostBack)   
                                {   
                                }   
                                string       sql       =       "select               *               from               search1               where               id               =           '"       +       Request.QueryString["id"]           +       "'";   
                                SqlConnection       connection       =       new       SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");   
                                SqlCommand       command       =       new       SqlCommand(sql,       connection);   
                                connection.Open();   
                                SqlDataReader       dr       =       command.ExecuteReader();   
                                if       (dr.Read())   
                                {   
                                                Response.Clear();   
                                                Response.Charset       =       "GB2312";   
                                                
                                                Response.ClearHeaders();   
                                                Response.BufferOutput       =       true;   
                                                Response.AddHeader("content-type",       Request.QueryString["FileType"]);   
                                                Response.ContentType       =       "application/msword";   
                                                Response.BinaryWrite((byte[])dr["MyImage"]);   
     }   
                     dr.Close();   
                                connection.Close();   

                }   
}   
我知道用replace替换关键字能显示红色,但不知道具体怎么套用请各位高手给个明示,谢谢,小弟是初学者请各位大侠帮忙谢谢,在线等 --------------------编程问答--------------------
private string SetBackBright(string strSearchResult,string strSearchWord)
{
string Ret = strSearchResult;
//Change multiple spaces which is continuous into one space, or else wrong will happen.
strSearchWord = Regex.Replace(strSearchWord,"\\s+"," ");
string[] arrySearchWord = strSearchWord.Trim().Split(new char[]{' '});
foreach(string s in arrySearchWord)
{
string strSearchWordFormat = this.DealWithSpecialCharacter(s);
Ret = Regex.Replace(Ret, strSearchWordFormat,"<font color=#C60A00>" + s + "</font>",RegexOptions.IgnoreCase | RegexOptions.Multiline);
}

return Ret;
}
--------------------编程问答-------------------- Response.BinaryWrite((byte[])dr["MyImage"]);       

对dr["MyImage"]做替换,dr["myImage"].ToString().Replace(关键字,"<font color=red>"+关键字+"</font>"); --------------------编程问答-------------------- 帮你顶一下 --------------------编程问答-------------------- up --------------------编程问答-------------------- 用InnerHTML前台显示.
str=SetBackBright(..,.);
lable1.innerhtml=str; --------------------编程问答-------------------- using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
        }
        string sql = "select   *   from   search1   where   id   =  '" + Request.QueryString["id"]  + "'";
        SqlConnection connection = new SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");
        SqlCommand command = new SqlCommand(sql, connection);
        connection.Open();
        SqlDataReader dr = command.ExecuteReader();
        if (dr.Read())
        {
            Response.Clear();
            Response.Charset = "GB2312";
            
            Response.ClearHeaders();
            Response.BufferOutput = true;
            Response.AddHeader("content-type", Request.QueryString["FileType"]);
            Response.ContentType = "application/msword";
            dr["MyImage"].ToString().Replace(TextBox1.Text, "<font color=red>" + TextBox1.Text + "</font>");
    Response.BinaryWrite((byte[])dr["MyImage"]);
    
     }
      dr.Close();
        connection.Close();
    }
   protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection myConn = new SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");
        string seletc = "select * from search1 where contains(MyImage, '" +TextBox1.Text + "')";
       
        SqlDataAdapter da = new SqlDataAdapter(seletc, myConn);
        DataSet ds = new DataSet();
        da.Fill(ds, "search");
        DataGrid1.DataSource = ds.Tables["search"].DefaultView;
        DataGrid1.DataBind();

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
    }
    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        string str;
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            str = e.Item.Cells[4].Text.ToString();
            str.Replace("+ TextBox1.Text +", "<font color=red>+TextBox1.Text+</font>");

        }
    }
}
我刚才改了一下我的程序但还是有错调试的时候说这一句有错大家再帮忙看看谢谢
            dr["MyImage"].ToString().Replace(TextBox1.Text, "<font color=red>" + TextBox1.Text + "</font>");
提示错误为 --------------------编程问答-------------------- 刚才修改了一下前台的TextBox加了一个默认文字后台程序不出问题了
但打开文件以后没效果关键字也没有替换成红色请大家帮忙看看是怎么回事?谢谢在线等
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
       
        if (!IsPostBack)
        {
        }
        string sql = "select   *   from   search1   where   id   =  '" + Request.QueryString["id"]  + "'";
        SqlConnection connection = new SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");
        SqlCommand command = new SqlCommand(sql, connection);
        connection.Open();
        SqlDataReader dr = command.ExecuteReader();
        if (dr.Read())
        {
            Response.Clear();
            Response.Charset = "GB2312";
            
            Response.ClearHeaders();
            Response.BufferOutput = true;
            Response.AddHeader("content-type", Request.QueryString["FileType"]);
            Response.ContentType = "application/msword";
          
        Response.BinaryWrite((byte[])dr["MyImage"]);
            dr["MyImage"].ToString().Replace(TextBox1.Text, "<font color=red>" + TextBox1.Text + "</font>");
    
     }
      dr.Close();
        connection.Close();
    }
   protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection myConn = new SqlConnection("server=(local);database=object;uid=sa;pwd=11331144;");
        string seletc = "select * from search1 where contains(MyImage, '" +TextBox1.Text + "')";
       
        SqlDataAdapter da = new SqlDataAdapter(seletc, myConn);
        DataSet ds = new DataSet();
        da.Fill(ds, "search");
        DataGrid1.DataSource = ds.Tables["search"].DefaultView;
        DataGrid1.DataBind();

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
    }
    
} --------------------编程问答--------------------
Response.BinaryWrite((byte[])dr["MyImage"]); 
                        dr["MyImage"].ToString().Replace(TextBox1.Text,   " <font   color=red> "   +   TextBox1.Text   +   " </font> "); 

response.binarywrite都生成完了,你又替换当然没用了.
dr只是一个对象,储存在内存里,不在生成页面上.
先REPLACE再RESPONSE.
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,