![](https://images.cnblogs.com/cnblogs_com/fishren/%E6%88%AA%E5%9B%BE.jpg)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ASPxGridviewTest.Business;
using System.Drawing;
namespace ASPxGridviewTest
{
public partial class test : System.Web.UI.Page
{
TeaInfoDataContextDataContext dataContext = new TeaInfoDataContextDataContext();
protected void Page_Load(object sender, EventArgs e)
{
databind();
}
protected void ASPxGridView1_CustomColumnDisplayText(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDisplayTextEventArgs e)
{
if (e.Column.FieldName == "CardSubject")
{
//判断字符长度,添加省略号,当然能也可以用e.Value .ToString ().Length 来对所有的列项判断
string s = ASPxGridView1.GetRowValues(e.VisibleRowIndex, "CardSubject").ToString();
if (s.Length > 20)
{
e.DisplayText = SubStr(s, 20);
s = SubStr(s, 20);//s作为传值
}
//添加new字样
System.DateTime data1 = (System.DateTime)(ASPxGridView1.GetRowValues(e.VisibleRowIndex, "CreateTime"));
System.DateTime data2 = System.DateTime.Now;
System.TimeSpan diff = data2.Subtract(data1);
int i = diff.Days;
if (i > 0 && i < 7)
e.DisplayText = TimeFormate(s);
}
}
private string SubStr(string sString, int nLeng)
{
if (sString.Length <= nLeng)
{
return sString;
}
string sNewStr = sString.Substring(0, nLeng);
sNewStr =sNewStr + "
![](https://www.cnblogs.com/Images/dot.gif)
return sNewStr;
}
private string TimeFormate(string s)
{
s = s + "<font color=red>" + "new" + "</font>";
return s;
}
protected void ASPxGridView1_Init(object sender, EventArgs e)
{
databind();
}
private void databind()
{
this.ASPxGridView1.DataSource = dataContext.CardInfo.ToList();
this.ASPxGridView1.DataBind();
}
protected void ASPxGridView1_HtmlRowPrepared(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
{
if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
//换行变色
if (e.VisibleIndex % 2 == 0)
e.Row.BackColor = ColorTranslator.FromWin32(16508626);
}
}
}