GridView中強制很長的資料換行

來源:互聯網
上載者:User

GridView中強制很長的資料換行

 

首先設定<asp:BoundField DataField="家庭住址" HeaderText="家庭住址" ItemStyle-Width="100" />
gridview裡有一資料行繫結的資料很長,顯示的時候在一行裡面顯示,頁面拉得很寬。
原因是連續英文段為一個整體導致的,

在RowDataBound中添加上了一句e.Row.Cells[2].Style.Add("word-break", "break-all")就可以。

 

如果要給所有的列增加此屬性:
protected void Page_Load(object sender, EventArgs e)
{
//正常換行
GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
//下面這行是自動換行
GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
if (!IsPostBack)
{
bind();//調用資料繫結即可
}
}

 

當然了也可以在GridView的CSS類裡,添加此樣式。

如:

.gv
{
 border:solid 1px #C3D6EC;
 word-break:break-all;
 word-wrap:break-word;
}

總之:善用CSS的word-break:break-all;word-wrap:break-word屬性即可,這個屬性是通用的對於頑固的南換行問題都可以解決,不局限於GridView。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.