• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 607
  • Last Modified:

bind a datagrid to a web service dataset C#

How do you bind a datagrid to a web service that returns a dataset.
0
carter_jl
Asked:
carter_jl
  • 3
  • 2
1 Solution
 
carter_jlAuthor Commented:
I have a webservice that returns a dataset. How can bind this dataset to a datagrid in a web application?
0
 
Edwin_CCommented:
It should makes no difference in binding a dataset to a datagrid when your dataset is returned from a webservice or directly from database.

MyWebService webService = new MyWebService();
DataSet ds = webService.GetMyDataSet();  //GetMyDataSet is the method returning your dataset
MyDataGrid.DataSource=ds.Tables[0];  //bind the first table to the datagrid. alternative you can specify the table name
MyDataGrid.DataBind();

I hope I understand your question correctly.

Edwin
0
 
carter_jlAuthor Commented:
Service1 webservice = new Service1();
                  DataSet ds = webservice.getAllEmployees();
                  DataGrid1.DataSource = ds.Tables[0];
                  DataGrid1.DataBind();

This is the code I use to bind the datagrid. The only thing I get is the columns. There are no rows returned. What could be causing this? I don't think its the service method because I tested the service by itself.
0
 
Edwin_CCommented:
The only explanation I can think of is that your ds.Tables[0] contains no rows.  You can show the value of ds.Tables[0].Rows.Count in a label or in debug mode to see whether it contains rows.

Good luck
Edwin
0
 
carter_jlAuthor Commented:
You are correct it contains on rows, which is weird because when i invoke my service, (by itself) I can see the rows returned.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now