做了个基于数据库内容的查询,通过datagrid显示查询结果,现在如何在查询结果中把查询的关键字用颜色标记出来啊?

解决方案 »

  1.   

    这个你要在datagrid的itemdatabound事件里面写代码
    if(e.item.itemindex >=0)
    {
       for(i =0;i<列数;i++)
       {
         if (e.item.cells[i].text.indexof("关键字")>-1)
    {
        e.item.cells[i].backcolor = Color.red;
    }
    }
    }
      

  2.   

    ItemDataBound事件:
      for(i =0;i<e.Item.Cells.Count;i++)
       {
         e.Item.Cells[i].Text=e.Item.Cells[i].Text.Replace("关健字","<span color='red'>关健字</span>");
      

  3.   

    同意 aspdotnet2005(天中之子、为中原喝采![我想找兼职MSN:Red-Maple@hot)
      

  4.   

    ItemDataBound事件:
      for(i =0;i<e.Item.Cells.Count;i++)
       {
         e.Item.Cells[i].Text=e.Item.Cells[i].Text.Replace("关健字","<span color='red'>关健字</span>");同意 aspdotnet2005---------------设置“关键字”高亮,关键字可以从数据库中读取