Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to make string as link

Posted on 2013-10-26
2
Medium Priority
?
268 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

618 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