从数据库里查询得到数据后,用GridView控件显示出来,实现在GridView控件中高亮显示,我查询时输入的字符。例如在一个textbox 里输入 “AB”GridView显示出姓名      年龄
ABCD       10
ABEF       20
ABGH       30“AB”两字的背景色变为黄色,犹如百度里的网页快照一样。

解决方案 »

  1.   

    在数据绑定的那个事件里编程实现。看看datagriew的事件,我记清不是哪个方法的具体名称了好像是databinditem什么的
      
    *****************************************************************************
    我行之我素
      

  2.   

    你说的是不是这个protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            e.Row.Attributes.Add("onmouseover","c=this.style.backgroundColor,this.style.backgroundColor='yellow',this.style.fontWeight='bold' ");
            e.Row.Attributes.Add("onmouseout","this.style.backgroundColor=c,this.style.fontWeight=''");
        }
    我要是局部数据的变色,并且在鼠标不移动到选择行上。
      

  3.   

    如果把整个单元格变色是不是要好弄点 这个很easy
      

  4.   

    比如:
    <asp:Repeater ID="MessageList" runat="server">
          <HeaderTemplate>
            <table id="MessageListTable" cellpadding="4" cellspacing="0" border="0" width="100%">
              <thead>
                <tr align="center" style="font-weight: bold;">
                  <td>选择</td>
                  <td>发信人</td>
                  <td>时间</td>
                  <td>内容</td>
                  <td>操作</td>
                </tr>
              </thead>
              <tbody>
          </HeaderTemplate>
          <ItemTemplate>
            <tr onmouseout="this.style.backgroundColor='';" onmouseover="this.style.backgroundColor='#cccccc';"
              align="center">
              <td><input type="checkbox" id='<%#Eval("id")%>' name="selected" value='<%#Eval("id")%>' /></td>
              <td id="Chatto">
                <%# ((bool)Eval("ReceiveOrSend")==false)?Messaging.MessageContext.Cuurent.Account.Name:Eval("ChatTo") %>
              </td>
              <td bordercolor="red">          //这个单元格就变红了
                <%#Eval("SendTime","{0:MM月dd日 hh:mm}")%>
              </td>
              <td>
                <%# Eval("content") %>
              </td>  
             <td><span style="cursor: hand" onmouseover="Onmouseover(this)" onmouseout="Onmouseout(this)"
                id="span<%#Eval("ID")%>" onclick="DeleteMessge(<%# Eval("ID")%>,this)">删除</span>
                <span style="cursor: hand" onmouseover="Onmouseover (this)" onmouseout="Onmouseout(this)"
                  id="<%#Eval("ChatTo")%>" onclick="Reply(this)">回复</span>
               </td>
            </tr>
          </ItemTemplate>
          <FooterTemplate>
            </tbody></table>
          </FooterTemplate>
        </asp:Repeater>
      

  5.   

    其实我个人觉得,你如果输入查询条件AB,那查询出来的数据肯定都包含了AB,并没有变色的必要了
      

  6.   

    试试吧,如果lz是用BoundField绑定的,就这样改
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            foreach(GridViewRow rows in GridView.Rows)
           {
               rows.Cell[索引].Text.Replace("AB","<font color=\"yellow\">AB</font>")
            }
        }
    其中AB可以设成变量了。
    如果不是用BoundField绑定的话就通过FindControl找吧,反正原理一样。
      

  7.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
                       e.Row.Cell[索引].Text.Replace(this.TextQuery.Text,"<font color='yellow'>"+this.txtQuery.Text+"</font>")
                 }
      

  8.   

    应该是:e.Row.Cell[索引].Text = e.Row.Cell[索引].Text.Replace(this.TextQuery.Text,"<font color='yellow'>"+this.txtQuery.Text+"</font>")
      

  9.   

    我也要改-_-!
    protected void GridView1_DataBound(object sender, EventArgs e)
        {
            foreach(GridViewRow rows in GridView.Rows)
           {
              rows.Cell[索引].Text = rows.Cell[索引].Text.Replace("AB","<font color=\"yellow\">AB</font>")
            }
        }