Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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>

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 />");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top