Amit
Amit

Reputation: 22076

How to assign DataTable to SQLDataSource?

I have bind my GridView with SQLDataSource and it is working fine. Now I have a method (this method is from a dll, so I can't alter it) which returns DataTable and I have to assign this DataTable to SQLDataSource.

I am looking for something like this

SQLDataSource1.DataSource = MyDataTable;

I know there is no DataSource property in SQLDataSource, but I need similar kind of functionality.

If I set GridView1.DataSource = MyDataTable; then I loose all functionality of SQLDataSource like sorting, updating etc.

Code example will be helpful.

Upvotes: 0

Views: 7105

Answers (1)

codingbiz
codingbiz

Reputation: 26376

You can change from SqlDataSource to ObjectDataSource. That will allow you to call your method and still do paging

You can read more on ObjectDataSource and an more here

<asp:ObjectDataSource 
    SelectCountMethod="GetXXXMethodCount" //a method that return total number of records
    EnablePaging="true" 
    TypeName="YourBLLFullClassName" 
    SelectMethod="GetXXXMethod"
    MaximumRowsParameterName="maxRows"
    StartRowIndexParameterName="startRows"
    ID="ObjectDataSource1" 
    runat="server">
</asp:ObjectDataSource>

Upvotes: 1

Related Questions