0

Hi I am developing a html tag based user input, like a rich text box, which saves all the data into a database; including all the html tags.

I then am pulling this data using gridview in asp.net c#.

But when the gridview displays my data, it displays incorrectly.

For example: a user enter his name in bold in the rich textbox as such < b > Superman < /b >, to make it bold. Sadly the gridview displays ecxactly what was entered tags and all without making it bold.

Another example: To enter the name in italics:< i > Superman < /i >, Superman is being display, not in italics.

What I want is for the gridview to display like an HTML PAGE, just like the rich textbox does.

I am using to write question. <-- no idea

Can you help me please? Thanks

Pow-Ian
  • 3,607
  • 1
  • 22
  • 31
Jack
  • 151
  • 1
  • 4
  • 21

2 Answers2

2

when you bring the html(because that is what you are asking them to enter) back to the view, you are either going to need to transform it yourself or eval the html as is mentioned by @MikeB

alternatively if you are not using Razor try this question for some ideas:

Is there a way to insert Html into a gridview row?

Community
  • 1
  • 1
Pow-Ian
  • 3,607
  • 1
  • 22
  • 31
  • I have finally found this cell.Text = Server.HtmlDecode(cell.Text); thank for the help Pow-lan and MikeB. – Jack Nov 12 '12 at 22:02
1

You need to display the raw html. Otherwise it is html encoded to prevent people from being able to run scripts against your site.

You need to be extremely careful displaying user inputted raw html.

If you are using razor it will be something like this:

@Html.Raw(ViewBag.HtmlOutput)
Malkus
  • 3,686
  • 2
  • 24
  • 39