views:

197

answers:

4

I need to break this text on commas in asp:GridView:

aaaaaaaaaaa,aaaaa,aaaaaaaaaa,asdsad,aasfasfa,sfasfasfsfasfasfa,afasf.

This text is stretching field too much.

I have tried with css and with label control as field but has no result.

A: 

If you insert space between the commas it will wrap (unless your css prevents from doing so).

Or you could truncate the text and use a title to show all the text on hover:

<span title="all the text here">truncated text here</span>
pedro
.Replace(",", ", ") !
Filip Ekberg
I can insert space when user is saving text field, but I have problem with numbers like 23,67.Thanks for answer
drejKamikaza
Do you have a number so big that it's streching the column ?If you have text and numbers you could only add the space if it's not a number (using regular expressions).
pedro
I have any kind of text that user can enter. :) I'll probably use truncate with span title.
drejKamikaza
A: 

You could set the CSS overflow property to scroll so the cell does not expand but instead shows a scrollbar.

dbemerlin
A: 

If the volume of your data source was not large you can handle the PreRender event of the label and then replace the comma with an html line break tag like this:

Label lbl = sender as Label;
lbl.Text = lbl.Text.Replace(",","<br />");
SubPortal
+1  A: 

Probably try something like this

<ItemTemplate>
    <asp:Label ID="idTitle" Text='<%# GetCommaDelimited(Eval("MyField")) %>'
        runat="server"></asp:Label>
</ItemTemplate>

And in the code-behind, implement the display logic you're looking for.

IrishChieftain