Solved

HTMLEncode in Code-Behind GridView BoundField

Posted on 2008-10-02
2
3,661 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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.…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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