Asp.Net将字符串从资源绑定到ListItem

时间:2013-04-23 11:49:10

标签: asp.net

我有以下代码。

  <asp:DropDownList ID="CurrencyList" AutoPostBack="true" runat="server" OnSelectedIndexChanged="CurrencyList_SelectedIndexChanged">
                    <asp:ListItem Text="<%$ GetGlobalResourceObject("GlobalResourceBms", "RentPage2FilterByLabel")%>" Value="-1"></asp:ListItem>
                </asp:DropDownList>

此代码抛出

  

分析器错误消息:文字表达式,如'&lt;%$ GetGlobalResourceObject(“GlobalResourceBms”,“RentPage2FilterByLabel”)%&gt;'不允许。请改用“/&gt;”。

如何在Asp.NET中使用这个东西,我需要从资源中获取字符串并将其作为下拉列表项目

2 个答案:

答案 0 :(得分:1)

尝试使用

<%# GetGlobalResourceObject("GlobalResourceBms","RentPage2FilterByLabel" ) %> 

修改

您需要以不同的方式添加项目。

使用rowdatabound方法填充ddl。看:

public void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow) {
        DropDownList ddl = (DropDownList)e.Row.FindControl("CurrencyList");
        //items.

    }
}

答案 1 :(得分:0)

我有点“迟到了吗?尽管如此,它可能会帮助别人。 &lt;%$%&gt;语法不允许编码表达式。使用: “值=” - 1“/&gt;