tags:

views:

1413

answers:

3

Hi Everybody,

I have created a custom field type as it is there in sharepoint OOTB, the difference is only that the end user does not need to check the name i.e I have replaced it with DropDownList. The dropdownlist suggest the no. of users available in the web site for that I have created a FieldClass which inherits from SPFieldUser and a FieldControlClass which inherits from UserField. It is working fine in all conditions i.e when I create a List or Document Libarary it shows me the DropDownList with respective users after saying OK it creates an item for me. I have overriden a Value property in FieldControlClass as follows,

public override object Value

{

    get
    {
        SPUserCollection userscollection = rootWeb.SiteUsers;
        //ddlInfoBox is a DropDownList to which I have Binded the collection of users in the form of string
        SPUser user = userscollection.Web.EnsureUser(this.ddlInfoBox.SelectedValue);
        SPFieldUserValue userval = new SPFieldUserValue(user.ParentWeb, user.ID, user.LoginName);

        return userval;
    }

    set
    {
        SPFieldUserValue userval = (SPFieldUserValue) this.ItemFieldValue;        
        this.ddlInfoBox.SelectedValue = userval.Lookupvalue;  //Here look up value is nothing but a Login name e.g In-Wai-Svr2\tjagtap
    }
}

Due to above property the Custom Field's Value for this current ListItem will be stored as SPFieldUserValue e.g 27#;In-Wai-Svr2\tjagtap.

The main problem is here, when this particular ListItem is shown in the list page views e.g on AllItems.aspx or the custom view pages associated with it, it shows the number as 27 as a FieldValue insted of HyperLink with text as "In-Wai-Svr2\tjagtap" and PostBackURL as "/_layouts/userdisp.aspx?ID=27".

When I edit this Item it makes the respective value selected in the dropdownlist, also while viewing this item i.e on DispForm.aspx it also shows the hyperlink. I have acheived it by writting a custom logic in createchildcontrol() method i.e by using ControlMode if it is New or Edit then fill the dropdown list, if it is Display then get the ItemFieldValue Type Cast it into SPFieldUserValue and get corresponding lookupid and value for making the URL and showing Text of the HyperLink.

I have spent a lot of time on searching and bringing the HyperLink as the user name with navigation insted of UserID (27) as a string on the list view pages e.g AllItem.aspx but to no avail, then after a lot of research I found that there might be a way of achieving such kind of functionality by using field type definition xml file where there is a provision to define a DisplayPatteren as you wish by specifying the html code. But here is a problem How can I get the UserID (27) with respective UserName e.g In-Wai-Svr2\tjagtap inorder to make an anchor tag like In-Wai-Svr2\tjagtap which will solve my problem. I have hard coded this anchor tag within the Default case statement of a switch under DisplayPatteren but it shows me the field value on AllItems.aspx as In-Wai-Svr2\tjagtap27 i.e the value defined in xml file is concatenating with the string value (27).

Please help me to resolve the above mentioned 2 issue. I am really in need of solving this problem ASAP.

Thanks & Regards, Tejas Jagtap

A: 

Have u tried to override the GetFieldValueAsHtml() method in the the custom field class or maybe the RenderFieldForDisplay() method in the custom field control class.

Johan Leino
A: 

Yes Johan,

I tried both but did'nt work either. I have used GetFieldValueAsHtml() for returning the HTML code in the form of string. Whatever comes in the value object I have type casted it to SPFieldUserValue then I fetched value and made HTML string to be return but when I have attached process to w3wp.exe this method never get called, I don't know why it is so or I am missing something. Also I did same for RenderFieldForDisplay() in FieldClassControl but to no avail. The first one I have tried in FieldClass.

Please help me in this regard. I was trying to e mail you but I did'nt find e mail id on your live blog. If anything I am missing please let me know.

Thanks, Tejas jagtap

Tejas
Please reply to answers by adding a comment to the answer.
Jeremy Stein
A: 

Can you use the DisplayPattern CAML from the User field type?