-2

Im the following code:

string xpathresultBTADSLMAX = "BT/Max Standard";

if (xpathresult2 == "BT ADSL Max")
{

//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'>" + xpathresultBTADSLMAX + @"</Value>
</Eq>
</Where>  
</Query>";

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

SPListItemCollection listItemCollection = list.GetItems(query);


//string fabricName = (string)item["Fabric_x0020_Name"]; commented out temporarily

//string definedFor = (string)item["Defined_x0020_For"]; commented out temporarily

string fabricName = (string)item["Fabric_x0020_Name"];
string definedFor = (string)item["Defined_x0020_For"];

AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(fabricName, definedFor 
));

} 

In the above code I am trying to display specific information from a list item that has a Vendor Produc Name of "BT/Max Standard". The values I want to display are currently "Fabric Name" and "Defined For".

I then want to be able to display them in a asp Place holder by adding a literal control but its simply not working. Is there something that I am doing wrong here? Please provide some suggestion on how to achieve this.

Many Thans in advance!

UPDATED!!!

So I have made some changes to the code, which basically fixed the issue mentioned earlier. I am now ablke to display the results of the CAML query in the asp place holder.

string xpathresultBTADSLMAX = "BT/Max Standard";

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

//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'>" + xpathresultBTADSLMAX + @"</Value>
</Eq>
</Where>  
</Query>";

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

SPListItemCollection listItemCollection = list.GetItems(query);


//string fabricName = (string)item["Fabric_x0020_Name"]; commented out temporarily

//string definedFor = (string)item["Defined_x0020_For"];
//string feniedFor = (string)item["Defined_x0020_For"];



//AvailabilityCheckerResults3.Controls.Add(new LiteralControl(fabricName + " " + 
definedFor));

//AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(fabricName)); 
commented out temporarily

//string fabricName = (string)listItemCollection["Fabric_x0020_Name"].ToString;

/*string fabricName = listItemCollection.ToString();

AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(fabricName));*/



foreach (SPListItem item in listItemCollection)
{
try
{

string results56 = (string)item["Fabric_x0020_Name"] + " " + 
(string)item["Defined_x0020_For"] + " " + "<b>MPLS:</b> " + (string)item["MPLS"] + 
"<br/>" + "<br/>";
AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(results56));
}
catch (Exception err)
{
AvailabilityCheckerResultsTwo.Controls.Add(new LiteralControl(err.ToString()));
}
}

} 

However i now have another problem in that I am getting all reacords from the List, and this is not the intended outcome. Here is the output:

Alpaca A dirty ADSL product for: CCTV third-party remote access interactive models and web site testing MPLS: No

Burnet Home user & SOHO product (<5 user site) Can support <5 VoIP connections with 2 concurrent calls. IPT package MPLS: Yes

The CAML query should only be displaying results for "Alpaca". How can I get only the required item and not all items in the list? Its probably something Im doing wrong!

Many Thanks

Dev P
  • 1,157
  • 5
  • 32
  • 54

2 Answers2

2

never include query tag in syntax try this

 string camlquery = @"<Where><Eq><FieldRef Name='Vendor_x0020_Product_x0020_Name'/>
                      <Value Type='Text'>" + xpathresultBTADSLMAX + @"</Value>
                      </Eq>
                     </Where>";

further details you can see this artical http://rmanimaran.wordpress.com/2011/03/11/new-in-sharepoint-2010-caml-query/

hops its helps..

Jignesh Rajput
  • 3,538
  • 30
  • 50
0

Try again with this - Remove the enclosed query tags from your variable camlquery

Nitin Rastogi
  • 1,446
  • 16
  • 30
  • The reason I use the tags is becasue I want the query to bring back the full results. Then I use (query.ViewFields = "";) in order to select specific values from the result set. The problem I have is that I not to sure how to get the results displayed in the asp control – Dev P Dec 05 '11 at 10:22
  • Have you checked whether you are getting the data back? – Nitin Rastogi Dec 05 '11 at 10:27
  • Ok, I see you are calling AvailabilityCheckerResultsTwo for adding controls. Can you put code for that method as well? Additionally, I am not sure what is the intent of the screen besides display of above data. If it's only above data, then you can possibly use DataViewWebPart as well. – Nitin Rastogi Dec 05 '11 at 12:18
  • The asp placeholder is just a normal place holder that I added to the webpart like so: . There is no method involved. – Dev P Dec 05 '11 at 12:30
  • Use SPGridView. It should be fairly quick. Refer here - http://blogs.msdn.com/b/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx – Nitin Rastogi Dec 05 '11 at 12:36
  • Additional you can also use .Net's Repeater control - http://www.sitepoint.com/asp-net-repeater-control/ – Nitin Rastogi Dec 05 '11 at 12:37