There is a similar thread about this. But I want to have a multiline TextBox with automatic width (fit width to the larger row).
With this code I can have a multiline TextBox (automatic height)
<div style="float:left; white-space:nowrap ">
<asp:TextBox style="display:inline; overflow:hidden"
ID="txt1"
runat="server"
Wrap="false"
ReadOnly="true"
TextMode="MultiLine"
BorderStyle="none"
BorderWidth="0">
</asp:TextBox>
</div>
<div style="float:left">
<asp:TextBox ID="txt2" runat="server" Text="Example textbox"></asp:TextBox>
</div>
Code behind:
txt1.Rows= text.Split("|").Length ' Sets number of rows but with low performance
txt1.Text = text.Replace("|", Environment.NewLine)
Once again, thanks for your help.
You could try a linq approach:
string[] rows = text.Split('|');
int maxLength = rows.Max(x => x.Length);
txt1.Rows = rows.Length;
txt1.Columns = maxLength;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With