首页  ·  知识 ·  
Label
      编辑:  图片来源:网络

1. 绑定方法

 公共类(C#)

 1public class Common
 2{
 3    public Common()
 4    {
 5        //
 6        // TODO: 在此处添加构造函数逻辑
 7        //
 8    }

 9
10    //根据要求返回特定长度的字符串
11    public string GetStringByLength(string Str, int Length)
12    {
13        if (Str.Length > Length)
14            return Str.Substring(0, Length);
15        else if (Str.Length > 0)
16            return Str;
17        else
18            return "";
19    }

20
21    //根据要求返回精简的文本
22    public string GetShowText(string Text,int MaxLength)
23    {
24        if (Text.Length < MaxLength)
25            return Text;
26        else
27            return GetStringByLength(Text, MaxLength - 2+ "";
28    }

29
30
31    //判断日期是否是新的
32    public bool IsNew(DateTime Date)
33    {
34        TimeSpan days = DateTime.Now.Subtract(Date);
35
36        int newDays = Int32.Parse(ConfigurationManager.AppSettings["NewDays"].ToString());
37
38        if (days.Days < newDays)
39            return true;
40        else
41            return false;
42    }


2. 使用<% %>块

公共类(C#)
 1public class Common
 2{
 3    public Common()
 4    {
 5        //
 6        // TODO: 在此处添加构造函数逻辑
 7        //
 8    }

 9    //检查Count是否为0
10    public string CheckIteams(int Count)
11    {
12        if (Count <= 0)
13            return "<span>暂无</span>";
14        else
15            return string.Empty;
16    }

17}

18

.aspx
1<%  =(new Common()).CheckIteams(gvClassNewsList.Rows.Count) %>

.aspx
 1<asp:GridView ID="gvMeiTiNews" runat="server">
 2<asp:TemplateField>
 3                <ItemStyle HorizontalAlign="Left" />
 4                <ItemTemplate>
 5                    <asp:HyperLink ID="hlnkNewsTitle" runat="server" NavigateUrl='<%# "ReadNews.aspx?NewsID=" + Eval("NewID") %>'
 6                        Text='<%# (new Common()).GetShowText(Eval("Title").ToString(),23) %>' ToolTip='<%# Eval("Title") %>'></asp:HyperLink>
 7                    <asp:Image ID="imgNew" runat="server" ImageUrl="~/theme/images/new.gif"  Visible='<%# (new Common()).IsNew(DateTime.Parse(Eval("EditDate").ToString())) %>' />
 8                    <asp:Image ID="imgHot" runat="server"  ImageUrl="~/theme/images/hot.gif" Visible='<%# (new Common()).IsHot(Int32.Parse(Eval("Clicks").ToString())) %>' />
 9                </ItemTemplate>
10            </asp:TemplateField>
11
12</asp:GridView>
本文作者:网友 来源: http://www.cnitblog.com/reddyone/
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读
也许感兴趣的
我们推荐的
主题最新
看看其它的
收藏至微信