如何让GridView不换行?

sapiential 2006-09-28 04:16:22
在VS2005中,如何在把每列的宽度固定下之后,让GridView不换行,即只显示部分数据。
...全文
224 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jingye721 2006-09-28
  • 打赏
  • 举报
回复
在GridView1_RowDataBound事件里面:
private void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType!=DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.Length>10)
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 10) + "";
}
}
}
yanghuijun 2006-09-28
  • 打赏
  • 举报
回复
这个需要在相应的事件中截取字符串了。
贴点代码供参考:
protected void gdvLog_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//判定当前的行是否属于datarow类型的行
{

Label lblUserAgent = (Label)e.Row.FindControl("lblUserAgent");
lblUserAgent.Text = lblUserAgent.ToolTip.Substring(0, 45);

在ASPX页面中模板列加入这个lbluserAgent控件
<ItemTemplate>
<asp:Label ID="lblUserAgent" runat="server" EnableViewState="False" ToolTip='<%# Eval("userInfo") %>'></asp:Label>
</ItemTemplate>
jc15271149 2006-09-28
  • 打赏
  • 举报
回复
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType==DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.Length>10)
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 10) + "...";
}
}
}
coley 2006-09-28
  • 打赏
  • 举报
回复
<body style=word-break:break-all>

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧