日期:2014-05-18  浏览次数:20788 次

gridview 内容过多
唉~每次挠的头发都快掉光的时候就来CSDN求解+吐槽,今儿又来求助了!

gridview中有个“备注”列,是用来显示用户备注的,因为字数过多,gridview总是被串好长一串,设置了Width="850px"也没效果,每行设置宽度也没效果
在网上找的http://www.bhcode.net/article/20100623/11335.html
在css里设置了.break{word-break:break-all} 无效果

<asp:BoundField DataField="Remark" HeaderText="备注">
  <ItemStyle HorizontalAlign="Center" Width="70px" CssClass="break" />
  <HeaderStyle />
</asp:BoundField>


http://hi.baidu.com/freesky125/blog/item/b4f15e44abde9e4b510ffe95.html
我要的就是这个效果,可惜这个帖子的写法不会弄啊

http://hi.baidu.com/evans_wang/blog/item/e5769b11b8f42406213f2eb1.html
这个看着到简单易实现,可谁能告诉我(list[i].Viscera)这个是什么???

求解求解啊!!我现在又在抓头发了……5555555555555

------解决方案--------------------
把你的备注换成下面模板列

<asp:TemplateField HeaderText="备注" SortExpression="Remark">
<ItemStyle HorizontalAlign="Center" Width="200px" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# String.Format("{0}", Eval("Remark")).Length >= 20 ? String.Format("{0}", Eval

("Remark")).Substring(0, 20) + ".." : String.Format("{0}", Eval("Remark")).Substring(0) + ".."%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
------解决方案--------------------
HTML code

 <style type="text/css">
         .mlength
          {
          text-align : left;
          display: block;
           width: 150px;
          overflow: hidden;  
          white-space: nowrap;
          -o-text-overflow: ellipsis;
          text-overflow: ellipsis;
          
          }
    </style>

 <asp:TemplateField HeaderText="备注">
                               <ItemTemplate>
                                 <asp:Label ID="Label1" runat="server" Text='<%# Eval("Remark") %>' CssClass="mlength" ToolTip='<%# Eval("Remark") %>'></asp:Label>
                               </ItemTemplate>
                           </asp:TemplateField>