Can GridView bind to a standalone DataTable

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have a type DataTable, it does exist in a DataSet.
How could I bind this DataTable to a GridView?
 
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
 
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
 
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();
 
Back
Top