2012-08-03 86 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();