PDA

View Full Version : عدم نمایش صحیح کنترل Literal درون Listview



A.S.Roma
یک شنبه 13 تیر 1389, 10:40 صبح
با سلام ... .

من دیتای ذخیره شده در DB را به شکل کد HTML است را با استفاده از Literal که درون Listview است می خواهم نمایش دهم اما متاسفانه درست کار نمی کند و به جای اینکه خروجی html بدهد خروجی text می دهد .
یک نمونه خروجی اشتباه :



<p> <strong>This Is A Test !</strong></p> <p> <strong>This Is A Test !</strong></p> <p> <strong>This Is A Test !</strong></p> <p> <strong>This Is A Test !</strong></p>


اما وقتی Literal را با همین Text خارج از Listview می گذارم خروجی صحیح می دهد !
با هر سه مد هم متحان کردم نشد !

A.S.Roma
یک شنبه 13 تیر 1389, 10:59 صبح
با Repeater نیز امتحان کردم و کار نمی کند.

raziee
یک شنبه 13 تیر 1389, 11:10 صبح
protected void Gv_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{

Literal lit = (Literal)e.Row.FindControl("Literal1");
lit.Text = Server.HtmlDecode(lit.Text);

}

}


این کد رو دوستمون در اینجا (http://barnamenevis.org/forum/showpost.php?p=1027145&postcount=39)داده بودند.

A.S.Roma
یک شنبه 13 تیر 1389, 11:49 صبح
ممنون مشکل حل شد اما دلیلش ؟!:افسرده:

Mostafa_Dindar
یک شنبه 13 تیر 1389, 12:16 عصر
سلام ,

البته کدی که دوستمون گذاشتند مربوط رویداد RowDataBound از گریدویو بود . من به شخصه ترجیح میدم که از یک متد کمکی استفاده کنم :

public static class TextUtil
{
/// <summary>
/// كار متد HttpUtility.HtmlDecode را انجام ميدهد
/// </summary>
/// <param name="rawText">آبجكتي كه ميخواهيد ديكد شدود</param>
/// <returns>رشته</returns>
public static string decodeText(Object rawText)
{
string txtObject = Convert.ToString(rawText);
if (!string.IsNullOrEmpty(txtObject))
return HttpUtility.HtmlDecode(txtObject);
return null;
}
}

و در ItemTemplate کنترل مورد نظر , اون رو فراخونی کنم