2012-04-26 41 views
1
<asp:DetailsView ID="DetailsView1" runat="server" 
DataSourceID="SqlDataSource1" AutoGenerateRows="False" 
DataKeyNames="ID" DefaultMode="Insert" > 

...如何在細節視圖中進行html解碼?

<asp:TextBox ID="ShortExcerptTextBox" runat="server" 
Text='<%#Bind("ShortExcerpt") %>' class="mceEditor" 
TextMode="MultiLine"></asp:TextBox> 

這是代碼,我有。

問題是我需要以某種方式HttpUtility.HtmlDecode它在#Bind("ShortExcerpt")那裏,但不知道如何。

最初的問題是tinyMCE(富文本編輯器)自行對文本進行編碼,但在讀取時不對其進行解碼。一個長長的故事:P

所以請只是,有人,說明,如何HttpUtility.HtmlDecode被讀入#Bind("ShortExcerpt")的文本請?

日Thnx

回答

5

我不認爲你可以使用HtmlDecodeBind

因此,無論嘗試HtmlDecode文本框在代碼隱藏:

<asp:TextBox ID="ShortExcerptTextBox" runat="server" 
    Text='<%# Eval("ShortExcerpt") %>' 
    OnDataBinding="ShortExcerptTextBox_DataBinding" class="mceEditor" 
    TextMode="MultiLine"> 
</asp:TextBox> 


protected void ShortExcerptTextBox_DataBinding(object sender, EventArgs e) 
{ 
    var txt = (TextBox)sender; 
    txt.Text = HttpUtility.HtmlDecode(txt.Text); 
} 

或嘗試使用Eval,而不是(如果這是可以接受的):

<asp:TextBox ID="ShortExcerptTextBox" runat="server" 
    Text='<%# HttpContext.Current.Server.HtmlDecode((string)Eval("ShortExcerpt")) %>' 
    class="mceEditor" 
    TextMode="MultiLine"> 
</asp:TextBox> 

雙方尚未測試。

+1

是的。作品。日Thnx。我使用了後面的代碼。 – b0x0rz 2012-04-26 22:25:21

+0

也許你可以幫助解決後續問題?對不起,打擾:(http://stackoverflow.com/q/10342792/101055 thnx – b0x0rz 2012-04-26 23:25:45

相關問題