dcsimg
Results 1 to 2 of 2

Thread: [RESOLVED] Show HTML from SQL Cell in AutoGeneratedColumns

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Seattle
    Posts
    218

    Resolved [RESOLVED] Show HTML from SQL Cell in AutoGeneratedColumns

    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:

    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:

    Code:
            <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 been generated?

    Thanks,
    Zach

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Sep 2011
    Location
    Seattle
    Posts
    218

    Re: Show HTML from SQL Cell in AutoGeneratedColumns

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

    Code:
        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...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width