【问题标题】:How to set Label Text in .aspx markup using a static class in application?如何在应用程序中使用静态类在 .aspx 标记中设置标签文本?
【发布时间】:2018-08-14 10:49:08
【问题描述】:

下面是解决方案中的静态类, 命名空间 WebApplication1

{
    public static class LabelValues
    {
        public static string GetLabelValue(string str)
        {
            Return "Hello" + str; //There's a complicated logic for this
        }
    }
}

现在我想使用下面的代码设置标签文本。但它不起作用

<asp:Label ID="_label1" runat="server" Text="<%# LabelValues.GetLabelValue("_label1") %>" >

我想从标签控件的 Text 属性中调用静态类来设置标签的值。

【问题讨论】:

标签: c# asp.net


【解决方案1】:

正如 VDWWD 所提到的,您可以写出完整的命名空间。同样对于数据绑定语法,我相信您需要将其用单引号括起来。

<asp:Label ID="_label1" runat="server" Text='<%# WebApplication1.LabelValues.GetLabelValue("_label1") %>' >

在这里看到https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/bda9bbfx(v=vs.100)

【讨论】:

    猜你喜欢
    • 2011-01-12
    • 2017-05-20
    • 2014-06-26
    • 2012-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多