Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

Why dont you use a hyperlink?

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

  this.Controls.Add(hyperlink);

http://msdn.microsoft.com/en-us/library/system.windows.documents.hyperlink.aspx

or

linbutton

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton(v=vs.80).aspx

EDIT

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"]);
            this.Controls.Add(hyperlink);
        }

hope it helps :)

share|improve this answer
    
so how do i make new uri to take the value from my column Links that i have in min list? –  Martin 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 Sharepoint Jan 22 '13 at 21:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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