Home All Groups Group Topic Archive Search About

Can GridView bind to a standalone DataTable

Author
25 Jun 2006 5:08 AM
ad
I have a type DataTable, it does exist in a DataSet.
How could I bind this DataTable to a GridView?

Author
26 Jun 2006 5:47 AM
Carl Prothman
"ad" <fly***@wfes.tcc.edu.tw> wrote in message news:%23$nJdVBmGHA.4816@TK2MSFTNGP03.phx.gbl...
>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
Author
26 Jun 2006 2:04 PM
ad
But my DataTable like MyTable is a stand alnoe DataTable, it do not belong
to any DataSet.
How can I do?


Show quote
"Carl Prothman" <c***@prothman.online.org> ¼¶¼g©ó¶l¥ó·s»D:%23%237dFQOmGHA.4***@TK2MSFTNGP03.phx.gbl...
> "ad" <fly***@wfes.tcc.edu.tw> wrote in message
> news:%23$nJdVBmGHA.4816@TK2MSFTNGP03.phx.gbl...
>>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
>
Author
26 Jun 2006 7:05 PM
Carl Prothman
"ad" <fly***@wfes.tcc.edu.tw> wrote
> 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();

AddThis Social Bookmark Button