Sunday, December 9, 2007

Checkbox in ListViewWebpart

When we see the checkbox to select multiple user in People and Groups page, every (new) sharepoint developers wonders how it can be implemented to their custom list. First we will look at how it is implemented in the People and Groups (people.aspx) Page.


The people.aspx page host the UserInfo list as in the following line

<SharePoint:ListView id="UserListView" ListID="UserInfo" runat="server"/>

and the schema for the users list is defined in the schema.xml file in the <12hive>\TEMPLATE\GLOBAL\Lists\USERS folder. The checkbox is implemented as a Computed type column as follows.

<Field ID="{625e82b6-fb2b-4c37-9a45-ba7541f8d139}" Type="Computed" ReadOnly="TRUE" Name="UserSelection" DisplayName="$Resources:userinfo_schema_selectionbox;" Sortable="FALSE" Filterable="FALSE" EnableLookup="FALSE" HeaderImage="unchecka.gif" ClassInfo="Icon" AuthoringInfo="$Resources:userinfo_schema_selectionbox_editinfo;" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="UserSelection">
<FieldRefs>
<FieldRef Name="ID" />
<FieldRef Name="Name" />
<FieldRef Name="EMail" />
<FieldRef Name="SipAddress" />
<FieldRef Name="Title" />
</FieldRefs>
<DisplayPattern><HTML><![CDATA[<input type="checkbox" name="spUserSelectionCheckBox_]]></HTML>
<Counter Type="View" /><HTML><![CDATA[" id="spUserSelCb_]]></HTML>
<Counter Type="View" />
<Column Name="ID" /><HTML><![CDATA[" ]]></HTML><HTML><![CDATA[value="]]></HTML>
<Column Name="ID" HTMLEncode="TRUE" /><HTML><![CDATA[" account="]]></HTML>
<Column Name="Name" HTMLEncode="TRUE" /><HTML><![CDATA[" email="]]></HTML>
<Column Name="EMail" HTMLEncode="TRUE" /><HTML><![CDATA[" ]]></HTML><HTML><![CDATA[sip="]]></HTML>
<Column Name="SipAddress" HTMLEncode="TRUE" /><HTML><![CDATA[" ]]></HTML><HTML><![CDATA[onclick="UserSelectionOnClick(this,']]></HTML>
<Counter Type="View" /><HTML><![CDATA[');" ]]></HTML><HTML><![CDATA[title="]]></HTML>
<Column Name="Title" HTMLEncode="TRUE" /><HTML><![CDATA["/> ]]></HTML>
</DisplayPattern>
</Field>

The DisplayPattern element tells how the column should be rendered when a ListViewWebpart renders a view.

If you have list definition for your custom list you can directly go and modify the schema. When you don’t have schema but you want to achieve the checkbox in your custom list, this where comes the handy AddFieldAsXml of SpFieldCollection type.

So to add a checkbox, to select multiple listitem, in the custom list, declare a xml string as follows. (This is simplified version of DisplayPattern from the userinfo schema)
<Field Type="Computed" ReadOnly="TRUE" Name="ListItemSelection" DisplayName="Select" Sortable="FALSE" Filterable="FALSE" EnableLookup="FALSE" SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="ListItemSelection">
<FieldRefs>
<FieldRef Name="ID" />
</FieldRefs>
<DisplayPattern>
<HTML><![CDATA[<input type="checkbox" ]]></HTML>
<HTML><![CDATA[LItemId="]]></HTML>
<Column Name="ID" HTMLEncode="TRUE" />
<HTML><![CDATA["/> ]]></HTML>
</DisplayPattern>
</Field>

and call the list.Fields.AddFieldAsXml(“xml string”);. Include this as a first column in your custom list’s view. You are done.



Cheers,
Murugan G.

Sunday, December 2, 2007

How do I implement client side warning/error messages in Sharepoint 2007

When you invoke Remove Users from Group menu in the Peoples and Groups (Site Actions -> Site Settings -> Peoples and Groups) without selecting any user the below warning message will be displayed.


How it is implemented. The people.aspx page in the <12hive>\ TEMPLATE\LAYOUTS, contains the following js declaration,

var noUserSelectedMsg = "<SharePoint:EncodedLiteral runat='server' text='<%$Resources:wss,people_nouserselected%>' EncodeMethod='EcmaScriptStringLiteralEncode'/>";

when we request the page the people_nouserselected string resource from wss.en-US.resx resource file is assigned to the noUserSelectedMsg. This variable later used in BtnRemoveUsersClick Js function. The Resources:wsss refers to the wss.en-US.resx file. To refer some other resource file replace the wss with your resource file.

To implement your custom resource file you can create a new assembly with you custom resource file, and keep the resx file in your C:\Inetpub\wwwroot\wss\VirtualDirectories\App_GlobalResources folder. Keep the assembly in the GAC, then declare and use as in the above example.


Cheers ,
Murugan G.

Monday, May 7, 2007

Welcome to Learning sharepoint

Hi,

I am murugan, currenlty working on sharepoint 2007. This blog mostly focusing on learning the sharepoint, in a not confusing way.

I will be posting atelast one blog per week, which mostly as walkthrough, so that most of the user can understand the sharepoint thing.

cheers,
murugan g.