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, ASP.NET Architecture MVP (Microsoft Most Valuable Professional) works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He is the Editor of a Developer Magazine called DNC Magazine. He has also written two EBooks 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!