bind a datagrid to a web service dataset C#

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

    Author Comment

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

    Accepted Solution

    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

    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

    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

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now