Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a web project which ask user enter an ID then the code behind form a SQL query access Oracle DB and get a data table rending into a Gridview. All this works fine.
My question is In this returned data table there is a field which contain a hyperlink information in text format like(for example)this:
HTML
<a href="https://google.com/maps/search/?api=1&query=32.5523979268129,-80.87412532968123">location in google maps</a>

I want to convert this text to be shown on the web page as a hyperlink so that user can click and redirect to the location.
What should I do in code behind. Please help thanks.

What I have tried:

I tried template it make a duplication of the location field but did not covert to hyperlink.
HTML
<asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
              <asp:TemplateField HeaderText="Google Location" >
                    
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Eval("Location") %>'></asp:Label>
                    </ItemTemplate>
                  <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("Location") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                
            </Columns>
            <FooterStyle BackColor="#CCCC99" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#F7F7DE" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#FBFBF2" />
            <SortedAscendingHeaderStyle BackColor="#848384" />
            <SortedDescendingCellStyle BackColor="#EAEAD3" />
            <SortedDescendingHeaderStyle BackColor="#575357" />
        </asp:GridView>
Posted
Updated 19-Mar-18 9:43am
v5
Comments
Richard Deeming 19-Mar-18 10:52am    
You don't need to do anything in the code-behind. If the Location field is an HTML string, then the <asp:Label> will render it as HTML.
Maciej Los 19-Mar-18 15:52pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900