首先在前臺(tái)設(shè)置樣式
復(fù)制代碼 代碼如下:
style type="text/css">
.listover150
{
width:150px;
text-align:left;
overflow:hidden;
text-overflow:ellipsis;//超長(zhǎng)設(shè)置省略號(hào)
white-space:nowrap;
}
/style>
然后在后臺(tái)GridView中的RowDataBind中進(jìn)行設(shè)置
,附帶幾句可以改變鼠標(biāo)移動(dòng)的樣式設(shè)置
復(fù)制代碼 代碼如下:
//列表加載處理
protected void gv_showReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當(dāng)鼠標(biāo)移開(kāi)時(shí)還原背景色
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)
{
//設(shè)置申請(qǐng)?jiān)蜃址@示長(zhǎng)度
string strDISC = e.Row.Cells[4].Text.Trim();
e.Row.Cells[4].Text = "div class=/"listover150/">" + strDISC + "/div>";
e.Row.Cells[4].ToolTip = strDISC;//鼠標(biāo)放上去顯示所有
//設(shè)置審批備注字符串截取長(zhǎng)度
string str = e.Row.Cells[7].Text.Trim();
e.Row.Cells[7].Text = "div class=/"listover150/">" + str + "/div>";
e.Row.Cells[7].ToolTip = str;
}
}