SQL Server BackEND Populates Datagrid with HTML Snipets

E

Eric

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
 
M

Manohar Kamath [MVP]

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
 
E

Eric

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top