Jaggu
Jaggu

Reputation: 6428

Is using ObjectDataSource a good practice?

In my company few of the employees are using ObjectDataSource. Example snippet is :

<asp:ObjectDataSource ID="odsRequirement" runat="server" EnablePaging="True" 
                      MaximumRowsParameterName="intMaxRows"
                      SelectMethod="GetAll" 
                      StartRowIndexParameterName="intRowIndex" 
                      TypeName="MyNamespace.MyType" 
                      SortParameterName="SortString"
                      OnSelecting="odsRequirement_Selecting"
                      SelectCountMethod="GetAllCount">
    <SelectParameters>
        <asp:Parameter Name="A" DefaultValue="null" />
        <asp:Parameter Name="B" DefaultValue="null" />
        <asp:Parameter Name="C" />
        <asp:Parameter Name="D" />
        <asp:Parameter Name="E" />
    </SelectParameters>
</asp:ObjectDataSource>

Will the SelectCountMethod GetAllCount be always fired after the SelectMethod GetAll? And is there a better way we should be doing this?

Thanks in advance:)

Upvotes: 2

Views: 398

Answers (1)

Jason Evans
Jason Evans

Reputation: 29186

Personally I'm not a big fan of these types of controls. I much prefer getting data from the code-behind and binding the data to the page. My problem is that you're baking domain logic into the ASPX page itself. I'd recommend seperating that by moving the code which gets the data into another class, which should be in another layer (i.e. Domain, or Model - which are usually class libraries).

Regardless, try to get away from using this control and move the data gathering logic into another file. In the long term, you will see the benefits.

http://geekswithblogs.net/opiesblog/archive/2006/09/11/90906.aspx

Upvotes: 3

Related Questions