菜鸟会用datalist控件把表里的数据显示到网页上,但我想让数据关于奥运2个字变成黄色,如何实现呢?

解决方案 »

  1.   

    你的在ItemDataBound事件里判断!!
    然后设置字体颜色!!
      

  2.   

    <ItemTemplate> 
              <asp:Label ID="Label1" runat="server" Text=' <%# Eval("field2") %>'> </asp:Label> 
    </ItemTemplate> Label lb =e.Item.FindControl("Label1") as Label; 
    lb.style="font-color:yellow;"
      

  3.   

    直接把数据库里的那个记当记录加上 <span style="color:黄颜色的代码">奥运</span> 哈哈
    或者说在页面写一个
    public string TextYellow(object str)
    {
      str=str.Replace("奥运","<span style="color:黄颜色的代码">奥运</span>")
    }然后绑定的时候<%# TextYellow(Eval("field2")) %>哈哈哈
      

  4.   

    sorry 上个方法没有写完,应该是:public string TextYellow(object str)
    {
      return str.ToString().Replace("奥运","<span style="color:黄颜色的代码">奥运</span>");
    }
      

  5.   

    既然是asp.net难道html不可用吗?
    replace("奥运","<font color='yellow'>奥运</font>")