Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts

    Two database fields in one datagrid column

    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:

    Code:
    <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.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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;

  • #3
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,092
    Thanks
    2
    Thanked 23 Times in 23 Posts
    Quote Originally Posted by Brandoe85
    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!

    Code:
    <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>
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Glad to hear you got it!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •