使用 C# 和 ASP.NET 的带有 CKEDITOR 的 GridView

发布于 2025-01-11 05:27:55 字数 2547 浏览 0 评论 0原文

所以我有一个网站,它使用主 GridView 和 CKEDITOR

如果我使用 CKEDITOR 编辑文本框上的字符串,则不会有问题。字符串的格式正确。

问题是当我关闭编辑时 GridView 中字符串的输出。

字符串未按 CKEDITOR 中的预期换行,并且一个字符串与另一个字符串之间没有空格。

我尝试使用此代码,但 GridView 中字符串的输出显示 HTML 代码。

我需要在 GridView 中显示与在 CKEDITOR 中编辑字符串时看到的相同格式。

这是 HTML 代码

,在编辑 gridview 行时,字符串的格式正确。

关闭编辑行后,网格视图不遵守格式并在一行上显示字符串。

<td align="left">
<span id="ctl00_ContentPlaceHolder1_gvProducts_ctl04_lbsezi" class="LabelJustifyTextStyle" style="padding:20px;">
<ul>
<li>        
<strong>First</strong>
</li>  
</ul>  
<p style="margin-left: 30pt; text-align: justify;">     
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>  
<ul>
<li>        
<strong>Second</strong>
</li> 
</ul>  
<p style="margin-left: 40px; text-align: justify;">     
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>  
</td>

感谢您的任何建议。

<asp:Label ID="lb" runat="server" CssClass="LabelJustifyTextStyle"
     Text='<%# Eval("lb").ToString().Contains("base64") ?
     HttpUtility.HtmlDecode(Eval("lb").ToString()) :
     HttpUtility.HtmlDecode(Mp.SpliceText(Eval("lb").ToString(),150)) %>'></asp:Label>
 
    public static string SpliceText(string text, int lineLength)
    {
        var charCount = 0;
        var lines = text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                        .GroupBy(w => (charCount += w.Length + 1) / lineLength)
                        .Select(g => string.Join(" ", g));
 
        return String.Join("<br />", lines.ToArray());
    }

So I have a web site that uses a main GridView with CKEDITOR.

Don't have problem if I use CKEDITOR for edit the string on the texbox. The string it's formatted correctly.

The problem i'ts the output of the string in GridView when I close the editing.

The strings don't wrap as expected in CKEDITOR and there is no space between one string and another.

I have tried using this code, but the output of the string in GridView displays the HTML code.

I need show in GridView the same formatting that you see when editing the string in CKEDITOR.

This is HTML code

In editing gridview row the string it's formatted correctly.

Closed the editing row the gridview does not respect the formatting and show the strings on a single line.

<td align="left">
<span id="ctl00_ContentPlaceHolder1_gvProducts_ctl04_lbsezi" class="LabelJustifyTextStyle" style="padding:20px;">
<ul>
<li>        
<strong>First</strong>
</li>  
</ul>  
<p style="margin-left: 30pt; text-align: justify;">     
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>  
<ul>
<li>        
<strong>Second</strong>
</li> 
</ul>  
<p style="margin-left: 40px; text-align: justify;">     
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.</p>  
</td>

Thanks for any advice.

<asp:Label ID="lb" runat="server" CssClass="LabelJustifyTextStyle"
     Text='<%# Eval("lb").ToString().Contains("base64") ?
     HttpUtility.HtmlDecode(Eval("lb").ToString()) :
     HttpUtility.HtmlDecode(Mp.SpliceText(Eval("lb").ToString(),150)) %>'></asp:Label>
 
    public static string SpliceText(string text, int lineLength)
    {
        var charCount = 0;
        var lines = text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
                        .GroupBy(w => (charCount += w.Length + 1) / lineLength)
                        .Select(g => string.Join(" ", g));
 
        return String.Join("<br />", lines.ToArray());
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文