gpt4 book ai didi

c# - 将多行文本绑定(bind)到标签

转载 作者:太空狗 更新时间:2023-10-29 21:14:27 24 4
gpt4 key购买 nike

我需要将大型文本数据动态绑定(bind)到标签。我将从数据源获取一些大文本数据,并且必须将其绑定(bind)到标签。那么如何在标签中显示多行文字。

最佳答案

最简单的就是

string value = "one\r\ntwo\r\nthree";

label.Text = value.Replace(Environment.NewLine, "<br/>");

但是如果您有一个字符串列表,您可以尝试使用中继器方法

<asp:Label ID="label" runat="server">
<asp:Repeater ID="repeater" runat="server">
<ItemTemplate>
<%# Container.DataItem %> <br />
</ItemTemplate>
</asp:Repeater>
</asp:Label>

代码

List<string> listOfStrings = new List<string>()
{
"One", "Two", "Three"
};

repeater.DataSource = listOfStrings;
repeater.DataBind();

关于c# - 将多行文本绑定(bind)到标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6692168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com