drejKamikaza
drejKamikaza

Reputation: 96

Break large text at comma in GridView

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.

Upvotes: 0

Views: 1899

Answers (4)

IrishChieftain
IrishChieftain

Reputation: 15253

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.

Upvotes: 1

Mostafa Elmoghazi
Mostafa Elmoghazi

Reputation: 2154

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 />");

Upvotes: 0

pedro
pedro

Reputation: 411

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>

Upvotes: 0

user253984
user253984

Reputation:

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

Upvotes: 0

Related Questions