Monday, 15 September 2014

c# - Webmethod returning Arraylist with a collection of objects -



c# - Webmethod returning Arraylist with a collection of objects -

i have webmethod returns arraylist containing 4 objects:

public class getdata { public string name { get; set; } public int tagid { get; set; } public string address { get; set; } } [webmethod] public arraylist getvalues() { arraylist list = new arraylist(); getdata employee1= new getdata() { name="sathya", tagid=10, address="chennai" }; getdata employee2= new getdata() { name="ram", tagid=11, address="chennai" }; getdata employee3= new getdata() { name="pandi", tagid=12, address="chennai" }; getdata employee4= new getdata() { name = "karthick", tagid = 13, address = "chennai" }; list.add(employee1); list.add(employee2); list.add(employee3); list.add(employee4); homecoming list; }

but here want retrieve (display) name of these employees. how can in ui?

and method calling webmethod:

protected void page_load(object sender, eventargs e) { employeewebservice obj = new employeewebservice (); arraylist list = obj.getvalues();//calling webmethod //foreach (object o in list) //response.write(o); }

output should be:

sathya ram pandi karthick

please seek following...

public class getdata { public string name { get; set; } public int tagid { get; set; } public string address { get; set; } } [webmethod] public list<getdata> getvalues() { var list = new list<getdata>(); getdata employee1= new getdata() { name="sathya", tagid=10, address="chennai" }; getdata employee2= new getdata() { name="ram", tagid=11, address="chennai" }; getdata employee3= new getdata() { name="pandi", tagid=12, address="chennai" }; getdata employee4= new getdata() { name = "karthick", tagid = 13, address = "chennai" }; list.add(employee1); list.add(employee2); list.add(employee3); list.add(employee4); homecoming list; } protected void page_load(object sender, eventargs e) { employeewebservice obj = new employeewebservice (); var list = obj.getvalues();//calling webmethod foreach (var item in list) { response.write(item.name + "<br>"); } }

c# web-services arraylist

No comments:

Post a Comment