我想做个限制吧招商名称那一列的数据做限制最多16个字节长度,汉字2字节
<asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSourceMer6" ForeColor="#333333"
GridLines="None" Height="100%" Width="100%"
onrowdatabound="GridView5_RowDataBound"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns>
<asp:HyperLinkField DataTextField="pname" HeaderText="招商名称 "
DataNavigateUrlFields="pname"
DataNavigateUrlFormatString="ShowDetalled.aspx?proj={0}" />
<asp:BoundField DataField="Column1" HeaderText="日期" ReadOnly="True"
SortExpression="Column1" >
<ItemStyle Width="90px" />
</asp:BoundField>
</Columns></asp:GridView>protected void GridView5_RowDataBound(object sender, GridViewRowEventArgs e)
{
//for (int i = 0; i < GridView5.Rows.Count; i++)
//{
// string s = GridView5.Rows[i].Cells[0].Text;
// string t = s;
// if (s.Length >= 14)
// {
// t = s.Substring(0, 14) + "...";
// }
// this.GridView5.Rows[i].Cells[0].Text = t;
// this.GridView5.Rows[i].Cells[0].ToolTip = t;
// 写这段代码发现整个招商名称列都不显示数据了,空的
//}
if (e.Row.Cells[0].Text.Length > 16)
{
this.GridView5.Rows[0].Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 16) + "…";
//这个运行就报错 : 索引超出范围。必须为非负值并小于集合大小。参数名: index
}
}上面效果图我看了好多其他类似帖子,但是都没解决求助GridViewASP.NET
<asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False"
CellPadding="4" DataSourceID="SqlDataSourceMer6" ForeColor="#333333"
GridLines="None" Height="100%" Width="100%"
onrowdatabound="GridView5_RowDataBound"> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> <Columns>
<asp:HyperLinkField DataTextField="pname" HeaderText="招商名称 "
DataNavigateUrlFields="pname"
DataNavigateUrlFormatString="ShowDetalled.aspx?proj={0}" />
<asp:BoundField DataField="Column1" HeaderText="日期" ReadOnly="True"
SortExpression="Column1" >
<ItemStyle Width="90px" />
</asp:BoundField>
</Columns></asp:GridView>protected void GridView5_RowDataBound(object sender, GridViewRowEventArgs e)
{
//for (int i = 0; i < GridView5.Rows.Count; i++)
//{
// string s = GridView5.Rows[i].Cells[0].Text;
// string t = s;
// if (s.Length >= 14)
// {
// t = s.Substring(0, 14) + "...";
// }
// this.GridView5.Rows[i].Cells[0].Text = t;
// this.GridView5.Rows[i].Cells[0].ToolTip = t;
// 写这段代码发现整个招商名称列都不显示数据了,空的
//}
if (e.Row.Cells[0].Text.Length > 16)
{
this.GridView5.Rows[0].Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 16) + "…";
//这个运行就报错 : 索引超出范围。必须为非负值并小于集合大小。参数名: index
}
}上面效果图我看了好多其他类似帖子,但是都没解决求助GridViewASP.NET
解决方案 »
- 关于计算表达式的问题 在线等待
- 有没有办法把数据库表的内容生成sitemappath??而不是从xml文件生成
- 页面嵌套问题
- 不装IIS,如何创建ASP.NET2.0WEB站点服务器?
- 怎么获取服务器端的所有页面列表
- 在分帧(frameset)中可以控制打开帧的顺序吗?
- 求问:b/s中,如何实现一段自定义格式的动画声音播放??
- 求救:javascript中有有求两个日期之间差的函数吗? 如sql中的datadiff(month,d1,d2)
- 水晶报表问题?BC30389: “C”是“Private”,因此它在此上下文中无法访问
- 怎么在dataset中的指定位置插入新的一行记录,并显示出来?
- gridview如何返回droplistdown数据给数据库
- ReportViewer控件的使用
http://www.cnblogs.com/insus/p/3181421.html
Eval("Name").ToString().Length>16 ? Eval("Name").ToString().Substring(0,16) + "..." : Eval("Name")
你定义截取的cut方法啊,帖子里不是贴得有么!
当你的字段内包含有html代码时,取出来看看,是什么效果?