I have an Webpart there i save some values and that also saves an link to an splist.

In an another webpart in what to display the link in an label but the label dont show as an link it only show like text,so my question is should i use an label to display an link. enter image description here


Why dont you use a hyperlink?

  HyperLinkField hyperlink = new HyperLinkField();
  hyperlink.HeaderText = "HyperLink";
  hyperlink.NavigateUrl = new Uri("http://www.google.com");







Im not on my work pc with sharpeoint to test any code and doing so on notepad so please bare with me if the code is slightly wrong ;)

SPSite site = SPContext.Current.Site;

SPWeb web = site.OpenWeb()

        SPList list = web.Lists["MyList"];
        SPListItemCollection items = list.Items;

        foreach (SPListItem item in items)
            HyperLinkField hyperlink = new HyperLinkField();
            hyperlink.HeaderText = item["Column Name For URL Title"];
            hyperlink.NavigateUrl = new Uri(item["Column Name For URL"]);

hope it helps :)

| improve this answer | |
  • so how do i make new uri to take the value from my column Links that i have in min list? – Batistuta Jan 22 '13 at 20:31
  • ok iv updated the answer im not sure if its 100% right but give it a try and let me know how it goes, It should be correct. You just need to update you list name and the column names one for the hyperlink name to display and one for the url column :) – Ali Jafer Jan 22 '13 at 21:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.