SQL Server BackEND Populates Datagrid with HTML Snipets

Discussion in 'ASP .Net Datagrid Control' started by Eric, Apr 2, 2004.

  1. Eric

    Eric Guest

    Howdy,
    I have a SQL back end holding a bunch of html CODE snipits that I want
    to populate in a datagrid using VB.net.

    The problem is that the browser is rendering the code snipets rather
    than displaying them.

    For instance. Once of the values in the database is the following
    string.

    "<img src=http://www.msn.com/logo.gif border=0>"

    Rather than displaying that HTML snippet string it displays the actual
    image since the browser is rendering it.

    Do the <code></code> tags work? it doesn't look like it. I know it's
    possible since the code on these message boards is never rendered by
    the browser.

    Thanks

    ericlangland AT hotmail DOT com
     
    Eric, Apr 2, 2004
    #1
    1. Advertising

  2. You will have to write code in the ItemDataBound to change HTMLEncode the
    string, cos by default DataGrid displays text as is (including HTML tags)

    Private Sub DGrid_ItemDataBound(sender As Object, e As
    DataGridItemEventArgs)
    Dim imageIndex As Integer

    ' Set the position of the image column
    columnIndex = 5

    ' HTMLEncode the column's text
    sender.Item.Cells(columnIndex).Text =
    Server.HTMLEncode(sender.Item.Cells(columnIndex).Text)
    End Sub


    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Eric" <> wrote in message
    news:...
    > Howdy,
    > I have a SQL back end holding a bunch of html CODE snipits that I want
    > to populate in a datagrid using VB.net.
    >
    > The problem is that the browser is rendering the code snipets rather
    > than displaying them.
    >
    > For instance. Once of the values in the database is the following
    > string.
    >
    > "<img src=http://www.msn.com/logo.gif border=0>"
    >
    > Rather than displaying that HTML snippet string it displays the actual
    > image since the browser is rendering it.
    >
    > Do the <code></code> tags work? it doesn't look like it. I know it's
    > possible since the code on these message boards is never rendered by
    > the browser.
    >
    > Thanks
    >
    > ericlangland AT hotmail DOT com
     
    Manohar Kamath [MVP], Apr 2, 2004
    #2
    1. Advertising

  3. Eric

    Eric Guest

    Manohar,
    Thanks for the post. Much appreciated. It got me on the right track
    but your post has a few syntax errors. Here's the final sub that works
    if anybody cares.

    Private Sub MyDatagrid_ItemDataBound(sender As Object, e As
    DataGridItemEventArgs)

    ' Set the position of the image column
    DIM columnIndex As Integer = 3

    ' HTMLEncode the column's text
    e.Item.Cells(columnIndex).Text =
    Server.HTMLEncode(e.Item.Cells(columnIndex).Text)
    End Sub

    Thanks

    Eric


    "Manohar Kamath [MVP]" <> wrote in message news:<>...
    > You will have to write code in the ItemDataBound to change HTMLEncode the
    > string, cos by default DataGrid displays text as is (including HTML tags)
    >
    > Private Sub DGrid_ItemDataBound(sender As Object, e As
    > DataGridItemEventArgs)
    > Dim imageIndex As Integer
    >
    > ' Set the position of the image column
    > columnIndex = 5
    >
    > ' HTMLEncode the column's text
    > sender.Item.Cells(columnIndex).Text =
    > Server.HTMLEncode(sender.Item.Cells(columnIndex).Text)
    > End Sub
    >
    >
    > --
    > Manohar Kamath
    > Editor, .netWire
    > www.dotnetwire.com
    >
    >
    > "Eric" <> wrote in message
    > news:...
    > > Howdy,
    > > I have a SQL back end holding a bunch of html CODE snipits that I want
    > > to populate in a datagrid using VB.net.
    > >
    > > The problem is that the browser is rendering the code snipets rather
    > > than displaying them.
    > >
    > > For instance. Once of the values in the database is the following
    > > string.
    > >
    > > "<img src=http://www.msn.com/logo.gif border=0>"
    > >
    > > Rather than displaying that HTML snippet string it displays the actual
    > > image since the browser is rendering it.
    > >
    > > Do the <code></code> tags work? it doesn't look like it. I know it's
    > > possible since the code on these message boards is never rendered by
    > > the browser.
    > >
    > > Thanks
    > >
    > > ericlangland AT hotmail DOT com
     
    Eric, Apr 5, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Um9zZQ==?=

    Dropdownlist populates Datagrid

    =?Utf-8?B?Um9zZQ==?=, Aug 29, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    561
    =?Utf-8?B?Um9zZQ==?=
    Aug 29, 2005
  2. gk
    Replies:
    1
    Views:
    466
  3. =?Utf-8?B?a2VuIHM=?=

    javascript populates dropdownlist

    =?Utf-8?B?a2VuIHM=?=, Feb 10, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    368
    Ken Smith
    Feb 11, 2007
  4. Ted
    Replies:
    1
    Views:
    425
  5. David. E. Goble
    Replies:
    9
    Views:
    479
    David. E. Goble
    Feb 2, 2005
Loading...

Share This Page