Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gridview wordwrap

I've tried changing the RowStyle Wrap property and every Wrap property in the grid. How do I stop word wrap in a Gridview no matter what size the Row's Text Length is?

like image 211
Eric Avatar asked May 26 '09 20:05

Eric


2 Answers

It's not RowStyle. You need to set the wrap setting of the individual Item under the columns.

<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:BoundField>
        <ItemStyle Wrap="False" />
        </asp:BoundField>
        <asp:BoundField>
        <ItemStyle Wrap="False" />
        </asp:BoundField>
    </Columns>
</asp:GridView>

This needs to be done for each individual column. You could set up a method in the code-behind to do it for you though.

like image 171
Joel Etherton Avatar answered Nov 01 '22 12:11

Joel Etherton


Jason writes in this blog post:

I was facing the same problems with the Gridview when loading long text from the database. I tried the DIV method to get with CSS styling to stop the table from expanding all the way to the right. I got it to work now with elipsis showing if the text is too long. However, this means that I can't display the whole text in the gridview which can me misleading to users.

So I added another style called "word-break : break-all" to break the text into chunks that fit properly in the table and got the results I wanted. Below is the parts to my code:

<style type="text/css">
    .DisplayDesc { width:500px; word-break: break-all; }
    .DisplayDiv  { width:500px; OVERFLOW:hidden; TEXT-OVERFLOW:ellipsis;}
</style> 

<asp:TemplateField HeaderText="Log Description">
    <ItemStyle Font-Names="Tahoma" Font-Size="X-Small" 
               HorizontalAlign="Left" Wrap="True" />
    <ItemTemplate>
        <div class="DisplayDiv">
            <asp:Label CssClass="DisplayDesc" ID="Label1" runat="server" 
                       Text='<%# Bind("TransText") %>'></asp:Label>
        </div>
    </ItemTemplate>
</asp:TemplateField>
like image 20
Robert Harvey Avatar answered Nov 01 '22 11:11

Robert Harvey