在ASP.net页面的文本区域中剪切文本

时间:2015-01-02 18:14:50

标签: c# html asp.net

我正在尝试将数据库中的文本加载到许多文本字段中 一切都好,但是文本长度的一个字段超过了文本字段的长度 所以并非所有文字都出现在屏幕上 那是我的ASP.net代码

<asp:TextBox ID="descriptiont" runat="server" Rows="3" Width="300px" Height="100px" Wrap="true">

这就是它背后的代码

descriptiont.Text = s.GetValue(1).ToString();
descriptiont.Enabled = false;

这就是我在网页上得到的内容 text field not appear well

原始文本是“ECASTI(埃及科学,技术和创新促进中心)”

任何人都可以帮忙吗?? !!!

5 个答案:

答案 0 :(得分:12)

使用它:

<asp:TextBox id="TextArea1" TextMode="multiline" Columns="50" Rows="5" runat="server" />

然后您可以通过以下方式访问内容:

string message= TextArea1.Text;

答案 1 :(得分:6)

不要修复文本框的高度。高度应为auto.And in css add text for textbox。它会起作用。

    word-wrap: break-word;

答案 2 :(得分:2)

试试这个:

string s = "Your Text Field";
        if (s.Length > 20)
        {
            //Change Width="450px"
        }

更新:

当文本长度大于字段长度时,您可以在CSS中更改宽度。

更新2:

您可以使用以下代码在C#中调整文本框的大小:

        if (s.Length>20)
        {
            textBox1.TextChanged += textBox1_TextChanged;
        }

    void textBox1_TextChanged(object sender, EventArgs e)
    {
        Size size = TextRenderer.MeasureText(textBox1.Text, textBox1.Font);
        textBox1.Width = size.Width;
    }

答案 3 :(得分:0)

如果不改变文本框的长度,可能会弄乱您的设计,添加具有相同内容的文本框工具提示。因此,当您将鼠标悬停在文本框上时,它将显示完整内容。

descriptiont.Text = s.GetValue(1).ToString();
descriptiont.Title = s.GetValue(1).ToString();
descriptiont.Enabled = false;

答案 4 :(得分:0)

有一个名为“TextMode”的文本框的属性。请添加'TextMode =“multiline”' 在您的视图中,您也可以从代码隐藏文件中添加它。