[英]Html strip in asp.net
我使用了一個ckeditor,用戶可以在其中以樣式將數據提交到數據庫,但是當數據在datagrid中填充時,它在IE中也具有相同的樣式,但是我希望在填充時以純文本格式顯示。 填充數據的功能如下:
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();
}
}
}
我需要進行哪些更改才能在數據網格中獲取純文本。
感謝您的幫助。
這是一些可以為您剝離標簽的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
但是請記住,如果文本包含<或>,則不會考慮此代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.