我设置的GridView中的这列宽度是 416 px ,可是如果这列的内容很长而且文字中间没有空格的话,他就不会自动换行,还是会把 416px 宽度的列给撑大??
怎么解决呢,怎么能让此列中的内容不把列撑大,到了416px长度就自动换行呢``??<asp:BoundField DataField="IO_Re" HeaderText="备注"  ItemStyle-Width="416px" />

解决方案 »

  1.   

    设置列宽
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
    //这里不知道什么意思,大概是行的状态(是不是可以编辑)
             if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)
                 || e.Row.RowState == DataControlRowState.Edit)
            {
    //定义一个文本筐
                TextBox curText;
    //有多少列,循环几次
                for (int i = 0; i < e.Row.Cells.Count; i++)
                {                if (e.Row.Cells[i].Controls.Count != 0)
                    {                    curText = e.Row.Cells[i].Controls[0] as TextBox;                    if (curText != null)
                        {                        curText.Width = Unit.Pixel(70);
                        }
                    }
                }
            }       }
      

  2.   

    应该可以啊
    要不你试试这样                                        
    <asp:BoundField DataField="processdate" HeaderText="處 理 時 間" ReadOnly="True">
       <ItemStyle Width="50px" />
      

  3.   

    e.Row.Cells[6].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word");且Wrap="True"
    http://www.cnblogs.com/cnaspnet/archive/2008/09/27/1300363.html
      

  4.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        { 
    //这里不知道什么意思,大概是行的状态(是不是可以编辑) 
            if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate) 
                || e.Row.RowState == DataControlRowState.Edit) 
            { 
    //定义一个文本筐 
                TextBox curText; 
    //有多少列,循环几次 
                for (int i = 0; i < e.Row.Cells.Count; i++) 
                {                 if (e.Row.Cells[i].Controls.Count != 0) 
                    { 
                      e.Row.Cells[6].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word"); 
                    }
                }
             }
    }
      

  5.   

    不行,比如此列中的内容是这样:"ss点点滴滴是打发士大夫是打发士大夫是打发士大夫是大方是打发士大夫是打发士大夫是大方是打发士大夫是s"
    中间没有一个空格,他就不会换行,会把单元格撑大`~!!怎么办呢??
      

  6.   

    e.Row.Cells[6].Attributes.Add("style", "word-break :break-all ; word-wrap: break-all"); 这样就可以了
      

  7.   

    最简单的办法:
    改成模板列,将Label替换成TextBox,设置TextBox的背景色,去掉边框,设置成只读,
    效果和Label一样,不会撑大了!!
      

  8.   

    //正常换行
     GridView1.Attributes.Add("style", "word-break:keep-all;word-wrap:normal");
     //自动换行
     GridView1.Attributes.Add("style", "word-break:break-all;word-wrap:break-word");
       
      

  9.   

    Itemtype的宽度设为百分比,设换行属性为True,可以不用再自己加脚本
      

  10.   

    /* CSS Document */
    body { word-wrap: break-word;
    word-break: break-all;
    }
      

  11.   

    <asp:TemplateColumn HeaderText="刪除" HeaderStyle-Width>表头的列宽就可以了HeaderStyle-Width
      

  12.   

    你也可以在rowdatabound事件中截取一段长度,然后多的用....
      

  13.   

    自动换行问题,正常字符的换行是比较合理的,而连续的数字和英文字符常常将容器撑大,挺让人头疼,下面介绍的是CSS如何实现换行的方法对于div,p等块级元素
    正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space:normal,当定义的宽度之后自动换行
    html
    <div id="wrap">正常文字的换行(亚洲文字和非亚洲文字)元素拥有默认的white-space:normal,当定义</div>
    css
    #wrap{white-space:normal; width:200px; }1.(IE浏览器)连续的英文字符和阿拉伯数字,使用word-wrap : break-word ;或者word-break:break-all;实现强制断行#wrap{word-break:break-all; width:200px;}
    或者
    #wrap{word-wrap:break-word; width:200px;}<div id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>效果:可以实现换行2.(Firefox浏览器)连续的英文字符和阿拉伯数字的断行,Firefox的所有版本的没有解决这个问题,我们只有让超出边界的字符隐藏或者,给容器添加滚动条#wrap{word-break:break-all; width:200px; overflow:auto;}<div id="wrap">abcdefghijklmnabcdefghijklmnabcdefghijklmn111111111</div>效果:容器正常,内容隐藏对于table1. (IE浏览器)使用 table-layout:fixed;强制table的宽度,多余内容隐藏<table style="table-layout:fixed" width="200">
    <tr>
    <td>abcdefghigklmnopqrstuvwxyz1234567890ssssssssssssss
    </td>
    </tr>
    </table>效果:隐藏多余内容2.(IE浏览器)使用 table-layout:fixed;强制table的宽度,内层td,th采用word-break : break-all;或者word-wrap : break-word ;换行<table width="200" style="table-layout:fixed;">
    <tr>
    <td width="25%" style="word-break : break-all; ">abcdefghigklmnopqrstuvwxyz 1234567890
    </td>
    <td style="word-wrap : break-word ;">abcdefghigklmnopqrstuvwxyz 1234567890
    </td>
    </tr>
    </table>效果:可以换行3. (IE浏览器)在td,th中嵌套div,p等采用上面提到的div,p的换行方法4.(Firefox浏览器)使用 table-layout:fixed;强制table的宽度,内层td,th采用word- break : break-all;或者word-wrap : break-word ;换行,使用overflow:hidden;隐藏超出内容,这里overflow:auto;无法起作用<table style="table-layout:fixed" width="200">
    <tr>
    <td width="25%" style="word-break : break-all; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
    <td width="75%" style="word-wrap : break-word; overflow:hidden; ">abcdefghigklmnopqrstuvwxyz1234567890</td>
    </tr>
    </table>效果:隐藏多于内容5.(Firefox浏览器) 在td,th中嵌套div,p等采用上面提到的对付Firefox的方法