關(guān)于中g(shù)ridview 字符串截取的方法
更新時間:2013年06月22日 10:28:57 作者:
在Gridview中,如果你的某一列字符串的長度過長,不做處理的話.那么將顯示的奇丑無比,可以采取設(shè)置樣式,將其顯示為定長,可以在點擊查看的時候,在另一個頁面對其進(jìn)行顯示
首先在前臺設(shè)置樣式
復(fù)制代碼 代碼如下:
<style type="text/css">
.listover150
{
width:150px;
text-align:left;
overflow:hidden;
text-overflow:ellipsis;//超長設(shè)置省略號
white-space:nowrap;
}
</style>
然后在后臺GridView中的RowDataBind中進(jìn)行設(shè)置
,附帶幾句可以改變鼠標(biāo)移動的樣式設(shè)置
復(fù)制代碼 代碼如下:
//列表加載處理
protected void gv_showReport_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//當(dāng)鼠標(biāo)移開時還原背景色
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è)置申請原因字符串顯示長度
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è)置審批備注字符串截取長度
string str = e.Row.Cells[7].Text.Trim();
e.Row.Cells[7].Text = "<div class=/"listover150/">" + str + "</div>";
e.Row.Cells[7].ToolTip = str;
}
}
相關(guān)文章
iis中為每個應(yīng)用程序池單獨設(shè)置aspnet.config配置文件
ASP.NET2.0之后的版本就在各Framework的根目錄下提供了一個aspnet.config文件,這個文件用來配置全局的一些信息,但是一直以來我們都沒有怎么用過2011-12-12
C# 中使用iTextSharp組件創(chuàng)建PDF的簡單方法
C# 中使用iTextSharp組件創(chuàng)建PDF的簡單方法,需要的朋友可以參考一下2013-03-03
DataTable數(shù)據(jù)導(dǎo)出成Excel文件的小例子
DataTable數(shù)據(jù)導(dǎo)出成Excel文件的小例子,需要的朋友可以參考一下2013-04-04
Entity?Framework使用DataBase?First模式實現(xiàn)數(shù)據(jù)庫的增刪改查
本文詳細(xì)講解了Entity?Framework使用DataBase?First模式實現(xiàn)數(shù)據(jù)庫的增刪改查,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-03-03

