Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a custom form, the data is getting stored in listview of a particular list.
now i want to fetch data from that listview based on 2 columns present in that listview. how do I go about it?
Posted
Comments
Beginner Luck 28-Jan-16 3:10am    
which code you using powershell or C# or javascript??
Member 12253249 28-Jan-16 4:35am    
C#

C#
SPQuery query = new SPQuery();
 query.Query = "<OrderBy><FieldRef Name='Modified' Ascending='TRUE'/></OrderBy>" +
 "<Where><And>" +
 "<Eq><FieldRef Name='status'/><Value Type='Text'>" + DocType + "</Value></Eq>" +
 "<Eq><FieldRef Name='Department1'/><Value Type='Lookup'>" + Department + "</Value></Eq>" +
 "</And></Where>";

using(SPweb newweb = newsite.open()){
SPlist spl = newweb.list.trygetlist("");

datatable dt = spl.getitem(query).getdatatable();


this is just example
 
Share this answer
 
C#
System.data;
Microsoft.sharepoint;

using(SPsite newsite = new SPsite("name of your website")){

using(SPweb newweb = newsite.open()){
SPlist spl = newweb.list.trygetlist(" name of your list ");

datatable dt = spl.getitem("add CAML query here").getdatatable();

foreach(datarow dr in dt.rows)
	dr["column name "].toString();
}
 
Share this answer
 
v3
Comments
Member 12253249 28-Jan-16 12:48pm    
ohkie. now i have got data in my table, using sp query. the query result is stored in datatabble. i want to display only those rows of datatable which have some data in a gridview.
Beginner Luck 28-Jan-16 20:19pm    
use CAML query

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900