asp.net - 自动文本框宽度

标签 asp.net .net html

有一个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/

相关文章:

asp.net - 在 asp.net 中使用数据列表控件显示来自 SQL Server 数据库的客户

c# - 等效于 Dispatcher.Invoke 或 Dispatcher.RunAsync 的可移植类库

html - Firebase Cloud Firestore 无法加载数据

HTML 图片和标题对齐问题

C# IList更新问题

c# - 如何将文件路径从我的代码中取出并放入 mysql 的插入语句中?

asp.net - 外部 css 中的哪些选择器名称?

c# - ConcurrentDictionary 乐观并发 Remove 方法

c# - Tuple.Create 返回类型

html - 如何使用 CSS 3 制作闪烁/闪烁的文本