如何从c#背后的代码改变CKeditor的背景
本文关键字:代码 改变 CKeditor 背景 背后 | 更新日期: 2023-09-27 18:15:33
真的很简单。如何从c#更改CKeditor的背景颜色?
如何在c#中获得CKeditor的实例?也许我不能?
我有一个gridview与许多文本区(asp:textbox)控制所有使用CKeditor,通过CSSclass
属性,它工作得很好!但现在我想动态地改变一个或两个,或所有的背景颜色,像LightYellow
。
我试图直接改变asp:textbox
的背景,但它当然不起作用,因为这是"隐藏"的CKeditor本身。
还有什么建议吗?
我已经下载了ASP.net的CKEditor,它也不工作,因为它还自动在后台创建了一个textarea
元素-有效地与使用CKEditor原生CSSclass=""
相同。
引用c#中的控件,我现在可以这样做,这很好,所以我可以得到数据并在我的数据库中使用它,但我仍然无法改变CKeditor的背景。CKeditor的BODY元素(通过FireBug测试),是我需要改变的,但如何从c# ?
再次感谢
首先,确保您已经安装了CKEditor和CKEditor forasp。. NET包通过Nuget。
然后,创建一个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");
}