Solved

how to make string as link

Posted on 2013-10-26
2
254 Views
Last Modified: 2013-10-30
hi i have one string like this:

Dim vstr as string = "trees, cars, houses"

i want some function that conver this to this.

<a href="/category.aspx?c=trees">trees</a><a href="/category.aspx?c=cars">cars</a><a href="/category.aspx?c=houses">houses</a>

so this way i can read and call the funcion inside aspx page.
0
Comment
Question by:rafaelrgl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39602739
.Net is not my strong area but try this

Dim vstr as string = "trees, cars, houses"

Dim words as string = vstr.Split(',');

Dim item as string

For Each item In words
	Response.write '<a href="/category.aspx?c=" & item & '">' & item & '</a>'
Next

Open in new window

0
 
LVL 15

Expert Comment

by:pateljitu
ID: 39606081
Have provided with 2 different output example, one does response.write to <a href> tab and another one take .NET approach and binds data to repeater.

// CODE BEHIND .cs file
protected void Page_Load(object sender, EventArgs e)
        {
            // Output to <A HREF> tag
            System.Text.StringBuilder abc = createHrefSample1("trees, cars, houses");
            Response.Write(abc.ToString());


            // Output to Repeater
            System.Data.DataTable pDT = new System.Data.DataTable();
            pDT = createHrefSample2("trees, cars, houses");

            Repeater1.DataSource = pDT;
            Repeater1.DataBind();
        }

        private System.Text.StringBuilder createHrefSample1(string sCategory)
        {
            System.Text.StringBuilder sLinkCategory = new System.Text.StringBuilder();
            string[] SCategory = sCategory.Split(',');

            foreach (string element in SCategory)
            {
                sLinkCategory.Append("<a href='/category.aspx?c=" + element.ToString().Trim() + "'>" + element.ToString().Trim() + "</a>");
            }

            return sLinkCategory;
        }

        public System.Data.DataTable createHrefSample2(string sCategory)
        {
            System.Text.StringBuilder sLinkCategory = new System.Text.StringBuilder();
            string[] SCategory = sCategory.Split(',');
            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("sCategory");

            foreach (string element in SCategory)
            {
                dt.Rows.Add(element.ToString().Trim());
            }

            return dt;
        }

Open in new window


.ASPx page
<asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <asp:HyperLink ID='HLCategory' runat="server" NavigateUrl='<%#Eval("sCategory","/category.aspx?c={0}")%>'><%#Eval("sCategory")%></asp:HyperLink><br />

        </ItemTemplate>
    </asp:Repeater>

Open in new window

0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP and Looping Thru a XML Document 4 33
Read text on Table 7 30
Calculating percentage 2 31
calculate days away 11 29
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question