Hi,
I tried writing a generic function - GetData and passing the generic parameters. It may not be exact code, but it works. I hope it helps.
Cheers ...
Rajendra
--------------------------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
----------
---
protected void Page_Load(object sender, EventArgs e)
{
string returnItems = GetData("City", "", "<FieldRef Name='Title' /><FieldRef Name='Country' />", "zones.aspx?ZoneID=", "ows_ID");
Response.Write(returnItems
);
}
private string GetData(string thelistName, string strQuery, string strViewFields, string aspx, string idColumn)
{
Lists.Lists myListservice = new Lists.Lists();
myListservice.Credentials = System.Net.CredentialCache
.DefaultCr
edentials;
myListservice.Url = "
http://localhost/subsite1/_vti_bin/Lists.asmx";
/* Assign values to pass the GetListItems method*/
//string thelistName = "Zones"; // "{B6E894E8-EBB3-4E41-8416-
E8150B0EC5
7B}";
//Maybe we can create views in sharepoint that are specifically used for our web app?
//string viewName = "{C5C450CF-CEA0-4081-B4BE-
7D7DA06C86
77}";
string rowLimit = "500";
// Instantiate an XmlDocument object
System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
System.Xml.XmlElement query = xmlDoc.CreateElement("Quer
y");
System.Xml.XmlElement viewFields = xmlDoc.CreateElement("View
Fields");
System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("Quer
yOptions")
;
/*Use CAML query*/
query.InnerXml = strQuery; // "";//"<Where><Gt><FieldRef Name=\"ID\" /><Value Type=\"Counter\">0</Value></Gt
></Where>";
viewFields.InnerXml = strViewFields; // "<FieldRef Name=\"Title\" /><FieldRef Name=\"Zone_x0020_Number\"
/>";
queryOptions.InnerXml = "";
System.Xml.XmlNode nodes = myListservice.GetListItems
(thelistNa
me, null, query, viewFields, rowLimit, queryOptions, null);
string returnedItems = "";
foreach (System.Xml.XmlNode node in nodes)
{
if (node.Name == "rs:data")
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
if (node.ChildNodes[i].Name == "z:row")
{
string theURL = string.Concat("<a href='" + aspx , node.ChildNodes[i].Attribu
tes[idColu
mn].Value,
"'>");
returnedItems += string.Concat(theURL, node.ChildNodes[i].Attribu
tes["ows_T
itle"].Val
ue ?? String.Empty, "</a><br />");
}
}
}
}
return returnedItems;
}