Hi,
I have a SQL database table with a description column which has HTML encoded data. I want to display this table's each row in an asp.net 3.5 details view control.
This details view has an template field which displays this column's data. This template field has an aspx Lable control which display's data when the details view is in view mode and a RadEditor which display's data when details view is in edit mode.
But both of these controls display data with HTML tags, but I want to display the data in HTML decoded form. Like plain text with html tag applied on the text, instead of showing along with text in the editor and label.
Here is the code-
<asp:DetailsView ID="dv" runat="server" Width="748px" DataSourceID="dvSqlDataSource"
DataKeyNames="Id" AutoGenerateRows="False"
HeaderText="Details" CellPadding="4">
<Fields>
<asp:BoundField DataField="Id" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:TemplateField HeaderText="Description" SortExpression="Description" >
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%# Eval("description") %>' Width="580px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadEditor ID="RadEditDesc" SkinID="Edit" runat="server" ToolsFile="~/Editor/BasicTools.xml" EditModes="Design,Preview" Width="580px" Content='<%#Bind("description")%>' />
<asp:RequiredFieldValidator ID="valRequireDesc" runat="server" ControlToValidate="RadEditDesc"
Display="Dynamic" ErrorMessage="Required" SetFocusOnError="true" ToolTip="Description is required." />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
<EmptyDataTemplate>No description found!</EmptyDataTemplate>
</asp:DetailsView>
<asp:SqlDataSource ID="dvSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT [ld], [description],FROM [tbldescripion]
UpdateCommand="UPDATE [tbldescription] SET [description] = @description WHERE [Id] = @Id">
<UpdateParameters>
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="description" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
I have handled this event handler for decoding the text of label control but It isn't working
protected void dvDeal_OnDataBound(object sender, EventArgs e)
{
DetailsView d = (DetailsView)sender;
foreach (DetailsViewRow row in d.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
foreach (Control c in row.Cells)
{
foreach (Control c1 in c.Controls)
{
if (c1.GetType() == typeof(Label))
{
Label l = (Label)c1;
l.Text = System.Web.HttpUtility.HtmlDecode(l.Text);
}
}
}
}
}
Anybody knows, how can we display a html encoded string into the lable control and in RadEditor as well in html decoded form. So that the end user can easily view and edit the description without looking onto these confusing html tags.
Any help will be really appreciated.
Regards,
dazy
I have a SQL database table with a description column which has HTML encoded data. I want to display this table's each row in an asp.net 3.5 details view control.
This details view has an template field which displays this column's data. This template field has an aspx Lable control which display's data when the details view is in view mode and a RadEditor which display's data when details view is in edit mode.
But both of these controls display data with HTML tags, but I want to display the data in HTML decoded form. Like plain text with html tag applied on the text, instead of showing along with text in the editor and label.
Here is the code-
<asp:DetailsView ID="dv" runat="server" Width="748px" DataSourceID="dvSqlDataSource"
DataKeyNames="Id" AutoGenerateRows="False"
HeaderText="Details" CellPadding="4">
<Fields>
<asp:BoundField DataField="Id" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:TemplateField HeaderText="Description" SortExpression="Description" >
<ItemTemplate>
<asp:Label ID="lblDescription" runat="server" Text='<%# Eval("description") %>' Width="580px"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadEditor ID="RadEditDesc" SkinID="Edit" runat="server" ToolsFile="~/Editor/BasicTools.xml" EditModes="Design,Preview" Width="580px" Content='<%#Bind("description")%>' />
<asp:RequiredFieldValidator ID="valRequireDesc" runat="server" ControlToValidate="RadEditDesc"
Display="Dynamic" ErrorMessage="Required" SetFocusOnError="true" ToolTip="Description is required." />
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
<EmptyDataTemplate>No description found!</EmptyDataTemplate>
</asp:DetailsView>
<asp:SqlDataSource ID="dvSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"
SelectCommand="SELECT [ld], [description],FROM [tbldescripion]
UpdateCommand="UPDATE [tbldescription] SET [description] = @description WHERE [Id] = @Id">
<UpdateParameters>
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="description" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
I have handled this event handler for decoding the text of label control but It isn't working
protected void dvDeal_OnDataBound(object sender, EventArgs e)
{
DetailsView d = (DetailsView)sender;
foreach (DetailsViewRow row in d.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
foreach (Control c in row.Cells)
{
foreach (Control c1 in c.Controls)
{
if (c1.GetType() == typeof(Label))
{
Label l = (Label)c1;
l.Text = System.Web.HttpUtility.HtmlDecode(l.Text);
}
}
}
}
}
Anybody knows, how can we display a html encoded string into the lable control and in RadEditor as well in html decoded form. So that the end user can easily view and edit the description without looking onto these confusing html tags.
Any help will be really appreciated.
Regards,
dazy