在gridview中制作一个彩色的字符串 [英] making a string colored in gridview

查看:49
本文介绍了在gridview中制作一个彩色的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在页面中有以下代码的gridview:
网格显示数据,如下例:

2010年12月17日苹果发送
12/18/2022葡萄发送

我的模板代码是:

Hi,

I have a gridview in page with following code:
Grid present data as following example:

12/17/2010 apple send
12/18/2022 grape send

my template code is:

<asp:TemplateField headertext="">
                            <ItemTemplate>
                                 <%# Eval("date","{0:MMMM d, yyyy}") %>
                                <asp:HyperLink ID="HyperLink1"
                                               runat="server"
                                               <%Eval("productname") %>''
<%Eval("whathappenedtoproduct") %>




我的问题是:
-如何在网格中呈现苹果"字符串红色(在代码端,我查询sql并将数据获取到数据集,并且仅设置为gridviews数据源以在asp页中显示数据.)

在我处理了产品列并检查行中的项目数组后,在代码站点(c#)中,我获得了苹果"字符串.但是,不确定stringview事件或如何处理已处理的字符串,以告知stringview如果string为"apple"时将其变为红色.

任何想法都很好.

亲切的问候,




My question is:
- how can i present "apple" string red colour in grid (at code side i query sql and get the data to dataset and only setting to gridviews datasource to present data in asp page.)

At code site (c#) after i handle the products column and check the item array in row, i obtain "apple" string. However, not sure about gridview events or what to do with handled string to tell to gridview to make it red if string is "apple".

Any idea would be good.

Kind Regards,

推荐答案

安德鲁斯,

基本上,您可以为每个项目调用一个函数来决定什么
css类您将使用的项目.在CSS中,定义文本的前景色

所以aspx应该看起来像这样:

Hi Andrews,

basically you could call a function for each item to decide what
css class that item you would use. In the css you define the foreground color of the text

so the aspx should look something like this:

<asp:hyperlink id="Hyperlink1" runat="server" class="<%# FunctionName(DataBinder.Eval(Container.DataItem, " productname=")) %>" xmlns:asp="#unknown">
<![CDATA[<%Eval("productname") %>]]>''</asp:hyperlink>




并且在后面的代码中,您应该有一个函数,该函数将字符串作为参数并返回一个字符串,returnvalue是要使用的css类的名称.

希望这对您有所帮助.

干杯:cool:




And in your code behind you should have a function that takes a string as argument and returns a string, the returnvalue being the name of the css class to use.

I hope this helps you along.

cheers :cool:


在ASPX中,
In ASPX,
<asp:hyperlink id="Hyperlink1" runat="server"><%# GetProductNameWithStyle(Eval("productname"))%></asp:hyperlink>



在后面的代码中,



In Code Behind,

protected string GetProductNameWithStyle(string productname)
{
     if (productname.ToLower() == "apple")
          return "<font color='red'>" + productname + "</font>";
     return productname;
}


这篇关于在gridview中制作一个彩色的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆