有一个similar thread about this .但我想要一个具有自动宽度的多行文本框(使宽度适合较大的行)。
使用这段代码我可以有一个多行文本框(自动高度)
<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>
代码隐藏:
txt1.Rows= text.Split("|").Length ' Sets number of rows but with low performance
txt1.Text = text.Replace("|", Environment.NewLine)
再次感谢您的帮助。
最佳答案
您可以尝试 linq 方法:
string[] rows = text.Split('|');
int maxLength = rows.Max(x => x.Length);
txt1.Rows = rows.Length;
txt1.Columns = maxLength;
关于asp.net - 自动文本框宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11438617/