0

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.

2
  • 2
    Why do you need to assign the table to the SqlDataSource at all? Can't you use the table as DataSource for the GridView directly? Commented Oct 11, 2012 at 22:33
  • @Tim Schmelter : I have updated my question. If I can set DataSource of SQLDataSource then all other functionality is ready. Commented Oct 11, 2012 at 22:34

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

Yes this is a option, but if I can set DataSource of SQLDataSource then all other functionality is ready. If I can keep SQLDataSource then it will be good.
I think ObjectDataSource is better than SQLDataSource as you can have a central BLL method that all ObjectDataSource can use, which can still be used by other part of your code. SQLDataSource on the other hand has SQL written in the Markup which not portable and is only useful to that page alone
Are you sure that I can still use all functionality of SQLDataSource without any changes in code?
Yes. Your SQL will go away and data will be coming from your method. The maxRows and startRows needs to be taken care of. Read those links.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.