When I tried to add html to data for my GridView control, I could only see html code. I could see "<span class="myhtmlclass">my text</span> from SQL request</span>. But I wanted to wrap my content with <span> tags.

I had this GridView column:

        GridView1.Columns.Add(new BoundField()
        {
            DataField = "msgb",
            HeaderText = "msgb",
            ReadOnly = true
        });

 

I was sure that it’ll be enough this code for Collection:

	myclass.msgb = "<span class="myhtmlclass">" + my text + "</span>"

 

But as a result I could see this on my display:

<span class="myhtmlclass">my text</span>

 

The solution appeared to be very simple – you need to set HtmlEncode for GridView cell to ‘false’ value. By default is is set in "true" value:

     GridView1.Columns.Add(new BoundField()
     {
         DataField = "msgb",
         HeaderText = "msgb",
         HtmlEncode = false,
         ReadOnly = true
     });