首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

Repeater绑定数据中关键字高亮有关问题!

2012-12-15 
Repeater绑定数据中关键字高亮问题!!!!!!!!!!从网上搜了一段高亮代码 想绑定Repeater的时候让绑定中的内容

Repeater绑定数据中关键字高亮问题!!!!!!!!!!
从网上搜了一段高亮代码 想绑定Repeater的时候让绑定中的内容变色 高手指点指点把。。
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Label lab = (Label)e.Item.FindControl("Label1");
        string a = lab.Text;
        Highlightkeywords(a);
    }
        /// 替换关键字为红色
        /// </summary>
        /// <param name="keycontent">原始内容</param>
        /// <param name="k">关键字,支持多关键字</param>
        /// <returns>String</returns>
        /// <author>haver Guo</author>
    public static string Highlightkeywords(string keycontent)
    {
        string resultstr = keycontent;
        string k = "公司";
        if (k.Trim().IndexOf(' ') > 0)
        {
            string[] myArray = k.Split(' ');
            for (int i = 0; i < myArray.Length; i++)
            {
                resultstr = resultstr.Replace(myArray[i].ToString(), "<font color=#FF0000>" + myArray[i].ToString() + "</font>");
            }
            return resultstr;
        }
        else
        {
            return resultstr.Replace(k, "<font color=#FF0000>" + k + "</font>");
        }
    }
[最优解释]
绑定的时候一个字段一个字加高亮:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
    ((Label)e.Item.FindControl("Label1")).Text=Highlightkeywords(((Label)e.Item.FindControl("Label1")).Text);//字段1
    ((Label)e.Item.FindControl("Label2")).Text=Highlightkeywords(((Label)e.Item.FindControl("Label2")).Text);//字段2
    .............
  }

public static string Highlightkeywords(string keycontent)
{
    string k = "公司";
    string resultstr = keycontent.Replace(k, "<font color=#FF0000>" + k + "</font>");
    return resultstr;
}
}
[其他解释]
用js就可以实现的。
------其他解决方案--------------------


求高手指点指点

[其他解释]
恩,不需要后台弄 用JS就实现了

function HighlightKey(key)
{

$(".searchlist").each(function(){
$(this).html($(this).html().replace(key,"<font color='#FF0000'>"+key+"</font>"));

})
}
[其他解释]
这个KEY 就是关键字?
我想把Repeater绑定的数据中的符合关键字的 加高亮 怎么实现
[其他解释]
谢谢楼上大哥了。~。~
分给你拉

[其他解释]

引用:
恩,不需要后台弄 用JS就实现了

function HighlightKey(key)
{

$(".searchlist").each(function(){
$(this).html($(this).html().replace(key,"<font color='#FF0000'>"+key+"</font>"));

})
}
        ……



请问这个如何调用这个函数,如何使用?

热点排行