2012-04-30 29 views
3

我有一個ListView,在其ItemTemplate中我已經綁定的字段,如:
<%#Eval("FiledName") %>
但FeildName itselfe來自資源,如:
<asp:Localize Text="<%$ Resources: Resources, productnamefield %>" runat="server" />
現在,我需要這樣的東西它:
<%#Eval(<asp:Localize Text="<%$ Resources: Resources, productnamefield %>" runat="server" />) %>
但它是不正確的(有編譯錯誤)
我如何結合這兩個?綁定到ListView的字段名來自資源

+0

+1有趣的問題 – Icarus

+0

嗯。我能想到的唯一方法就是反射。 –

+0

所以它是強制使用「評估」,你不能將你的數據綁定到你的ListView中的Web控件(如Literal)? – sbhomra

回答

3

會不是沿着這個工作線:

protected void yourListView_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 
    if (e.Item.ItemType == ListViewItemType.DataItem) 
    { 
     DataRowView drv = e.Item.DataItem as DataRowView; 

     Label filedName = e.Item.FindControl("FiledNameLabel") as Label;  

     //Get resource value 
     string resourceValue = GetGlobalResourceObject("ResourceFile","productnamefield").ToString(); 
     filedName.Text = drv[resourceValue].ToString(); 
    } 
} 

然後,您將使用標籤在你的ListView顯示該值。