Forum Moderators: open

Message Too Old, No Replies

How do you display a hyperlink in a datagrid?

         

IanTurner

12:48 pm on Apr 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



We are looking to display a hyperlink in a datagrid and can't find any examples that show us how to do this.

We are looking to have a column with a value that is itself a hyperlink.

edicius

6:25 pm on Apr 23, 2004 (gmt 0)

10+ Year Member



The best approach I've found is using Template Columns within the datagrid. Be sure to turn "Automatic Column Generation" off. A quick example (only one column to save on post size):


<ASP:DATAGRID id="customers_grid" runat="server" autogeneratecolumns="False">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<A href='?SortBy=CustName' target='_self'>Customer</A>
</HeaderTemplate>
<ItemTemplate>
<A href='<%#"?ACTProg=CustomerList&ID="+ DataBinder.Eval(Container.DataItem, "CustID")%>'><%#DataBinder.Eval(Container.DataItem, "CustName")%></A>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</ASP:DATAGRID>

You'll notice that I've used single quotes within the HTML tags for the links. This is pretty crucial for any of HTML that will include server-side data/calls. Especially in the case of the ItemTemplate above - you would get errors when trying to serve up the page (the double quotes are necessary in the server-side calls).

If you run into any problems/further questions let me know - I learned quite a bit on this topic during my struggles with it last spring. I can sticky you a few good links/resources if you have any interest.

duckhunter

8:10 pm on Apr 23, 2004 (gmt 0)

10+ Year Member



Also, checkout the post here: [webmasterworld.com ] which does the same thing but with an asp:image instead of asp:HyperLink