首先在前台設置樣式
復制代碼 代碼如下:
<style type="text/css">
.listover150
{
width:150px;
text-align:left;
overflow:hidden;
text-overflow:ellipsis;//超長設置省略號
white-space:nowrap;
}
</style>
然後在後台GridView中的RowDataBind中進行設置
,附帶幾句可以改變鼠標移動的樣式設置
復制代碼 代碼如下:
//列表加載處理
protected void gv_showReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當鼠標移開時還原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#F4FBFF'");
e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#e2eaf1'");
}
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Attributes.Add("style", "background-image:url('../images/grid3-hrow.gif')");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//設置申請原因字符串顯示長度
string strDISC = e.Row.Cells[4].Text.Trim();
e.Row.Cells[4].Text = "<div class=/"listover150/">" + strDISC + "</div>";
e.Row.Cells[4].ToolTip = strDISC;//鼠標放上去顯示所有
//設置審批備注字符串截取長度
string str = e.Row.Cells[7].Text.Trim();
e.Row.Cells[7].Text = "<div class=/"listover150/">" + str + "</div>";
e.Row.Cells[7].ToolTip = str;
}
}