显示CAML查询结果?

时间:2011-11-17 09:57:20

标签: c#-4.0 sharepoint-2010 caml

我正在尝试基于条件if语句执行CAML查询。因此,如果在这种情况下“xapthresult”中的变量等于“BT ADSL”,则将执行查询。以下是代码片段:

//Executing the correct query based on a if condition for BT ADSL
if(xpathresult == "BT ADSL")
{

//Creating the CAML query to perfomr the query on the list to find the required values
SPQuery query = new SPQuery();


//try to find items in this list that matches the result of the XPATH query performed
//earlier
//in this case "BT/Standard"
string camlquery = @"<Query>
<Where>
<Eq>
<FieldRef Name='Vendor_x0020_Product_x0020_Name'/>
<Value Type='Text'>" + xpathresultBTADSL + @"</Value>
</Eq>
</Where>  
</Query>";

query.Query = camlquery;
query.ViewFields = "<FieldRef Name='Fabric_x0020_Name'/>
<FieldRefName='Defined_x0020_For/><FieldRef name='MPLS'/>"; 
//selecting only the required fields from the CAML query

SPListItemCollection listItemCollection = list.GetItems(query);


}

我想知道如何在webpart中显示查询结果!

非常感谢任何帮助,

由于

1 个答案:

答案 0 :(得分:1)

您可以使用SPGridView控件。