Last post Apr 20, 2011 11:17 PM by Decker Dong - MSFT
Apr 18, 2011 03:23 PM|WarrenW|LINK
Right now I am using the SQLDatasource control to call a stored procedure on an AS400. The SQLDatasource is binded to a gridview control that shows the results. All of this works fine. But what I really want to do is create a datatable from the SQLDatasource
after it is databound and assign the datatable to the gridview control's datasource property. I have tried several ways and cannot get it right.
Can someone show me source on how to do this from creating the datatable from the SQLDatasource control and then assigning it to the gridview? The reason I want to do this is I want to use the datatable for other stuff without requerying such as exporting
to excel and other.
I appreciate your help!
Apr 18, 2011 03:47 PM|thirumaran007|LINK
Apr 20, 2011 11:17 PM|Decker Dong - MSFT|LINK
As far as I know, SqlDataSource will do nearly everything to fetch data from real db and bind to the GridView automatically, so you needn't do manually.
However, if you insist, I think you can call something like this:
GridView1.DataSource = SqlDataSource1.Select(DataSourceSelectArguments.Empty);
Compared with the first one, I think you can use SqlDataAdapter with DataTable/DataSet, as well as SqlCommandBuilder, which makes your work more flexible when doing binding.