locked
size label RRS feed

  • Question

  • User-1501966095 posted

    using VS2010, aspnet4, c#

    how to, maximum size label

    Sunday, June 2, 2013 1:22 PM

Answers

  • User-825980306 posted

    If your label text is large, show only starting of the text using substring.And show the full text as
    tooltip. Here I m displaying 1st 5 letteres.

    lblName.Text = NameString.Substring(0, 5)+"...";
    lblName.ToolTip = NameString;

    OR you can write

    <asp:Label ID="lblName" runat="server" ToolTip='<%#(Eval("NameString"))%>' Text='<%#(((Eval("NameString") != null) ?  ((Eval("NameString").ToString().Length >5) ? Eval("NameString").ToString().Substring(0,5) + "..." : Eval("NameString")) : ""))%>'></asp:Label>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2013 1:13 AM
  • User1508394307 posted

    You can use CSS

    <div style="text-overflow: ellipsis; overflow: hidden; width: 50px; overflow-y: hidden; height:37px">
    <asp:Label Width="100px" Text="A long sample text and the layout is fixed" ID="Label2" runat="server" ></asp:Label>
    </div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2013 3:35 AM

All replies

  • User1508394307 posted

    Do not set size at all, it will be resized automatically.

    Sunday, June 2, 2013 2:16 PM
  • User-1501966095 posted

    my screen space is only 50px. If the text is longer than that, show only 50 px.

    EX: <asp:Label ID="lblName" runat="server" size="50px"></asp:Label>

    How to limit the size of the label?

    Sunday, June 2, 2013 5:45 PM
  • User-825980306 posted

    If your label text is large, show only starting of the text using substring.And show the full text as
    tooltip. Here I m displaying 1st 5 letteres.

    lblName.Text = NameString.Substring(0, 5)+"...";
    lblName.ToolTip = NameString;

    OR you can write

    <asp:Label ID="lblName" runat="server" ToolTip='<%#(Eval("NameString"))%>' Text='<%#(((Eval("NameString") != null) ?  ((Eval("NameString").ToString().Length >5) ? Eval("NameString").ToString().Substring(0,5) + "..." : Eval("NameString")) : ""))%>'></asp:Label>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2013 1:13 AM
  • User1508394307 posted

    You can use CSS

    <div style="text-overflow: ellipsis; overflow: hidden; width: 50px; overflow-y: hidden; height:37px">
    <asp:Label Width="100px" Text="A long sample text and the layout is fixed" ID="Label2" runat="server" ></asp:Label>
    </div>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2013 3:35 AM