I’m working on a WSS 3 site that has a ListViewWebpart displaying various columns.
I need to add a checkbox to each row and a button to the header that will perform a server side action for the selected rows.
Do I need to make my own custom webpart or can the ListViewWebpart support checkboxes?
Adding checkboxes to each row
I’ve found a post Checkbox in ListViewWebpart which suggests
…to add a checkbox, to select multiple
listitem, in the custom list, declare
a xml string as follows.
<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.
I’m assuming the latter part requires a SPList. E.g.
SPList list = SPContext.Current.Web.Lists["MyList"];
list.Fields.AddFieldAsXml(stringWithXmlFieldDefinition);
Adding a button to the header row
One option for the header button is a CustomAction. This should create a button in the toolbar.
Here is a post to create a custom web part, then you can add a check box to your custom web part using the post you have found (Checkbox in ListViewWebpart).
Be aware that,
list.Fields.AddFieldAsXml(stringWithXmlFieldDefinition);can end up adding many duplicated check boxes to you sharepoint. The duplicated can be deleted from database and are located at AllLists table, tp_Fields column.To find the right fields, you can search by the list guid.
then, update the fields
You can simply add a button by
but possibly you need create another toolbar to hold the button, you can even create your own toolbar. You just need to put it in
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES\YourCutomToolBar.ascx