IIF返回一个资源变量

时间:2015-07-20 15:10:31

标签: c# asp.net

这里是ligne:

<%# IIf(Container.DataItem("OldAdress") = Container.DataItem("NewAdress"), "", "Adress")%> 

而不是硬编码&#34; Adress&#34;,我想返回一个资源变量。有可能吗?

1 个答案:

答案 0 :(得分:0)

通过使用GetGlobalResourceObject / GetLocalResource对象函数。从 https://msdn.microsoft.com/en-us/library/ms227982(v=vs.140).aspx

C#:

<%@ Page Language="C#" %>

<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        Button1.Text = 
            GetLocalResourceObject("Button1.Text").ToString();
        Image1.ImageUrl = 
            (String)GetGlobalResourceObject(
            "WebResourcesGlobal", "LogoUrl");
        Image1.Visible = true;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" 
            OnClick="Button1_Click" 
            Text="Get Resources" />
        <asp:Image ID="Image1" runat="server" 
            Visible="false" />
    </div>
    </form>
</body>
</html>

VB.Net:

<%@ Page Language="VB" %>

<script runat="server">
    Protected Sub Button1_Click( _
        ByVal sender As Object, ByVal e As System.EventArgs)
        Button1.Text = _
            GetLocalResourceObject("Button1.Text").ToString()
        Image1.ImageUrl = _
            CType(GetGlobalResourceObject("WebResourcesGlobal", _
           "LogoUrl"), String)
        Image1.Visible = True
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" 
            OnClick="Button1_Click" 
            Text="Get Resources" />
        <asp:Image ID="Image1" runat="server" 
            Visible="false" />
    </div>
    </form>
</body>
</html>