2012-08-03 84 views
1

我们正从2.0版本迁移ASP.NET项目4.0ASP.NET 4.0服务器标签

在以前的版本我有下面的代码行规定:

<asp:CheckBox runat="server" ID="chkContentFilter" 
     Text="<%# SearchResultDictionary.ContentFilter %>" 
     OnCheckedChanged="chkFilterCheckbox_ValueChanged" AutoPostBack="True" 
     EnableViewState="True" ></asp:CheckBox> 

的问题是,在ASP .NET 4.0 <%# %>服务器标记不会将数据映射到控件。

当然,有一种解决方法可以在代码隐藏中设置控制文本。但我很有趣,有没有办法在aspx布局上绑定文本?

+0

你有什么似乎很好,你能告诉我们你收到了什么错误? 也许更多关于“SearchResultDictionary.ContentFilter” – 2012-08-03 13:12:37

+1

检查这里:http://stackoverflow.com/questions/558954/asp-net-inline-expression-issue – Karlth 2012-08-03 13:14:37

+0

我没有得到任何错误。只需在文本字段中清空文本。我需要的是设置此文本,请注意控件不在数据绑定控件中。 – 2012-08-03 13:24:30

回答

3

必须调用DataBind()在容器上或控制本身<%# %>进行评估:

Data-Binding Expressions

标记:

<asp:CheckBox runat="server" ID="chkContentFilter" 
     Text='<%# SearchResultDictionary.ContentFilter %>' 
     OnCheckedChanged="chkFilterCheckbox_ValueChanged" AutoPostBack="True" 
     EnableViewState="True" ></asp:CheckBox> 

代码隐藏:

chkContentFilter.DataBind();