日期:2014-05-18 浏览次数:20924 次
如果显示的文字过多,可用省略号…代替展示 方法一:<asp:TemplateField HeaderText="备注?" ItemStyle-HorizontalAlign="Left"> <ItemTemplate> <%#Eval("ipadRemark").ToString().Length > 3 ? Eval("ipadRemark").ToString().Substring(0, 3) + "..." : Eval("ipadRemark")%> </ItemTemplate> </asp:TemplateField>
------解决方案--------------------
看不到你的图片
若是在输入的时候可以用jquery去实习
若是在输出的时候 就用截取
/// <summary> /// 截取字符串函数 /// </summary> /// <param name="value">所要截取的字符串</param> /// <param name="cutLength">截取字符串的长度(中文字符长度2)</param> /// <param name="ellipsis">是否添加省略号</param> /// <param name="cleanFormat">是否清除格式</param> /// <returns>返回截取指定长度字符串后的字符串</returns> public static string CutString(string value, int cutLength, Boolean ellipsis, Boolean cleanFormat) { string m_sOutString = string.Empty; int m_iN = 0; if (value == null || value.Trim() == "") { return ""; } foreach (char m_cChar in cleanFormat ? Regex.Replace(value, "<[^>]+>", "").ToString() : value) { m_iN += System.Text.Encoding.Default.GetByteCount(m_cChar.ToString()); if (m_iN > cutLength) { break; } else { m_sOutString += m_cChar; } } if (ellipsis == true) { if (Encoding.Default.GetByteCount(value) > cutLength) { m_sOutString += "..."; } } return m_sOutString; }
------解决方案--------------------
看不到图,你试下是不是这种效果(渐变位置自己调)
public partial class Form1 : Form { public Form1() { InitializeComponent(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); string text = "今天的天气真好啊今天的天气真好啊今天的天气真好啊今天的天气真好啊今天的天气真好啊"; SizeF size = e.Graphics.MeasureString(text,this.Font); RectangleF displayRect = new RectangleF(50, 50, 300, size.Height); float split = Math.Min(displayRect.Width / size.Width, 1); using (var brush = new LinearGradientBrush(displayRect, Color.Red, Color.Transparent, LinearGradientMode.Horizontal)) { ColorBlend blend = new ColorBlend(); blend.Colors = new Color[] { Color.Red, Color.Red, Color.Transparent, Color.Transparent }; blend.Positions = new float[] { 0, split-0.1f, split+0.1f, 1}; brush.InterpolationColors = blend; e.Graphics.DrawString(text, this.Font, brush, displayRect); } } }