Asp.net 設定GridView自適應列寬不變形

來源:互聯網
上載者:User

標籤:style   blog   ar   color   sp   for   資料   on   div   

動態綁定的GridView由於列數不固定,而列又太多,這樣設定GridView固定寬度就不能滿足需求了。為此整理了兩種方法來達到GridView自適應列寬不變形的效果。

    //在GridView的行資料繫結完的事件中設定    protected void gvObjectList_RowDataBound(object sender, GridViewRowEventArgs e)    {        if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)        {            //保持列不變形            for (int i = 0; i < e.Row.Cells.Count; i++)            {                   //方法一:                e.Row.Cells[i].Text = "&nbsp;" + e.Row.Cells[i].Text + "&nbsp;";                e.Row.Cells[i].Wrap = false;                //方法二:                //e.Row.Cells[i].Text = "<nobr>&nbsp;" + e.Row.Cells[i].Text + "&nbsp;</nobr>";                        }                }         }

代碼說明:
方法一,設定cell的自動換行屬性為false。
方法二,用html標記的方式實現不換行; 就是一個空格,可以讓網格線和裡面的內容留有一定的距離保持美觀。

有興趣的朋友,動手下吧,看看效果如何哦。

Asp.net 設定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.