4

I am trying to populate a gridview from sharepoint list and population is working good expect in one column i want to display and <a> tag

I have the following code:

 StringBuilder cstext = new StringBuilder(); dr["Status"] = cstext.Append("<a>click me</a>"); 

but in my browser i am seeing this <a>click me</a> and in inspect element i am seeing this &lt;a&gt;click me&lt;/a&gt;

Please help me

3
  • can you try it as cstext.Append("<a>click me</a>").toString(); ? Commented Jul 11, 2017 at 8:33
  • @GautamSheth: ToString won't help, as it's called anyway before rendering. The problem probably is HTMLEncode-ing the content Commented Jul 11, 2017 at 8:36
  • 2
    A StringBuilder is for Building strings, and the Append() methods return value is intended for chaining (value.Append("a").Append("b") ). Using it in the way you are using it (like a regular System.String) is probably going to lead to other unwanted side effects. Commented Jul 11, 2017 at 12:15

1 Answer 1

6

I'm guessing your problem is not StringBuilder, but the "gridview". Are you using a SPGridView?

If so, the grid is probably encoding the content you put there. If you want to add HTML content in a cell set the HTMLEncode-property of your BoundField to false.

Also, on a sidenote, dr["Status"] = cstext.Append("<a>click me</a>"); will set the content of the cell to the StringBuilder. StringBuilder.Append will return the whole StringBuilder.

1
  • i luv u, u saved my life Commented Jul 11, 2017 at 8:38

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.