如何在WebForms中包装标签

时间:2014-11-14 20:26:19

标签: c# asp.net webforms

我的Webform中有一个标签。我想包装它的文本,以便在特定宽度(以像素为单位)后自动换行。

标签的文本来自数据库

        Label lblU = new Label();
       lblU.ID = "LabelU" + i.ToString();
        lblU.Text = ds.Tables[0].Rows[i][0].ToString() + " : ";

没有像Autoresize或MaximumWidth这样的属性,我需要一些程序集引用吗?

this is the Bug I want to overcome

1 个答案:

答案 0 :(得分:1)

Label控件呈现为<span>元素,因此只需通过样式表设置其宽度:

我看到你的示例文本没有空格。在这种情况下,您必须将自动换行属性设置为break-word

span {width:5em; word-wrap:break-word}