locked
How to show a string as a hyperlink dynamically? RRS feed

  • Question

  • User344680819 posted

    Let's consider that I have a comma separated string. For example, "APL-1,APL-2,APL-3,APL-4".

    So I want to show each one string with hyperlink and on that it should redirect to some other page.

    Note: The comma separated string may vary (means may increase or decrease) So please guide me how to do this?

    Saturday, September 15, 2012 4:26 AM

Answers

  • User-1438829842 posted

    I've made this code for you.. :)

    string Txt = "APL-1,APL-2,APL-3,APL-4";
            string[] main = Txt.Split(',');
            int lenght = main.Length;
            Response.Write("Its Lenght of your APL : " + lenght + "<br />");
            for (int i = 0; i < lenght; i++)
            {
                string url = "http://your-url.com/" + main[i];
                string good = main[i];
                
                Response.Write(good.Replace(main[i], "<a href='" + url + "'>" + main[i] + "</a><br />"));
            }

    Output:

    Its Lenght of your APL : 4
    APL-1
    APL-2
    APL-3
    APL-4


    Good luck`

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 15, 2012 7:02 AM

All replies

  • Saturday, September 15, 2012 6:25 AM
  • User1410450975 posted

    Dwonload the same program which was made by for you help this program create on VS 2008 

    https://skydrive.live.com/#cid=2F22272220E37707&id=2F22272220E37707%21103

    Program name is=RepeaterHyperLink

    Saturday, September 15, 2012 6:36 AM
  • User-1438829842 posted

    I've made this code for you.. :)

    string Txt = "APL-1,APL-2,APL-3,APL-4";
            string[] main = Txt.Split(',');
            int lenght = main.Length;
            Response.Write("Its Lenght of your APL : " + lenght + "<br />");
            for (int i = 0; i < lenght; i++)
            {
                string url = "http://your-url.com/" + main[i];
                string good = main[i];
                
                Response.Write(good.Replace(main[i], "<a href='" + url + "'>" + main[i] + "</a><br />"));
            }

    Output:

    Its Lenght of your APL : 4
    APL-1
    APL-2
    APL-3
    APL-4


    Good luck`

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, September 15, 2012 7:02 AM
  • User-1360095595 posted
    A couple of ways. First split the string so you get the array of strings. You can then either use a data control like datalist/repeater/gridview and bind a hyperlink's URL; or you can iterate through the string array and create dynamic hyperlink controls.
    Saturday, September 15, 2012 7:29 AM