如何从 C# 后面的代码更改 CKeditor 的背景

How to change background of CKeditor from code behind C#

真的很简单的问题。如何从 C# 更改 CKeditor 的背景颜色?

如何在 C# 中获取 CKeditor 的实例?可能我不能?

我有一个带有很多文本区域 (asp:textbox) 控件的 gridview,所有控件都使用 CKeditor,通过 CSSclass 属性,效果很好!但是现在我想动态地将它们的一两个或所有背景颜色更改为 LightYellow.

我试图直接更改 asp:textbox 的背景,但它当然不起作用,因为那是来自 CKeditor 本身的 "hidden"。

还有其他提示吗?

更新

我已经为 ASP.net 下载了 CKEditor,它也 不起作用 ,因为它还会在后台自动创建一个 textarea 元素 -实际上与使用 CSSclass="".

本机使用 CKeditor 相同

引用 C# 中的控件,我现在可以做到这一点,这很好,所以我可以获取数据并在我的数据库中使用它,但我仍然无法更改 CKeditor 的背景。 CKeditor 的 BODY 元素(通过 FireBug 测试)是我需要更改的元素,但是如何从 C# 更改?

再次感谢

首先,确保您已经通过 Nuget 安装了两个 CKEditor and CkeditorForASP.NET 包。

然后,创建一个 editor.css 文件,该文件将仅包含与编辑器相关的样式,例如:

.lightYellow {
   background-color: lightyellow;
}

在您的网格视图中,绑定到 OnRowDataBound 事件并正确指定 CKEditor 脚本的基本路径。

<asp:GridView ID="EditorGridView" runat="server" OnRowDataBound="EditorGridView_RowDataBound">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <CKEditor:CKEditorControl ID="Editor" runat="server" BasePath="~/Scripts/ckeditor" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

那么您就可以按如下方式更改主体颜色:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    CKEditorControl editor = (CKEditorControl)e.Row.FindControl("Editor");
    editor.BodyClass = "lightYellow";
    editor.ContentsCss = ResolveUrl("~/Content/editor.css");
}