[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3901
  • Last Modified:

HTMLEncode in Code-Behind GridView BoundField

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
Steve Krile
Asked:
Steve Krile
1 Solution
 
Gyanendra SinghArchitectCommented:
use this for bound field

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

also set  htmlencode="false" for yr grid
0
 
Steve KrileAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now