Solved

HTMLEncode in Code-Behind GridView BoundField

Posted on 2008-10-02
2
3,535 Views
Last Modified: 2012-05-05
I have successfully created a GridView in my code and can add a BoundColumn too.  However, when the column is drawn on the page, the HTML tags are displayed.  

{.asp.vb code}
                        Dim dg As New GridView
                        dg.AutoGenerateColumns = False
                        dg.ShowHeader = False
                        dg.CssClass = "SubReqBox_on"
                        Dim dgc As BoundField = New BoundField()
                        dgc.DataField = "CRSubRequirement"
                        dgc.HtmlEncode = True
                        dgc.HtmlEncodeFormatString = True
                        dgc.InsertVisible = True
                        dg.Columns.Add(dgc)
                        dg.DataSource = ds
                        dg.DataBind()

The text in my DB that corresponds to CRSubRequirement would be something like:

<div>words words words</div>

And of course, I don't want those Div tags showing in my grid.
0
Comment
Question by:Steve Krile
2 Comments
 
LVL 16

Accepted Solution

by:
Gyanendra Singh earned 500 total points
ID: 22625174
use this for bound field

         <asp:boundfield datafield="Address"
            htmlencode="false"
            headertext="Address"/>
         

also set  htmlencode="false" for yr grid
0
 
LVL 16

Author Comment

by:Steve Krile
ID: 22625270
Aha!  If you don't want to see HTML, set HTMLEncode to false.  Sure..Got it!

The "answer" is then:

                       Dim dg As New GridView
                        dg.AutoGenerateColumns = False
                        dg.ShowHeader = False
                        dg.CssClass = "SubReqBox_on"
                        Dim dgc As BoundField = New BoundField()
                        dgc.DataField = "CRSubRequirement"
                        dgc.HtmlEncode = False  '<--IMPORTANT PART-->
                        dgc.HtmlEncodeFormatString = True
                        dgc.InsertVisible = True
                        dg.Columns.Add(dgc)
                        dg.DataSource = ds
                        dg.DataBind()


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now