...

View Full Version : Two database fields in one datagrid column



vinyl-junkie
02-25-2006, 05:52 PM
I have a HyperlinkColumn that right now only displays one database field (Artist) on my web page but I would like for it to display two database fields (The and Artist). I have found documentation for formatting a single field, but I can't find anything that will take in two fields. Is this even possible? If so, could you post some sample code for how to do that.

Here is the code I'm using right now:


<asp:HyperLinkColumn
DataNavigateUrlField="ArtistID"
DataNavigateUrlFormatString="MusicDBSearch.aspx?ArtistID={0}"
DataTextField="Artist" HeaderText="Artist"
ItemStyle-Width="38%">
<HeaderStyle CssClass="row2left"></HeaderStyle>
</asp:HyperLinkColumn>
So, for example, the link value currently says Corrs, and the link itself will be:
MusicDBSearch.aspx?ArtistID=74.

What I would like for the link value to say is The Corrs, but I only want the The database field to be displayed if it's populated. Does that make sense?

FWIW, I did find some documentation for ASP.NET 2.0 that would take in two fields for the URL of the HyperlinkColumn, but apparently you can't do the same thing on the HeaderTextField. I'm still using ASP.NET 1.1 but will soon be on 2.0, if that makes any difference.

In any event, whatever help you can provide would be appreciated.

Brandoe85
02-26-2006, 07:36 AM
Just to see if i'm on the right track, so correct me if i'm wrong. You want to display a field in your database called "the", or you want to display the text "the"?

Either way, have you looked into using template columns?

Good luck;

vinyl-junkie
02-27-2006, 02:07 AM
Just to see if i'm on the right track, so correct me if i'm wrong. You want to display a field in your database called "the", or you want to display the text "the"?
I want to display a field in my database called "the"


Either way, have you looked into using template columns?

Not until you mentioned it. I'm still pretty new to .NET. :)

Well, I converted it to a template column in Visual Studio, and here's what I came up with, which by the way, works like a charm. Thanks for the help!



<asp:TemplateColumn HeaderText="Artist">
<HeaderStyle CssClass="row2left"></HeaderStyle>
<ItemTemplate>
<asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.The", "{0}") & " " & DataBinder.Eval(Container, "DataItem.Artist", "{0}") %>' NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.ArtistID", "MusicDBSearch.aspx?ArtistID={0}") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>

Brandoe85
02-27-2006, 03:27 AM
Glad to hear you got it! :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum