How to set ellipses on a column data
I have the following BoundField
in my GridView:
text-overflow:ellipsis;
only works if the the following properties are true:
The element's width must be specified.
The element must have overflow:hidden
and white-space:nowrap
set. Change your css
like below
.hideText {
width:120px;
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
}
Here is the working Demo
Update:
Here is your complete TemplateField
definition. Define a div
within the TemplateField
and decorate with the css properties for ellipsis.
<asp:TemplateField HeaderText="Provider Name">
<ItemTemplate>
<div style="width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
<asp:Label ID="lblEllipsis" runat="server" Text='<%#Eval("Provider") %>' ToolTip='<%#Eval("Provider") %>'></asp:Label>
</div>
</ItemTemplate>
</asp:TemplateField>
Here is how it looks like when I tried this in a gridview locally.
You seem to be modifying this where you could not store it back to the database anyway so I would just handle it like this unless they need an option to then see the entirety of the data.
I did all this c# in this editor so there might be slight problems, lets call it psuedo code!
string provider = item["Provider"].ToString().Replace("#", "\n").TrimStart(';');
string[] providerListing = provider.Split(new[]{";"}, StringSplitOptions.RemoveEmptyEntries));
if(providerListing.Length > 3)
{
//Make an array of the first 3 providers
string[] firstProviders = new string[3];
Array.Copy(providerListing, firstProviders, 3);
//Reconcatenate with ; and add ellipsis
provider = String.Join(";",firstProviders)+"...";
}
If they do need to see the entirety of the data I would add another column called FullProviders or something like that to query.