WebService service = new WebService();
string xml = service.FindCountry();\\ getting xml string
DataSet ds = new DataSet();
XmlTextReader reader = new XmlTextReader(new StringReader(xml));
GridView1.DataSource = (ds.ReadXml(reader));
GridView1.DataBind();
**Exception Get while binding gridview**
- Data source is an invalid type. It must be either an IListSource, IEnumerable, or IDataSource.
From your error description, I suggest you can try the following two methods.
1: ReadXml() returns XmlReadMode which you can't assign as DataSource. You can populate the DataSet and assign it as DataSource in a separate line. You can try the following code.
DataSet ds = new DataSet();
XmlTextReader reader = new XmlTextReader(new StringReader(xml));
ds.ReadXml(reader);
GridView1.DataSource = ds;
GridView1.DataBind();
2: You can refer the following tutorial. It defines a DataTable return type in the method and gridview can be bound by the DataTable which will return from a Web Service.
Populate (Bind) GridView using Web Service (Web Method) in ASP.Net:
ASP.NET forums are moving to a new home on Microsoft Q&A, we encourage you to go to Microsoft Q&A for .NET for posting new questions and get involved today. Learn more >
Member
9 Points
39 Posts
Bind Webservice response into GridView
Mar 09, 2016 08:25 AM|Morfious90|LINK
My web-service returns XML string Response . I have this data to Show it on Grid-view. How to do so ?
request And Response code of my web service
This code returns me this XML string
**This is How i'm Binding grid**
**Exception Get while binding gridview**
- Data source is an invalid type. It must be either an IListSource,
IEnumerable, or IDataSource.
Star
11464 Points
2439 Posts
Re: Bind Webservice response into GridView
Mar 10, 2016 05:14 AM|Yohann Lu|LINK
Hi morfious90,
From your error description, I suggest you can try the following two methods.
1: ReadXml() returns XmlReadMode which you can't assign as DataSource. You can populate the DataSet and assign it as DataSource in a separate line. You can try the following code.
2: You can refer the following tutorial. It defines a DataTable return type in the method and gridview can be bound by the DataTable which will return from a Web Service.
Populate (Bind) GridView using Web Service (Web Method) in ASP.Net:
http://www.aspsnippets.com/Articles/Populate-Bind-GridView-using-Web-Service-Web-Method-in-ASPNet.aspx
Best Regards,
Yohann Lu