Mask HyerlinkField with short name

Last post 05-12-2008 3:58 AM by Hughesie11. 11 replies.

Sort Posts:

  • Mask HyerlinkField with short name

    05-08-2008, 12:28 PM
    • Loading...
    • Hughesie11
    • Joined on 10-10-2007, 1:22 PM
    • Posts 64
     
    I have a datagrid, which is written to programatically, I want to populate one of the fields as URL, howevere the url's are quite long, so i just want to mask them all with the word "link", any ideas how i can do this?
    here is my code:

    <asp:HyperLinkField DataTextField="location" DataNavigateUrlFields=location HeaderText="Link" />

    also, the link will work fine for URL's but then the value is a file directory it replaces the beginnig with the localhost address e.g

    this link works fine when i open manually http://domain.company.net//download/word_doc.doc

    but when opened as hyperlink through code above it comes out as http://localhost/Website/%20http://domain.company.net//download/word_doc.doc

     

    any ideas on both?

  • Re: Mask HyerlinkField with short name

    05-08-2008, 3:50 PM
    • Loading...
    • lberan
    • Joined on 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 235

    change this line:

    <asp:HyperLinkField DataTextField="location" DataNavigateUrlFields=location HeaderText="Link" />

    to:

    <asp:HyperLinkField DataTextField="location"  Text="Link"  DataNavigateUrlFields="location"  DataNavigateUrlFormatString="{0}" headerText="Link" />
    Lynn

    Please remember to click "Mark as Answer" on the post to all the replies that have helped you so that these answers could help others. Thanks.
  • Re: Mask HyerlinkField with short name

    05-09-2008, 4:12 AM
    • Loading...
    • Hughesie11
    • Joined on 10-10-2007, 1:22 PM
    • Posts 64
    Hi,
     
    Im afraid that still doesnt work, it is still showing up my link as http://domain.company.net//download/word_doc.doc  and not simply the word 'Link', it does show 'link' when there is actually no value in the Location field, but for records that do a value is still displays the whole URL.

     

  • Re: Mask HyerlinkField with short name

    05-09-2008, 9:38 AM
    • Loading...
    • lberan
    • Joined on 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 235

    delete this attribute:  DataTextField="location" 

    Lynn

    Please remember to click "Mark as Answer" on the post to all the replies that have helped you so that these answers could help others. Thanks.
  • Re: Mask HyerlinkField with short name

    05-09-2008, 10:27 AM
    • Loading...
    • Hughesie11
    • Joined on 10-10-2007, 1:22 PM
    • Posts 64
    excellent! thank you that worked.
    I have one more question, some of my links are to webt pages, they work fine, however some are to documents sitting on other servers/pcs

    the link works fine when i open manually http://domain.company.net//download/word_doc.doc

    but when opened as hyperlink through code above it comes out as http://localhost/Website/%20http://domain.company.net//download/word_doc.doc

     

    any ideas as to why this happens.?

  • Re: Mask HyerlinkField with short name

    05-09-2008, 11:22 AM
    • Loading...
    • lberan
    • Joined on 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 235
    in your web.config file, there is a line like this

    <sessionState cookieless="true" />

    chang it to

    <sessionState cookieless="false"  />

     

    Lynn

    Please remember to click "Mark as Answer" on the post to all the replies that have helped you so that these answers could help others. Thanks.
  • Re: Mask HyerlinkField with short name

    05-09-2008, 11:41 AM
    • Loading...
    • Hughesie11
    • Joined on 10-10-2007, 1:22 PM
    • Posts 64

    hi tried that, still no success, the session state was expilicity set in my web.config I had to put the line in manually

    this is the link its trying to access, i need to get rid of  http://localhost/website/%20http

    http://localhost/website/%20http://domain.net//download/RP_FV.doc%20

     

     

  • Re: Mask HyerlinkField with short name

    05-09-2008, 11:48 AM
    • Loading...
    • lberan
    • Joined on 02-12-2008, 7:23 PM
    • Pittsburgh, PA
    • Posts 235

    the bound value has problem.  you need to change the configuration of your datasource to get the correct value for the Id.  if you use sqldatasource, you could run your query in a query window to see the result.

    Lynn

    Please remember to click "Mark as Answer" on the post to all the replies that have helped you so that these answers could help others. Thanks.
  • Re: Mask HyerlinkField with short name

    05-09-2008, 11:54 AM
    • Loading...
    • JAllen404
    • Joined on 08-02-2006, 9:55 PM
    • Posts 18

     I see two problems.  First of all the spaces (which get translated to %20) and especially the one at the end of the link.

    Also, it's coming up as local host before the actual URL.  Wherever you're getting the link info from (I suspect a database but it could have been from dragging and dropping in design view too) has the wrong info in it.

    If you're getting the info from a database you'll need to check the record in the DB.  If the URL is hard coded into the page you'll have to  look at the source view and manually make the URL start at the "http://"

    -JA


    Don't forget to mark "Answer" if this post solves the problem.
  • Re: Mask HyerlinkField with short name

    05-09-2008, 11:59 AM
    • Loading...
    • Hughesie11
    • Joined on 10-10-2007, 1:22 PM
    • Posts 64

    hi my data souce is an XML doc, it populates a data grid on page load, so basiucally i want to be able ot edit/update records. i load them to a dataset.,

  • Re: Mask HyerlinkField with short name

    05-09-2008, 12:44 PM
    • Loading...
    • JAllen404
    • Joined on 08-02-2006, 9:55 PM
    • Posts 18

    Well then you need to look at your XML document.  The links themselves are getting  "http://localhost/Website/%20" from your datasource unless you are having it prepend (yes, I just made up an antonym for append) it in the codebehind somewhere.

    Look at where the link is created in your source (it's possible you have that localhost part in the actual hyperlink markup itself).
    Look in your databind statement in your code behind page.
    Look in your datasource at the record itself.

    If you can't find it, post all three of those. 

    -JA 


    Don't forget to mark "Answer" if this post solves the problem.
  • Re: Mask HyerlinkField with short name

    a few seconds ago
    • Loading...
    • Hughesie11
    • Joined on 10-10-2007, 1:22 PM
    • Posts 64

    my source:
      <Module>
        <name>
          module name
        </name>
        <mediatype>
          DOC
        </mediatype>
        <location>
         http://domain.company.net//download/word_doc.doc
        </location>
      </Module>

    data bind code:

    DataSet ds = new DataSet();
    ds.ReadXml(Request.PhysicalApplicationPath + "App_Data\\Docs\\Modules.xml");
    GridView1.DataSource = ds;
    GridView1.AutoGenerateColumns = false;
    GridView1.DataBind();

Page 1 of 1 (12 items)