Solved

HTMLEncode in Code-Behind GridView BoundField

Posted on 2008-10-02
2
3,581 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

18 Experts available now in Live!

Get 1:1 Help Now