How to set ellipses on a column data if it exceeds more than a set record

后端 未结 2 386
清酒与你
清酒与你 2021-01-07 08:24

How to set ellipses on a column data

I have the following BoundField in my GridView:



        
相关标签:
2条回答
  • 2021-01-07 08:39

    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.

    enter image description here

    0 讨论(0)
  • 2021-01-07 08:56

    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.

    0 讨论(0)
提交回复
热议问题