Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Asp.net hyperlink anchor text

Status
Not open for further replies.

nichols

Technical User
May 24, 2001
92
GB
I am trying to show a hyperlink from field in a sql database with the anchor text from another field how can i do this?

eg
database field_url = database filed_text =testtext

I wan to be able to display the anchor text 'testtext' which will navigate to the testurl.aspx in a gridview. currently I can only get it to display and the 'testtext' field alongside.

I hope someone can help?
 
Code:
<script runat="server">

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub

    Protected Sub GridView1_SelectedIndexChanged1(ByVal sender As Object, ByVal e As System.EventArgs)

    End Sub
</script>

<style type="text/css" media="all">
@import "css/styles.css";
</style>
<link href="css/styles.css" rel="stylesheet" type="text/css" />
   <form id="form1" runat="server">
  	
   	<div>           
               <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="<%$ ConnectionStrings:groupitConnectionString4 %>" 
                    
                    SelectCommand="SELECT [fizz_graphic_2], [fizz_headline_2], [fizz_text_2], [fizz_url_2] FROM [homepage]">
                </asp:SqlDataSource>
                <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" 
                    AutoGenerateColumns="False">
                    <Columns>
                        <asp:TemplateField InsertVisible="False" ShowHeader="False">
                            <ItemTemplate>
                                <asp:Image ID="Image1" runat="server" 
                                    ImageUrl='<%# Eval("fizz_graphic_2") %>' />
                                <asp:Label ID="Label1" runat="server" Text='<%# Eval("fizz_headline_2") %>'></asp:Label>
                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("fizz_text_2") %>'></asp:Label>
                              [COLOR=red]  <asp:HyperLink ID="HyperLink1" runat="server" 
                                    NavigateUrl='<%# Eval("fizz_url_2") %>'>HyperLink</asp:HyperLink>[/color red]
                            </ItemTemplate>
                            <ControlStyle BackColor="White" BorderColor="White" BorderStyle="None" 
                                BorderWidth="0px" />
                            <FooterStyle BackColor="White" BorderColor="White" BorderStyle="None" 
                                BorderWidth="0px" />
                            <HeaderStyle BackColor="White" BorderColor="White" BorderStyle="None" 
                                BorderWidth="0px" />
                            <ItemStyle Height="50px" VerticalAlign="Top" Width="100%" />
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>            
    </div>
   </form>

I want to display ("fizz_headline_2") as the anchor text to ("fizz_url_2").

Hope this helps some?
 
Personally, I would do this in the code behind, not the HTML.
In the RowDataBound event, you just would use FindControl() to get a reference to your Hyperlink. Then you would set the NavigateURL property, and the Text property.

To keep in line with your way of doing it, you can try this:
Code:
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("fizz_url_2") %'>[blue]Text='<%# Eval("fizz_headline_2") %'>[/blue]</asp:HyperLink>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top