Can GridView bind to a standalone DataTable

A

ad

I have a type DataTable, it does exist in a DataSet.
How could I bind this DataTable to a GridView?
 
C

Carl Prothman

ad said:
I have a type DataTable, it does exist in a DataSet.
How could I bind this DataTable to a GridView?

Ad,
Just set the DataSource property, then call DataBind() method.

gridView1.DataSource = dataSet1.Tables["MyTableName"];
gridView1.DataBind();

The GridView can also be bound to a data source control. e.g. SqlDataSource
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx
- Note this is the preferred method to bind to data.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.CarlProthman.NET
 
A

ad

But my DataTable like MyTable is a stand alnoe DataTable, it do not belong
to any DataSet.
How can I do?


Carl Prothman said:
ad said:
I have a type DataTable, it does exist in a DataSet.
How could I bind this DataTable to a GridView?

Ad,
Just set the DataSource property, then call DataBind() method.

gridView1.DataSource = dataSet1.Tables["MyTableName"];
gridView1.DataBind();

The GridView can also be bound to a data source control. e.g.
SqlDataSource
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.aspx
- Note this is the preferred method to bind to data.

--

Thanks,
Carl Prothman
Microsoft ASP.NET MVP
http://www.CarlProthman.NET
 
C

Carl Prothman

ad said:
But my DataTable like MyTable is a stand alnoe DataTable, it do not belong
to any DataSet.
How can I do?

gridView1.DataSource = myDataTable;
gridView1.DataBind();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top