GridView截取超過一定寬度的字符
來源:程序員人生 發(fā)布時(shí)間:2014-01-29 17:58:37 閱讀次數(shù):3423次
方法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:服務(wù)器端截取字符
在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;
}
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈