如果DataGrid显示记录值时,怎么控制长度? 有些记录值比较长,那么DataGrid就会换行显示,如果选择不换行,那么就会延长显示。那么怎么控制显示内容的长度? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 截取长度,超过某个长度,则不显示:if(e.Item.Cells[3].Text.Trim().Length>12) { e.Item.Cells[3].Text = e.Item.Cells[3].Text.Substring(0,12); } e.Item.Cells[3]是第三个字段下的值的意思吗? 在数据绑定事件(dgData1_ItemDataBound)里加if (e.Item.ItemIndex!=-1){ if (e.Item.Cells[3].Text.Trim().Length>10) { e.Item.Cells[3].Text =e.Item.Cells[3].Text.Substring(0,10);; } } 备注:10为你要截取的长度 3为你要限定长度的字段 可以在前台帮定字段里加属性(DataFormatString):<asp:BoundColumn DataField="CurrencyValue" HeaderText="Price"DataFormatString="{0:c}"> to xiaolicong(深林小径) 我照着做了。如果我Substring(0,20);的话程序就提示"索引和长度必须引用该字符串内的位置。参数名: length "那么如果我设为小于20的话,那么运行时就没有效果! 先判断一下Length > 20然后再Substring(0,20) VS2008 菜单栏 生成选项下面的 配置管理器找不到了 急!!急!!急删除数据库! dropdownlist绑定数据后的“初始化”问题 ISAPI_Rewrite 配置无效,帮我看看。谢谢。顶着有分~ 一个远程服务器图片,如果转换成image对象 如何动态生成模板列的宽度 求一条sql语句,谢谢 中文文件名下载保存时乱码问题,高手请进。 找不到类型或命名空间名称? linq查询语句的问题 上传文件的问题 谁用.net2005建过web站点,请问bin文件夹和DLL文件为何没有了?
if(e.Item.Cells[3].Text.Trim().Length>12)
{
e.Item.Cells[3].Text = e.Item.Cells[3].Text.Substring(0,12);
}
{
if (e.Item.Cells[3].Text.Trim().Length>10)
{
e.Item.Cells[3].Text =e.Item.Cells[3].Text.Substring(0,10);;
}
}
备注:10为你要截取的长度
3为你要限定长度的字段
<asp:BoundColumn DataField="CurrencyValue" HeaderText="Price"DataFormatString="{0:c}">
然后再Substring(0,20)