2013-04-23 59 views
0

我有以下代碼。從資源到ListItem的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> 

此代碼拋出

分析器錯誤信息:像文字表現形式 '<%$ GetGlobalResourceObject( 「GlobalResourceBms」, 「RentPage2FilterByLabel」)%>' 是不允許的。使用「/>代替。

如何這個東西Asp.NET,我需要從資源獲取字符串,並把它作爲下拉列表的項目

回答

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. 

    } 
} 
+0

文字內容。( '的 StringBuilder 2013-04-23 12:04:25

+0

感謝的人之內,但我也有點震驚的是ASP .NET在標記中不支持這一點。 – StringBuilder 2013-04-23 12:15:27