2012-04-30 27 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显示该值。