Tutorial :force breaking a string in a fixed width Gridview cell


I have a Gridview control on an ASP.Net page with fixed width cells. The data coming from the database occasionally comes over as a contiguous string of characters. When there are dashes in the string, it will break so as not to upset the width of the layout. If there are no dashes (specifically, I'm dealing with underscores), the string will not break and forces the cell to widen out, thus upsetting the layout of the page. Is there a way to tell the cell to keep its width and break the string? As it stands, I don't have access to the field's data directly, as the GridView bind its datasource to a dataset object coming from the database. Thanks for any feedback.


If you handle the RowDataBound event you'll be able to break the string "manually". Otherwise it'll only break based on "HTML rules".


First thing to note is that this doesn't have a lot to do with ASP.NET but is rather a pure HTML (and CSS) problem.

A possible solution is to use the css attribute table-layout: fixed and set some fixed width values to all columns. The disadvantage of this approach is that the total table width is fixed so it doesn't scale with the window size.

Another possible approach is to display in columns shorter strings using a utility function that cuts the long strings to a maximum length.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »