GridView截取超过一定宽度的字符
来源:程序员人生 发布时间:2014-01-29 17:58:37 阅读次数:3215次
方法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;
}
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠