0
votes

I have a SharePoint list with Roles as the columns(Admin, Viewer, Manager) and Document Types as the items (Word docs, PPtx docs, excel docs). I have filled in the corresponding values with the permissions each Role has per Doc Type.

I have built a web part with 2 dropdowns. Dropdown1 has Roles and Dropdown2 has Doc Types.

How can I use the selected value for each dropdown and query the corresponding value from the list?

Do I use CAML or can I use SharePoint object model?

using (SPSite siteCol = new SPSite("http://mySharepoint/"))
{
    using (SPWeb web = siteCol.RootWeb)
    {
        SPList list = web.GetList("/Lists/PermissionMatrix");

        SPListItem item = list.GetItemByIdSelectedFields([*Requires ID*], "Role");

        String role1= (String)item["Roles"];
    }
}

Doesn't work because I have to use the Item ID and I could only query the item using CAML

Please help. Thanks

1

1 Answers

0
votes

There are several technologies and concepts given in SharePoint 2010. First of all is using SPQuery in conjunction with an CAML Query to ask for listitems matching the given conditions. For an example you should have a look at MSDN (http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.aspx).

This short sample is looking for all completed items with an ListItem id larger than 20.

var sampleQuery = new SPQuery();
sampleQuery.Query = @"<Where>
     <And>
       <FieldRef Name='Status' />
       <Value Type='Text'>Completed</Value>
     </And>
     <Gt>
       <FieldRef Name='Id' />
       <Value Type='Number'>20</Value>
     </Gt>
   </Where>";
var foundItems = list.GetItems(sampleQuery);

As also mentioned within the MSDN article you can use LINQ 2 SharePoint in order to generate strongly typed model classes based on the structure given within your SharePoint site.