加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > 正文

GridView截取超过一定宽度的字符

发布时间:2018-09-03 19:04:30 所属栏目:创业 来源:站长网
导读:方法1:css处理: a { width: 80px; overflow: hidden; /*注意不要写在最后了*/ white-space: nowrap; -o-text-overflow: ellipsis; text-overflow: ellipsis; } a:hover { text-decoration: none; color: #000; } a href=# style=display:block; ;text-dec
方法1:css处理:

a
{
width: 80px;
overflow: hidden; /*注意不要写在最后了*/
white-space: nowrap;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
}
a:hover
{
text-decoration: none;
color: #000;
}

<a href="#" style="display:block; ;text-decoration: none; color: #000;" title='<%#Eval("GlobalCode")%>'><%#Eval("GlobalCode")%></a>

方法2:服务器端截取字符

在GridViewTicket_RowDataBound等事件中:

string hotelAddress = dtHotel.Rows[row.RowIndex]["hotel_address"].ToString().Trim();
if (hotelAddress.Length > 9)
{
((Label)row.FindControl("LabelHotelAddress")).Text = hotelAddress.Substring(0, 8) + "...";
((Label)row.FindControl("LabelHotelAddress")).ToolTip = hotelAddress;

}
else
{
((Label)row.FindControl("LabelHotelAddress")).Text = hotelAddress;
((Label)row.FindControl("LabelHotelAddress")).ToolTip = hotelAddress;
}

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读