views:

770

answers:

3
+1  Q: 

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?

+1  A: 

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>
Robert Harvey
A: 

Just set nowrap in a css class, and apply that class to span tag, and put your lable inside that span tag,

span class="yourclassname" your asp lable tag /span

Ali
A: 

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.

Joel Etherton