1

Ive been banging my head against the wall for the last few hours, I just cant seem to view the HTML markup from a SQL Cell in a GridView.

When I set the AutoGenerateColumns=False it's easy because I can set the boundfield property in the DataGird ASP.Net markup. However, I can't seem to do anything with the gridview if the AutoGenerate is turned on.

Here is my vb code:

      Dim sqlcmd As String = "Select [Bugs:], [QC#:] FROM " & """" & datasource & """" & Extra
    Using con As New System.Data.SqlClient.SqlConnection(connexstring)
        con.Open()
            Dim da = New SqlDataAdapter(sqlcmd, con)
            Dim ds = New DataSet()
            da.Fill(ds)
            Gridview1.DataSource = ds
            da.Dispose()
            ds.Dispose()
        con.Close()
    End Using
    GenTables(gen)
    Dbind()

I have html markup in the both columns that I need to show up.

Here is my Gridview:

      <asp:GridView ID="GridView1" runat="server" 
        EmptyDataText="There are no data records to display." 
          BackColor="White" BorderColor="#999999" BorderWidth="1px" 
        CellPadding="3" ForeColor="Black" GridLines="Vertical" BorderStyle="Solid" 
        Visible="False" AutoGenerateEditButton="True">
        <AlternatingRowStyle BackColor="#CCCCCC" />
        <Columns>
        </Columns>
        <FooterStyle BackColor="#CCCCCC" />
        <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#999999" ForeColor="Black" 
            HorizontalAlign="Center" />
        <SelectedRowStyle BackColor="#000099" ForeColor="White" Font-Bold="True" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#808080" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#383838" />
    </asp:GridView>

Does anyone have any idea how to allow the gridview cell to show html after the columns have already been generated?

Thanks, Zach

Nefariis
  • 3,451
  • 10
  • 34
  • 52

2 Answers2

0

You can use the OnPreRender event of the grid to achieve this I believe.

Manoj De Mel
  • 927
  • 9
  • 16
0

I swear I saw someone answer this with the correct answer (Im just not sure why they would delete their answer).

For all of those people looking for the same answer, here it is:

    Try
        For x = 0 To GridView5.Rows.Count
            GridView5.Rows(x).Cells(2).Text = Context.Server.HtmlDecode(GridView5.Rows(x).Cells(2).Text)
        Next
    Catch ex As Exception
    End Try

Its as simple as that...

Nefariis
  • 3,451
  • 10
  • 34
  • 52