Zain ul Haq Zain ul Haq - 2 months ago 10
ASP.NET (C#) Question

ASP .NET display html tags in RadioButton.Text

I am developing a quiz application in ASP.NET. I am using radio buttons to display options like this:

rbOption1.Text = reader["Option1"].ToString();

Now, for a question related to HTML, all the options have only HTML tags in database e.g:

tr td /td td rowspan=”2” /td /tr


I have removed the
<>
signs otherwise the above example won't render here as text.

When the text for such radio buttons is rendered on webpage, then no text is displayed using
RadioButton.Text
property.

How can I force the radio buttons to display the tags as stored in database?

Answer

You could do something like this:

string TestString = "This is a <Test String>.";
string EncodedString = System.Web.HttpUtility.HtmlEncode(TestString);

More information here: https://www.dotnetperls.com/htmlencode-htmldecode

But the bigger question is why you want to use tables in the first place. It might be a lot simpler to look at a CSS implementation.

Comments