怎麼設定GridView的單元格在內容顯示超過長度的時候用省略號代替而不是換行當滑鼠移上去的時候將影藏的內容提示出來
滑鼠移上全部顯示用ToolTip,
1.CSS:
<style type="text/css">
.mlength
{
display: block;
width: 100px;
overflow: hidden;
white-space: nowrap;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
}
</style>
2.設定GeidView某一欄位為模板列並設定css,如:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("欄位") %>' CssClass="mlength"
3.後臺設定tooltip:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((Label)e.Row.Cells[0].FindControl("Label1")).ToolTip = ((Label)e.Row.Cells[0].FindControl("Label1")).Text;
}
}