1.字段过长截取字符串
1.1 截取字符串类
可以直接substring也可以<%# Utility.Common.GetShow( Eval("NewTitle").ToString(),20,true) %> <%#fcwms.Common.GetContent.GetShow(Eval("com_address").ToString(), 19, true)%> ////// 按字节数截取字符串,中文算两个字节,全角字符算两个字节,大写字母也算两个字节 /// /// 要处理的字符串 /// 要保留的字节数 /// 设置截取后加不加省略号( "... ")默认的传true ///public static string GetStrByByteCount(string strSrc, int count, bool withPoint) { Regex regex = new Regex("[\u4e00-\u9fa5]+", RegexOptions.Compiled); char[] stringChar = strSrc.ToCharArray(); StringBuilder sb = new StringBuilder(); int nLength = 0; bool isCut = false; for (int i = 0; i < stringChar.Length; i++) { if ((regex.IsMatch((stringChar[i]).ToString())) || (stringChar[i] > 65280 && stringChar[i] < 65375) || (stringChar[i] > 64 && stringChar[i] < 91)) { nLength += 2; if (nLength > count) { isCut = true; break; } sb.Append(stringChar[i]); } else { nLength = nLength + 1; if (nLength > count) { isCut = true; break; } sb.Append(stringChar[i]); } } if (isCut) { if (withPoint) { return sb.ToString() + "..."; } else { return sb.ToString(); } } else { return sb.ToString(); } }
1.2 示例
无提示:
<td><%#fcwms.Common.GetContent.GetShow(Eval("com_address").ToString(),19,true)%></td>
2.时间格式化
<%# Convert.ToDateTime(Eval("time")).ToString("yyyy-MM-dd HH:mm")%> <%#string.Format("{0:yyyy-MM-dd HH:mm}", Eval("time"))%> <%#string.Format("{0:g}",Eval("add_time"))%> 2018/4/2 15:03
3.合并单元格
<td runat="server" id="tdName"><%#Eval("td_name")%></td>
rptList.DataSource = pds; rptList.DataBind(); //合并方法放到数据邦定之后 for (int i = rptList.Items.Count - 1; i > 0; i--) { HtmlTableCell oCell_Previous = rptList.Items[i - 1].FindControl("tdName") as HtmlTableCell; HtmlTableCell oCell = rptList.Items[i].FindControl("tdName") as HtmlTableCell; oCell.RowSpan = (oCell.RowSpan == -1) ? 1 : oCell.RowSpan; oCell_Previous.RowSpan = (oCell_Previous.RowSpan == -1) ? 1 : oCell_Previous.RowSpan; if (oCell.InnerText == oCell_Previous.InnerText) { oCell.Visible = false; oCell_Previous.RowSpan += oCell.RowSpan; } }