Adding a SharePoint List Item URL to a grid view

Posted: 22nd August 2012 in ASP.NET, SharePoint

Okay, I’ve not blogged for sometime. So here a quick one just as a memory jogger for myself.

I needed to add a SharePoint URL field to a GridView to display data from a SP link list.  Here’s how i did it.

Code Snippet
  1. <asp:TemplateField>
  2.                         <HeaderTemplate>
  3.                           Title
  4.                         </HeaderTemplate>
  5.                         <ItemTemplate>
  6.                             <asp:Hyperlink NavigateUrl='<%#DataBinder.Eval(Container.DataItem, "URL").ToString().Split(new string[] {", "}, StringSplitOptions.RemoveEmptyEntries)[0]%>' Text='<%#DataBinder.Eval(Container.DataItem, "URL").ToString().Split(new string[] {", "}, StringSplitOptions.RemoveEmptyEntries)[1]%>' runat="server"></asp:Hyperlink>
  7.                         </ItemTemplate>
  8.                     </asp:TemplateField>

I know its not rocket science and there’s probably a better way to do it, but a least I won’t have to trawl through Google again to find the answer.

More to come soon. Need to get back into blogging…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s