今天就跟大家聊聊有關使用gridview怎么對字符串進行截取,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
首先在前臺設置樣式
復制代碼 代碼如下:
<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;
}
}
看完上述內容,你們對使用gridview怎么對字符串進行截取有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。