Link to home
Start Free TrialLog in
Avatar of mking777
mking777

asked on

Need Help with Visual Web Developer Gridview Hyperlink problem

I am a beginner and I am using Visual Web Developer to create a website. In it, I have an Access DB in which I have a column of URLs for websites. I am using a GridView to show the data from the DB that comes from the AccessDataSource connecting to the DB. The GridView column is a hyperlink column and it lists the URLs as hyperlinks but when I click on them, it looks for them as is they are a page in the current project that I am creating( like http://www.mysite.com/www.cnn.com)   All of the websites are external websites, like www.cnn.com.

How do I set up the GridView to have the hyperlinks take me to the external sites?

Thanks for your help with this!!

Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

add link like that

<a href='<%# DataBinder.Eval(Container.DataItem, "link")%>' target="_blank">
                        <%# DataBinder.Eval(Container.DataItem, "title")%></a>
Avatar of mking777
mking777

ASKER

Where/how whould I put that in this section?
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" Width="261px" PageSize="7">
                <Columns>
                    <asp:HyperLinkField DataTextField="URL" DataNavigateUrlFields="URL" HeaderText="BANKRUPTCY" />
                </Columns>
            </asp:GridView>
            <br />

Open in new window

<Columns>
                <asp:TemplateField HeaderText="BANKRUPTCY">
                    <ItemTemplate>
                    <%#Container.DataItem %>
                   <a href='<%# DataBinder.Eval(Container.DataItem, "URL")%>' target="_blank">
                        <%# DataBinder.Eval(Container.DataItem, "URL")%></a>
                    </ItemTemplate>
                </asp:TemplateField>
             
            </Columns>
Thanks but all it now shows is "System.Data.DataRowView " in the GridView. Any suggestions?
Are Your urls starting with http://

or just www
Just www. Should I change it to also have http:// ?
yes change to http://www.bbc.co.uk something like that
you can change in your table or you can try below i have embeded http:// in code
  <ItemTemplate>
                        <a href= <%# "http://"+ Eval( "ProductName")%> target="_blank">
                            <%# DataBinder.Eval(Container.DataItem, "ProductName")%></a>
                    </ItemTemplate>
SOLUTION
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
could you please post your code
Your solution worked. THANKS. I AWARDED YOU THE POINTS!!!
Thanks but you should have accepted the solution by hiting Green Solution Accepted button  not by closing the question.
anyway glad your problem is resolved
Happy Coding :)