Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I use a Datagird with Width=850, and 4 BoundColumn, which I want them to be always in the same size.

So, for each BoundColumn, I gave ItemStyle-Width="25%".

It's working just fine, unless there is a long string in the BoundColumn,
In this case, it's not 25% anymore, the BoundColumn become as long as the value string inside.

I don't want it to act like this, I want that when the string value is long, It will be wrapped.

And the string will be divided into 2 lines (or more) and the BoundColumn will stay 25% Width.

I Googled it and found the ItemStyle-Wrap="True" attribute for the BoundColumn, but it's not working.

What should I do?

Is there any answer?
Posted
Updated 28-Nov-11 22:52pm
v2

ItemStyle-Wrap="True" generally works well, except when there is no space between characters.
wrapping is done based on words so that any single word is not broken in two lines.

so ItemStyle-Wrap="True" won't work for you if your data has long string without space.
and the problem is that you can't insert spaces on your own because that may change the meaning of data.

in my previous project we encountered this issue and used a work around
while showing in grid we show only that long string which can be accommodated in column and then add "..." (only if string is more than what is showing) and then add a tooltip to show the full string.
that way the grid formatting is not compromised and if user wants he can hover his mouse and see the whole string.

hope this helps
 
Share this answer
 
Your ItemStyle-Wrap="True" not working because to Wrap the text contents, text should contain ' '(SPACE) in it. and the SPACE in your text and check it will wrap your text.
you can use \r\n or a space for wraping.

If you don't have a SPACE in your text then it is treated as one word.
 
Share this answer
 
v2
Try using "style" attribute . style="white-space:normal;". This will break the words in the columns correctly. eg:If a sentence contains "paragraph" as a word in the column, above solution will break near "paragraph" and wrap it to next line.

Whereas : word-break:word-all etc, breaks the words and then wraps, eg. "paragraph" may be wrapped as "para" in firstline and "graph" in second line, based on the column width.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900