We help IT Professionals succeed at work.

How to bind a GridView to a DataTableReader

rowansmith
rowansmith asked
on
Medium Priority
920 Views
Last Modified: 2013-12-17
I have a

DataTableReader dtr
GridView gv1

How do I bind the first result set of dtr to gv1 and have all the columns show so that I can traverse through all the records.

What is the best way to do this, I am just looking for something quick and dirty.

Thanks.

-Rowan
Comment
Watch Question

Commented:
DataTableReader dtr
GridView gv1

If your DataTableReader is not null than

gv1.datasource = dtr;
gv1.databind()

OK.
Commented:
Correct the code

DataTableReader dtr
GridView gv1

If your DataTableReader is not null than

gv1.datasource = dtr;
gv1.databind();

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
There is no databind method.. this is .NET 3.5 and I just realised it is a datagridview class.

Author

Commented:
I found the following on another site and it worked so I went with it.  the original parameters have changed so the question is no longer valid.

I have no idea what the following two lines do or even if they are both required but it works and as I am only doing this for a debug function I don;t need to undestand the datagridview class (yet).

Thanks.

public TableGridView(DataSet ds,string tableName)
        {
       

            dataGridView1.DataSource = ds.Tables[tableName].DefaultView;
            dataGridView1.DataSource = ds.Tables[tableName];
        }
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.