Tags

, , ,

Recently, it cross my mind the idea of displaying groups for current user in a DVDropDownList. There are solutions which are using SharePoint web services, but I found something easier. Again, membership CAML clause help me.

Following code is an example of an SPDataSource showing information I need.

<SharePoint:SPDataSource runat="server" DataSourceMode="List" ID="GroupsDataSource" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;Where&gt;&lt;Membership Type=&quot;CurrentUserGroups&quot;&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;/Membership&gt;&lt;/Where&gt;&lt;/Query&gt;&lt;/View&gt;" UseInternalName="True">
<SelectParameters><asp:Parameter Name="ListName" DefaultValue="User Information List" />
				</SelectParameters>
</SharePoint:SPDataSource>

To be more clear, I placed below decoded CAML:

<View><Query><Where><Membership Type="CurrentUserGroups"><FieldRef Name="ID"/></Membership></Where></Query></View>

The rest is simple. Create a DVDropDownList and bind to this source.

<SharePoint:DVDropDownList runat="server" DataSourceID="GroupsDataSource" DataTextField="Title" DataValueField="Title" />
Advertisements