从数据库里查询得到数据后,用GridView控件显示出来,实现在GridView控件中高亮显示,我查询时输入的字符。例如在一个textbox 里输入 “AB”GridView显示出姓名 年龄
ABCD 10
ABEF 20
ABGH 30“AB”两字的背景色变为黄色,犹如百度里的网页快照一样。
ABCD 10
ABEF 20
ABGH 30“AB”两字的背景色变为黄色,犹如百度里的网页快照一样。
解决方案 »
- 今天面试了个公司,遇到个题
- 怎样在运行时用Page.FindControl设置Formview中的dropdownlist控件属性
- SQL数据库使用脚本创建的问题
- 大家帮我看看这个网站是用.net开发的吗,还是就是静态的html
- 一个错误,不知道是怎么回事???
- 急!!!win2000pro+.net1.1+iis5.0下,为什么创建asp.net alpplication时总是出现“http/1.0 500 internal server error"???????
- 如何用datagrid中模板列里控件的值更新绑定数据源的值?
- FCKEditor如何实现像CSDN Blog中可以插入代码的功能?
- DataGrid 小问题求解^_^~
- 急!请教asp大人,不知道是否碰到过这样的问题
- showModalDialog 獲取回傳值的問題。!!!!
- 怎么把confirm的默认焦点改为cancel???在线等!
*****************************************************************************
我行之我素
{
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=''");
}
我要是局部数据的变色,并且在鼠标不移动到选择行上。
<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>
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找吧,反正原理一样。
{
e.Row.Cell[索引].Text.Replace(this.TextQuery.Text,"<font color='yellow'>"+this.txtQuery.Text+"</font>")
}
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>")
}
}