Make Custom Linkable Column in List using C#

English:
(This articles has already been posted in
www.msd2d.com. Now I post it again in my own blog.)

Whatever list you made, SharePoint will automatically add the first instantly visible column name “Title” (unless you’ve made custom list definition). The “Title” column is special because it has two consecutive column view, one which is linked to Context Menu, and the other one is linked to item URL. (Figure 1)

image002

Figure -1. Title linked to item and edit menu are always created

Its also special because you can’t delete it, but only hiding from list view is possible. May be for a normal situation, where you don’t want to make custom list representation, this behavior is not a problem. But imagine the situation you want to move the context menu into next column in you list or the situation where you want to have custom link in the other column.
As we always say, numerous way to solve this problem. The JavaScript was one of my explored solutions, but today I won’t talk the code in JavaScript (may be for the next tips if you need it). Today, let us use C# which may be then deployed into custom web part.

Web user control or Webpart ?
I am not a good teacher in webpart and I believe there are many webpart’s sample out there. I also don’t want to push you to jump into webpart development. Therefore I will use web user control to solve this problem, which is then included into Sharepoint using SmartPart v2. Building web user control GUI is as easy as drag and drop operation, so for novice Sharepoint developer, it won’t be a problem. The important thing for us is getting experience with Sharepoint list, providing quick and easy solution.

image004

Figure -2. Default list view. Menu context will be moved to next column

Suppose we have a simple List with two column (Title and New Linked Column). Figure-2 shows default view from Sharepoint, and we want to move context menu to the next column.

Starting the experience
First make sure that your Sharepoint has been equipped with SmartPart v.2 (goto http://www.gotdotnet.com ) and create new web application project! This project will demonstrate moving context menu/hyperlink of recent CustomEdit list. (see my other tips)

1. In the new web application project add Web user control class and name it “CustomLink.ascx”.
2. Add SmartPart and Sharepoint reference to your project

image006

Figure -3. Reference to smartpart and sharepoint

3. Open CustomLink.ascx.cs in the editor and add namespace reference to Sharepoint and SmartPart

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using SmartPart;

4. Don’t forget to implement SPWeb of SmartPart.IUserControl
5. Create client side script procedure for Context Menu

myTable += “\n<SCRIPT>\n”;
myTable += “ctx = new ContextInfo();\n”;
myTable += “ctx.listBaseType = 0 ;\n”;

(…….etc…)
myTable +=”</SCRIPT>\n”;

6. Compose the table and Context Menu enabled cell

myTable +=”<TD Class=\”ms-vb-title\” height=\”100%\”>”;
myTable +=”<table height=\”100%\” cellspacing=0 class=\”ms-unselectedtitle\” onmouseover=\”OnItem(this)\” CTXName=\”ctx1\” ItemId=\””+ item.ID.ToString() +”\”>”;
myTable +=”<tr><td width=\”100%\” Class=\”ms-vb\”><a onfocus=\”OnLink(this)\””+ itemURL +”target=\”_self\”>” + ((item[“Editable_x0020_Field”]==null) ? “” : item[“Editable_x0020_Field”].ToString()) + “</a>”;
myTable +=”<td><img src=\”/_layouts/images/blank.gif\” width=13 style=\”visibility: hidden\” alt=\”\”></td>”;
myTable +=”</tr>”;
myTable +=”</table>”;
myTable +=”</TD>”;

7. Override the page rendering to parse-out the new table

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
base.Render (writer);
this.Response.Write(this.RenderListTable());
}

8. Compile, open SmartPart and use its procedure to show the new web user control. (Figure 4).

image008

Figure 4. New placement of context menu as well as hyperlink

What I am showing here is one of many ways costuming the List view. I’ve included a very basic web user control to show you about and giving insight to all of you. The code is not intended for production, because I’ve removed many processing sequence.

About

Riwut Libinuko, experienced Architect. Currently working with Credit Agricole CIB, responsible for SharePoint platform in Asia Pasific. . Certification: SharePoint 2013, SharePoint 2010, SharePoint 2007, ITiL v3

Posted in Microsoft Sharepoint
One comment on “Make Custom Linkable Column in List using C#
  1. download mobile napster ringtones download boost mobile ringtones

    For c139 free motorola ringtones download free tracfone ringtones

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: