.net设置中GridView自适应列宽

有一个项目只有30分钟开发时间,速成,使用了古老的.net gridview. 但需要列宽自适应好看些.

于是琢磨了,实现思路如下. 

先看下大致效果(很粗暴没有优化)

 

代码如下:

    protected void GridView1_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 = "<nobr> " + e.Row.Cells[i].Text + " </nobr>";
                }
            }
        }

  

绑定事件

原文地址:https://www.cnblogs.com/benbenfishfish/p/9253678.html