Show groups for current user in DVDropDownList

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" />

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" />

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s