【问题标题】:Display TinyMCE content in datagridview c# asp.net在datagridview c#asp.net中显示TinyMCE内容
【发布时间】:2017-11-23 06:51:42
【问题描述】:

我尝试使用 AddMemo.aspx 页面中的 multiLine 属性将 TinyMCE 添加到我的文本框,并且成功。这是我页面中的 javascript sintax:

<script type="text/javascript">
   tinyMCE.init({
        mode : "textareas",
        theme : "advanced",
        plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
        theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : false,
        template_external_list_url : "js/template_list.js",
        external_link_list_url : "js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "js/media_list.js"
    });
</script>

这是我们的照片:

当点击提交按钮时,它将被保存到数据库中。我不知道如何在HistoryMemo.aspx 中将TiniMCE 内容sintax 显示到我的DataGridview(我使用绑定源)。 结果如下:

任何人都可以帮助我将 TiniMCE 内容从数据库显示到我的 datagridview 我会很感激吗?

【问题讨论】:

    标签: c# asp.net datagridview tinymce


    【解决方案1】:

    我相信您需要使用@Html.Raw 来阻止 .NET 转义您的 HTML。

    【讨论】:

      【解决方案2】:

      如果您想将 TinyMCE 内容从数据库显示到您的 datagridview,只需将此代码添加到您的 datagriview 页面,以在您的 datagridview 的所有列中解码 html:

      protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
              {
                  if (e.Row.RowType == DataControlRowType.DataRow)
                  {
                      for (int i = 0; i < e.Row.Cells.Count; i++)
                      {
                          string encoded = e.Row.Cells[i].Text;
                          e.Row.Cells[i].Text = Context.Server.HtmlDecode(encoded);
                      }
                  }
              }
      

      如果您想解码到特定列(例如第一列),请添加以下代码:

      if (e.Row.RowType == DataControlRowType.DataRow)
      {
        string decodedText = HttpUtility.HtmlDecode(e.Row.Cells[0].Text);
        e.Row.Cells[0].Text = decodedText;
      }
      

      您可以根据需要进行自定义。

      【讨论】:

        【解决方案3】:

        SqlDataReader 帮助你显示没有html标签的内容

        string strQuery = "SELECT * from table";
        using (SqlConnection myCon = new SqlConnection(con))
        {
            using (SqlCommand cmd = new SqlCommand(strQuery, myCon))
            {
                myCon.Open();
                using (SqlDataReader sdr = cmd.ExecuteReader())
                {
                    GridView1.DataSource = sdr;
                    GridView1.DataBind();
                    sdr.Close();
                }
                myCon.Close();
            }
        }
        

        【讨论】:

        • 欢迎来到 StackOverFlow,@SajithKumar ! 虽然这确实回答了这个问题,但对代码的一些解释对我们所有人都有好处。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-07-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多