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
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.
<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.
24 comments:
Can you clarify what you mean by "declare a xml string" and "call the list.Fields.AddFieldAsXml(“xml string”);"?
I don't understand where you put this information.
Declare a string variable and assign the above said xml string then pass the string variable to the function.
I usually keep this kind of string declaration in a resource file as string resource and use it in code.
Murugan G.
what do you mean with: Include this as a first column in your custom list’s view. You are done.
just create a column
what do you mean with: Include this as a first column in your custom list’s view. You are done.
normal column creation?
aru,
not in the column creation. after creating the column as explained in the article using xml, go the view(all items) editing/creating page and include the newly added column as first column, so that it will appear, when you are viewing all items, it display the checkbox in the first column.
but how can i check condition of these checkboxes in the column ?
Hi,
i want buuton check all same user, and i want know how to process check all
Hi all,
I have found on many many blog site for this problem. And get a deadly solution with no way out!!!
Great article, I have learned a great deal from stepping through your solution. I am currently trying to implement the "Select All" button that operates on the title bar of the newly created field. If you can provide any insight into how we can accomplish this it would be greatly appreciated.
Thank You
Hi,
This post was really very helpful , which solved one of my issue.
Can U please let me know how to fetch checked/selected checkboxes programatically in a webpart.
That would be of great help if u can post some code sample.
Great Article.
Thanks.
Hi Murugan,
Where do i paste "..HTML..CDATA..input id="checkboxID"... " when i export schema.xml from existing list?
When i add this to ViewBody>tag in schema.xml checkbox appere always when i add any of column(text, number, date,...) to list.
And then how i reach this checkbox in code from SPList, SPListItem or other object?
Can you show me piece of code?
hi,
i was succefully added check box control to my List.when i was trying to edit the item iam getting following error:
One or more field types are not installed properly. Go to the list settings page to delete these fields
How to access selected items?
i just want to access selected items in that listview webpart for not to update the same list.
j
Hello,
i'm very new to sharepoint but your solution is exact the thing i'm looking for.
But i don't know how to realize it. Maybe can you give me some tips on how to implement this.
I understand that i have to create the checkboxes with your xml but don't know then where to add the call list.Fields.AddFieldAsXml(“xml string”); and what i have to put in for "xml string".
Please can you help me.
regards Mike
I appreciate your article. The only thing that I would recommend is to use ReadOnly="FALSE" and to add ShowInNewForm="FALSE" ShowInViewForm="FALSE" ShowInEditForm="FALSE". The reason I suggest this is because when I tried to remove it because of some other problems I had, I received an error indicating that I couldn't delete a readonly field. Rather than writing code to update the entire schema xml again, it was easier to add these settings and use the field delete method.
i have a custom list and i want to put a check box for each of the item and if i check the box then the item sholud open in a new window and by default in same window.. please help
even after setting ReadOnly="FALSE" and adding ShowInNewForm="FALSE" ShowInViewForm="FALSE" ShowInEditForm="FALSE" the field can not be deleted. While deleting the field, it throws error that one or more fields are not installed properly.
Great !!!
keep it up...
Sukumar Jena
www.objectfrontier.com
Can you please clarify where should we declare xml variable and put the code ?
Post a Comment