How to Prevent Word Wrap in an ASP.NET GridView

 

Recently I came across an interesting answer by Jason, where he suggests how to stop word wrap in an ASP.NET GridView. I thought of sharing this trick with the viewers facing similar issues:

The trick is to use

<td style="WORD-BREAK:BREAK-ALL;">


Check this sample:



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

<
asp:TemplateField>
<
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("SomeLongText") %>'></asp:Label>
</
div>
</
ItemTemplate>
</
asp:TemplateField>


I am sure there are many developers who had this problem in the past without a decent solution. Let me know if it worked for you!



Will you give this article a +1 ? Thanks in advance


About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

3 comments:

Venkat said...

Whether it will wrap the text or not ... I have not seen any difference , Let you give the sample code.. with the screenshot explanation.

Anonymous said...

Thanks it worked :)

Anonymous said...

Great post. It worked!