bind a datagrid to a web service dataset C#

Posted on 2006-06-05
Medium Priority
Last Modified: 2008-02-01
How do you bind a datagrid to a web service that returns a dataset.
Question by:carter_jl
  • 3
  • 2

Author Comment

ID: 16837846
I have a webservice that returns a dataset. How can bind this dataset to a datagrid in a web application?
LVL 16

Accepted Solution

Edwin_C earned 2000 total points
ID: 16840969
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

I hope I understand your question correctly.


Author Comment

ID: 16841695
Service1 webservice = new Service1();
                  DataSet ds = webservice.getAllEmployees();
                  DataGrid1.DataSource = ds.Tables[0];

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.
LVL 16

Expert Comment

ID: 16842101
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

Author Comment

ID: 16842139
You are correct it contains on rows, which is weird because when i invoke my service, (by itself) I can see the rows returned.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month15 days, 9 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question