在ASP.NET控件属性中使用条件语句

在ASP.NET控件属性中使用条件语句,asp.net,binding,model,Asp.net,Binding,Model,我的页面上有一个DropDownList,我希望DataTextField值基于条件(语言)。我正在使用模型绑定,这个下拉列表嵌套在绑定的FormView中 这就是我想做的: <asp:DropDownList ID="DropDownList1" ItemType="BLL.HelperClasses.ItemForList" DataValueField="id" DataTextField="<%#:

我的页面上有一个DropDownList,我希望DataTextField值基于条件(语言)。我正在使用模型绑定,这个下拉列表嵌套在绑定的FormView中

这就是我想做的:

<asp:DropDownList ID="DropDownList1" ItemType="BLL.HelperClasses.ItemForList" 
                                     DataValueField="id" DataTextField="<%#: (this.IsEnglish) ? "en" : "fr" %>" SelectMethod="DropDownList1_GetData" 
                                     SelectedValue="<%#: Item.Claim.CurrencyID %>" runat="server"></asp:DropDownList>

.NET正在抱怨我的DataTextField“服务器标记格式不正确”。IsEnglish是我的基本页中的布尔属性

有人知道如何在不使用隐藏代码的情况下执行此操作吗?

我认为您必须插入“Eval”,以便它实际比较它们,不是吗

<asp:label id="Label1" runat="server" text="<%# Eval("StReply") == true ? "yes" : "no" %>"     xmlns:asp="#unknown">
</asp:label>

问题在于周围的双引号。把它们改成单引号,一切都很完美

最终解决方案:

<asp:DropDownList ID="DropDownList1" ItemType="BLL.HelperClasses.ItemForList" 
                  DataValueField="id" DataTextField='<%#: (this.IsEnglish) ? "en" : "fr" %>' SelectMethod="DropDownList1_GetData" 
                  SelectedValue="<%#: Item.Claim.CurrencyID %>" runat="server"></asp:DropDownList>

不起作用。1) Eval至少需要转换为bool。2) 仍然给我YSOD,抱怨标签格式不正确。检查了你提供的链接中的其他解决方案,仍然没有骰子。