Sharepoint SPQuery
-
For instance, let us take a State List which holds all the states of India. States are grouped under different zones i.e. North, South, East & West. If I need to retrieve all the States for North zone then my SP Query would look somewhat like, SPQuery stateQuery = new SPQuery(); stateQuery.Query = "<Where><Eq><FieldRef Name=\"Zone\"/><Value Type=\"Text\">North</Value></Eq></Where>"; SPListItemCollection stateCol = StateList.GetItems(stateQuery); In the code above the StateCollection object gets populated with the States only related to North zone. You can then bind this collection to a GridView or DataList or any other similar controls to view the actual values. Note: - Each tag must be properly ended / closed. - Eq stands for Equal. One cab also use NEq for not equal conditions. - FieldRef holds the column name on which we want to run the query. In our case it is Zone. - Value holds the parameter for the query column. In our case it is North. - Can use / surround column name with / tags to have the corresponding NULL condition checks. http://www.mindfiresolutions.com/Sharepoint-SPQuery-30.php[^]
Cheers, Eliza