简体   繁体   English

ASP.NET中的HTML条

[英]Html strip in asp.net

I have used a ckeditor in which user can submit data to the database in styles but when the data is populated in the datagrid then also it comes with same styles in IE but I want it to be in plain text when get populated. 我使用了一个ckeditor,用户可以在其中以样式将数据提交到数据库,但是当数据在datagrid中填充时,它在IE中也具有相同的样式,但是我希望在填充时以纯文本格式显示。 the function for populating the data is as follows: 填充数据的功能如下:

protected void LoadQA(int intQuestionId)
{
    string strSelectQuery = "SELECT TITLE, DESCRIPTION, ANSWER, FK_OWNER_ID, CREATED_ON FROM M_QA WHERE PK_ID = "
                          + intQuestionId + " AND IS_ACTIVE = 1";

    OleDbConnection connectionSelectQuestion = new OleDbConnection(ConfigurationSettings.AppSettings["SQLConnectionString"]);
    OleDbCommand commandSelectQuestion = new OleDbCommand(strSelectQuery, connectionSelectQuestion);
    OleDbDataReader readerSelectQuestion;
    try
    {
        connectionSelectQuestion.Open();
        readerSelectQuestion = commandSelectQuestion.ExecuteReader();
        if (readerSelectQuestion.Read())
        {
            lblHeader.Text = "View Q&A";
            txtTitle.Text = readerSelectQuestion["TITLE"].ToString();

            if (readerSelectQuestion["TITLE"].ToString().Length > 50)
            {
                ViewState["QA_Title"] = readerSelectQuestion["TITLE"].ToString().Substring(0, 50) + "...";
            }
            else
            {
                ViewState["QA_Title"] = readerSelectQuestion["TITLE"].ToString();
            }

            txtDescription.Text = readerSelectQuestion["DESCRIPTION"].ToString();
            hlnkQuestionBy.Text = clsCommons.SayUserName(readerSelectQuestion["FK_OWNER_ID"].ToString());
            hlnkQuestionBy.NavigateUrl = "AddMember.aspx?id=" + readerSelectQuestion["FK_OWNER_ID"].ToString();
            lblAskedOn.Text = readerSelectQuestion["CREATED_ON"].ToString();

            if (this.Session["UserId"].ToString() != "1")
            {
                btnUpdate.Visible = false;
                txtEditorAnswer.Visible = false;
                divQaDescription.Visible = true;
                divQaDescription.InnerHtml = Server.HtmlDecode(readerSelectQuestion["ANSWER"].ToString());
            }
            else
            {
                txtEditorAnswer.Text = readerSelectQuestion["ANSWER"].ToString();
            }
        }
        else
        {
            lblError.Text = "ERROR WHILE READING QA DATA!";
        }
    }
    catch (Exception ex)
    {
        ExceptionLogger.LogException(ex);
        lblError.Text = ex.Message;
    }
    finally
    {
        if (connectionSelectQuestion != null)
        {
            connectionSelectQuestion.Close();
        }
    }
}

What changes I need to make to get the plain text in the datagrid. 我需要进行哪些更改才能在数据网格中获取纯文本。

Thanks for ur help.. 感谢您的帮助。

here is some sql code that can strip the tags for you. 这是一些可以为您剥离标签的sql代码。

declare @string varchar(max), --string to remove html from
    @a varchar(max), --holds left part of string after removal
    @b varchar(max) --holds right part of string after removal

set @string='<htlml><head><title></title></head><body>This is the body. <p>This is a paragraph.</p></body></html>'

declare @i bit, --determines if there are any more tags in the string
    @start int, --position of the first < character
    @end int --position of the first > character


set @i='false' --set default value

--set the positions of the first tag
select @start=CHARINDEX('<',@string),
@end=charindex('>',@string)


--only do the loop if there is a tag
if (@start>0 and @end>0) set @i='true'



while (@i='true')
begin

    set @a='' --reset
    set @b='' --reset

    set @a=LEFT(@string,@start-1)
    set @b=RIGHT(@string,len(@string)-@end)

    --select @a, @b

    set @string=@a+@b

    select @start=CHARINDEX('<',@string),
        @end=charindex('>',@string)

    if (@start>0 and @end>0) set @i='true' else set @i='false'


end


select @string

keep in mind, however, that this code does not take into consideration if the text contains a < or >. 但是请记住,如果文本包含<或>,则不会考虑此代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM