我的 GridView 的宽度是 100% ,可是就有问题了,其中的一列中的内容是很长的,就导致整个 GridView 拉的很长(很难看)。那么我如何能设置此列:让此列每多少个字符就自动换行呢~~??

解决方案 »

  1.   

    不用,设置一下列的宽度,给需要换行的列加上这个样式:style="word-wrap:break-word;word-break:break-all;"即可
      

  2.   

    在你的gridview 的 rowdatabound 中加入
    e.Row.Cells[2].Style.Add("word-break", "break-all");
            e.Row.Cells[2].Width = 1024;e.Row.Cells[2] 是第三列 
    这就是给第三列加css e.Row.Cells[2].Width = 1024; 是说 宽度超过1024px 就换行 
    根据需要改下就好
      

  3.   


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
          e.Row.Cells[0].Wrap = true;//0可以改写别的列,换行启动
       }
    }
      

  4.   

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow) 
            {
                //e.Row.Cells[0].Wrap = true; or
                e.Row.Cells[0].Attributes.Add("word-break", "break-all") ;        }
        }
      

  5.   

    各位在后台设置的方法我也试用了,怎么不好使牙~~
     protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
        {
          
            if (e.Row.RowType == DataControlRowType.DataRow) 
            { 
                e.Row.Cells[0].Wrap = true;
                e.Row.Cells[3].Attributes.Add("word-break", "break-all") ;
                e.Row.Cells[3].Width = 10;
                e.Row.Cells[4].Attributes.Add("word-break", "break-all");
                e.Row.Cells[4].Width = 10;
            } 
        }
      

  6.   

    给具体行由后面加个class, 通过css控制.
      

  7.   

    GV的行宽是可以设置的,有个ControlStyle-Width属性设置下就可以了