Multiline label in asp.net

后端 未结 5 1946
感动是毒
感动是毒 2021-01-17 14:09

I want to use a multiline label but as the control is browser dependent, even on setting the height, width and wrap properties of the label control I am unable to display mu

相关标签:
5条回答
  • 2021-01-17 14:17

    You can concatenate the string in asp:label with "<br/>" because it will result in html.

    For Example:

    label1.Text = strSample1 & "<br/>" & strSample2 
    

    If you don't specific the width of label, it will auto expand the width to fit your string.

    0 讨论(0)
  • 2021-01-17 14:25

    You can solve it with "maximunsize" and "autosize" label properties and your problem is solved:

    <asp:Label runat="server" style="width:300px;" maximunsize="300px" autosize="true">
    
    0 讨论(0)
  • 2021-01-17 14:27

    Labels are single line by default.

    But if you want to display multiple lines in a text box, then there is one option that might work. I could not get autowrap to work, but if you want specific line breaks to occur, then

    label.text = string1 + "<br/>" + string2 + "<br/>" + string3;
    

    It may seem simple, but the C# Environment.Newline did not work in aspx. Only rendering the <br/> worked for me.

    0 讨论(0)
  • 2021-01-17 14:37
    width ="...px"  style="word-wrap:normal; "
    

    If you want to break last word if it exceeds width then style="word-wrap:break-word; " You can use max-width:...px; on style tag for being sure word wrapping if you change width programmaticaly.

    0 讨论(0)
  • 2021-01-17 14:39

    If you mean asp:Label then it resolves to a span element in HTML output. It is neither single-line or multiline.

    Define some fixed width for this element and the text will wrap into several lines when it's long enough.

    <asp:Label runat="server" style="width:300px;">
    
    0 讨论(0)
提交回复
热议问题