Combine string and variable?

Results 1 to 4 of 4

Thread: Combine string and variable?

  1. #1

    Default Combine string and variable?

    I've never programmed in C# and I've also never programmed in .NET. However, we're working on a new site that utilizes both of these. After looking at some of the code, I'm starting to understand some of it better now, but I have a fairly basic question.

    One of our pages is listing buttons using this code:

    <asp:HyperLink ID="ManufacturerLink" runat="server"  Text='<%#Eval("Name")%>' NavigateUrl='<%#Eval("ManufacturerID")%>'></asp:HyperLink>
    It works fine, except that the Navigation URL is currently being set to the ID and nothing else. I need to add the string portion of the link, but cannot figure out how to do that.

    This sort of worked, but I lost my ID:

    <asp:HyperLink ID="ManufacturerLink" runat="server"  Text='<%#Eval("Name")%>' NavigateUrl='~/page.aspx?ID=<%#Eval("ManufacturerID")%>'></asp:HyperLink>
    The link then turns into /page.aspx?ID=<%#Eval("ManufacturerID")%> and does not execute the eval script, it just displays it as plain text. I know there's obviously something I'm not doing properly, but I just don't know what it is yet.

    Can anyone tell me how I can write the string for the link, as well as the id that's being pulled from the database, all into one string?

    Also, does anyone have any suggestions on where I should start reading up on my transition from classic asp/vbscript to now working with I literally just started two days ago, so I'm starting from square one right now.


  2. #2


    Found this which seems to work for what I need...

    <asp:HyperLink ID="ManufacturerLink" runat="server"  Text='<%#Eval("Name")%>' NavigateUrl='<%#this.ResolveUrl("~/" + string.Format("page.aspx?ID={0}",Eval("ManufacturerId")))%>'></asp:HyperLink>
    Not sure if that is the best (or correct) way to do it though. Any feedback is appreciated.


  3. #3
    Join Date
    Feb 2009


         NavigateUrl='<&#37;# Eval("StoryID", "StoryBook.aspx?ID={0}") %>'
         Text='<%# Eval(”Title”) %>' 
    I borrowed this from another article to illustrate the point, but Eval has a couple of overloads - this one lets you do the formatting directly.

    I don't think you would need to specify the whole url as your example showed?

    Good article on it:
    Last edited by Ryan6491; 04-02-2009 at 05:59 PM.

  4. #4


    Very cool. I will try that instead.

    Thanks Ryan!


Posting Permissions

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