concatenate text with a bound value in a gridview field

Discussion in 'ASP .Net' started by smccauslin@comcast.net, Sep 11, 2006.

  1. Guest

    URLs are stored in a database in a form similar to www.mysite.com.
    When the user clicks on the link, it should launch a seperate window
    and go to that site. Here's the code


    <asp:HyperLink
    ID="HyperLink1"
    runat="server"
    NavigateUrl='<%# Bind("URL") %>'
    Text='<%# Bind("URL") %>'
    Target="_blank"
    </asp:HyperLink>

    All of the URLs in the database do not have http:// at the beginning.
    I'd rather do it programmatically so that when new records are added,
    the user does not have to remember to type http:// Is there an easyway
    to code this so it is added at runtime?

    In pseudo-code, I want to accomplish this:

    NavigateUrl='<%# "http://" + Bind("URL") %>'

    so that the data has http:// at the beginning. I'm just not sure how
    to code it and haven't been able to find any examples.

    Any suggestions are welcome! Thanks!
    , Sep 11, 2006
    #1
    1. Advertising

  2. smccaulsin,

    <asp:HyperLink
    ID="HyperLink1"
    runat="server"
    NavigateUrl='<%# Eval("URL", "http://{0}") %>'
    Text='<%# Eval("URL") %>'
    Target="_blank"
    </asp:HyperLink>

    Also... Bind is for 2 way data binding (display and updating), while Eval is
    for display only.

    Regards,

    Rob MacFadyen


    <> wrote in message
    news:...
    > URLs are stored in a database in a form similar to www.mysite.com.
    > When the user clicks on the link, it should launch a seperate window
    > and go to that site. Here's the code
    >
    >
    > <asp:HyperLink
    > ID="HyperLink1"
    > runat="server"
    > NavigateUrl='<%# Bind("URL") %>'
    > Text='<%# Bind("URL") %>'
    > Target="_blank"
    > </asp:HyperLink>
    >
    > All of the URLs in the database do not have http:// at the beginning.
    > I'd rather do it programmatically so that when new records are added,
    > the user does not have to remember to type http:// Is there an easyway
    > to code this so it is added at runtime?
    >
    > In pseudo-code, I want to accomplish this:
    >
    > NavigateUrl='<%# "http://" + Bind("URL") %>'
    >
    > so that the data has http:// at the beginning. I'm just not sure how
    > to code it and haven't been able to find any examples.
    >
    > Any suggestions are welcome! Thanks!
    >
    Rob MacFadyen, Sep 12, 2006
    #2
    1. Advertising

  3. Guest

    Rob,

    Thanks. I knew it would be rather simple. Now I know what I need to
    learn more about.
    Once again, thanks!

    Scott

    Rob MacFadyen wrote:
    > smccaulsin,
    >
    > <asp:HyperLink
    > ID="HyperLink1"
    > runat="server"
    > NavigateUrl='<%# Eval("URL", "http://{0}") %>'
    > Text='<%# Eval("URL") %>'
    > Target="_blank"
    > </asp:HyperLink>
    >
    > Also... Bind is for 2 way data binding (display and updating), while Eval is
    > for display only.
    >
    > Regards,
    >
    > Rob MacFadyen
    >
    >
    > <> wrote in message
    > news:...
    > > URLs are stored in a database in a form similar to www.mysite.com.
    > > When the user clicks on the link, it should launch a seperate window
    > > and go to that site. Here's the code
    > >
    > >
    > > <asp:HyperLink
    > > ID="HyperLink1"
    > > runat="server"
    > > NavigateUrl='<%# Bind("URL") %>'
    > > Text='<%# Bind("URL") %>'
    > > Target="_blank"
    > > </asp:HyperLink>
    > >
    > > All of the URLs in the database do not have http:// at the beginning.
    > > I'd rather do it programmatically so that when new records are added,
    > > the user does not have to remember to type http:// Is there an easyway
    > > to code this so it is added at runtime?
    > >
    > > In pseudo-code, I want to accomplish this:
    > >
    > > NavigateUrl='<%# "http://" + Bind("URL") %>'
    > >
    > > so that the data has http:// at the beginning. I'm just not sure how
    > > to code it and haven't been able to find any examples.
    > >
    > > Any suggestions are welcome! Thanks!
    > >
    , Sep 12, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip Vong
    Replies:
    0
    Views:
    413
    Phillip Vong
    Jul 27, 2006
  2. shapper

    Get GridView Bound Field value

    shapper, Mar 9, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    775
    shapper
    Mar 9, 2007
  3. Guest
    Replies:
    1
    Views:
    621
    Milosz Skalecki [MCAD]
    Dec 6, 2007
  4. jr
    Replies:
    3
    Views:
    414
  5. Carlos

    Concatenate/De-Concatenate

    Carlos, Oct 12, 2012, in forum: VHDL
    Replies:
    10
    Views:
    875
Loading...

Share This Page