CodeSmith Community
Your Code. Your Way. Faster!

How do I use the provider datasource with getpaged?

Latest post 10-08-2007 8:03 AM by evolved. 8 replies.
  • 10-22-2006 10:30 AM

    • bsimser
    • Top 200 Contributor
    • Joined on 02-14-2006
    • Calgary, Alberta
    • Posts 23
    • Points 845

    How do I use the provider datasource with getpaged?

    I have a repeater on a webpage hooked up to a provider datasource (the one generated for my table in the .Web project). I've been using GetAll as the select method but want to page the data. I know repeaters don't page information but I need a better layout than what GridView will give me. So I tracked down how to page data on a repeater control (http://www.dotnethero.com/hero/Repeater/paging.aspx?nmx=2_1) but I'm not sure how I specify GetPaged in my datasource or how I pass parameters to it.

    Here's my datasource in the aspx page:

    <data:AddonDataSource runat="server" ID="AddonDS" SelectMethod="GetPaged" EnablePaging="true" EnableCaching="true" EnableSorting="true">
    <Parameters>
    <data:DataParameter Name="start" PropertyName="StartRowIndex" Type="Int32" DefaultValue="1" />
    <data:DataParameter Name="size" PropertyName="MaximumRows" Type="Int32" DefaultValue="10" />
    </Parameters>
    </
    data:AddonDataSource>

    The only data: that are allowed in Parameters is CustomParameter, DataParameter, and SqlParameter and the only type of tag allowed in the AddonDataSource (my table) is Parameters.

    Thanks.

    • Post Points: 45
  • 10-22-2006 1:14 PM In reply to

    • mcquiggd
    • Top 25 Contributor
    • Joined on 07-11-2006
    • Amsterdam
    • Posts 174
    • Points 4,375

    Re: How do I use the provider datasource with getpaged?

    Just a thought, and this is untested, but you could use the GetPaged method on your TypedDataSource, as I am doing, but instead of binding to a GridView which returns the PageSize, PageNumber automatically, specify a paramater such as:

     <!-- The basic DataSource for Articles to be displayed on a Page -->
    <data:ArticleDataSource id = "ArticleDS" runat= "server" selectmethod="GetPaged" EnableDeepLoad="true" EnableViewState="false">
      <Parameters>
        <asp:ControlParameter Name="PageNumber" ControlID="__Page" PropertyName="PageNumber" />
      </Parameters>
    </data:ArticleDataSource>

    And in your Code behind, expose a property named PageNumber that tracks which 'virtual page' of data you are on in ViewState. The <asp:ControlParamater does work, however it is not displayed in intellisense.

    Then perhaps wrap the Repeater in an Atlas UpdatePanel for partial page rendering, using forward and back buttons as triggers, with event handlers that increment or decrement the PageNumber. That way you take adavantage of the GetPaged method which is far more efficient. Im a bit busy at the moment but try this out and if there are problems, ill get back to you...

    David (Could people PLEASE click the 'Mark As Answer' button on the message that solved their problems - it will help others with similar questions and could potentially be included in an FAQ to save time for all of us)
    • Post Points: 65
  • 10-25-2006 8:38 AM In reply to

    • ham
    • Not Ranked
    • Joined on 10-11-2006
    • Posts 4
    • Points 110

    Re: How do I use the provider datasource with getpaged?

    Hi All,

    I require the same functionality but I am developing my DataList within a user control (.ascx). Can you let me know if I can directly reference the user control instead of the page.

    Many Thanks

    Ham

    • Post Points: 35
  • 10-25-2006 9:50 AM In reply to

    • Gonzo
    • Top 75 Contributor
    • Joined on 07-21-2006
    • Glasgow, Scotland
    • Posts 57
    • Points 1,480

    Re: How do I use the provider datasource with getpaged?

    You can use Typed Datasources in user controls, well i have it working *runs and checks*
    David Lawton Hyperion Technologies Ltd (UK)
    • Post Points: 5
  • 02-20-2007 2:50 AM In reply to

    • Tanno
    • Top 100 Contributor
    • Joined on 10-06-2006
    • Posts 50
    • Points 1,215

    Re: How do I use the Repeater + provider datasource with getpaged?

    Hi All,

    This thread started and broke off arround 10-22-2006, and we are now at 20-02-2007.

    I just wanted to know if, since then, there is any progress possible in this subject, because I also need a paged Typed Repeater.

    The main problem I have now, is that I need to obtain the NrOfRecords of the Count query that is part of the GetPaged stored procudure to determine the number of pages in my page-links. Which event and which datastructure or which method or  property of which object can I use to retreive this information from the .Net Tiers Black Box ??? It seems that the typed DataSource is very poor in its implementation of events. 

    Any comments are welcome

    regards

    Tanno    

     

    • Post Points: 35
  • 02-20-2007 12:41 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 767
    • Points 22,605

    Re: How do I use the Repeater + provider datasource with getpaged?

    Hi Tanno,

    I just threw this together real quick, but it seems to work anyway.  This is based on the Northwind Employees table.  The OnSelected event exposes the total number of rows through the e.AffectedRows property.

    Here's the guts of the aspx page:

        <data:EmployeesDataSource ID="EmployeesDS" runat="server" SelectMethod="GetPaged" OnSelected="EmployeesDS_Selected">
          <Parameters>
             <data:CustomParameter  Name="PageSize" DefaultValue="3" Type="Int32"  />
             <asp:ControlParameter Name="PageIndex" ControlID="__Page" PropertyName="PageNumber" />
             <data:CustomParameter Name="OrderBy" DefaultValue="LastName" />
          </Parameters>
        </data:EmployeesDataSource>
        
        <asp:Repeater runat="server" ID="rptEmployees" DataSourceID="EmployeesDS">
          <ItemTemplate>
             <asp:Label runat="server" Text='<%#Eval("LastName") %>'></asp:Label><br />
          </ItemTemplate>
          <FooterTemplate>
             Total Rows:<%#TotalRows %><br />
             Page Number: <%#PageNumber %><br />
             <br />         
             <asp:button id="cmdPrev" runat="server" text="Prev" 
                    onclick="cmdPrev_Click"></asp:button>&nbsp;
                    <asp:button id="cmdNext" runat="server" text="Next" 
                    onclick="cmdNext_Click"></asp:button>
    
          </FooterTemplate>
        </asp:Repeater>
    

    Here's the code-behind page:

       protected void EmployeesDS_Selected(object sender, ObjectDataSourceStatusEventArgs e)
       {
          TotalRows = e.AffectedRows;
       }
       
       public int TotalRows
       {
           get
          {
             if (ViewState["TotalRows"] != null)
                return Convert.ToInt32(ViewState["TotalRows"]);
             else
                return 0;
          }
          set
          {
             ViewState["TotalRows"] = value;
          }
    
       }
    
       public int PageNumber
       {
          get
          {
             if (ViewState["PageNumber"] != null)
                return Convert.ToInt32(ViewState["PageNumber"]);
             else
                return 0;
          }
          set
          {
             ViewState["PageNumber"] = value;
          }
       }
    
       protected void cmdPrev_Click(object sender, EventArgs e)
       {
          PageNumber -= 1;
       }
    
       protected void cmdNext_Click(object sender, EventArgs e)
       {
          PageNumber += 1;
       }
    

    Hope this helps.  Also, if you feel that the typed DataSource controls have poor events implemented, please give us some constructive feedback about what is missing.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 75
  • 07-06-2007 7:41 AM In reply to

    • jrbirdman
    • Not Ranked
    • Joined on 06-15-2007
    • Naples, FL
    • Posts 3
    • Points 15

    Re: How do I use the Repeater + provider datasource with getpaged?

    I posted a message somewhere else about not getting this example to work. Something about the "<#%TotalRows %>" not working.  It was worse than that.

    The paging buttons were hinkey as well.  They seemed "postback delayed" by one.  In other words, the first time I clicked any paging button, the page would do a postback but the rows won't change.  The next time I clicked a paging button it I's see the effect of the first previous click, not the latest one.  It was weird.  ViewState was turned off so I'm not sure what was going on except maybe it was picking up the PageNumber from ViewState during the pageload before it had a chance to update it after the button was clicked.  Probably something simple like that.

    The solution was to put the the buttons OUTSIDE the repeater.  Moving the TotalRows and PageNumber outside the repeater and plain old literals fixed that.

    Dave


     

     

    Dave D "I don't pretend to have all the answers, I don't even pretend to know all the questions.. Hey, where am I?" -- Jack Handy
    • Post Points: 5
  • 10-04-2007 10:42 AM In reply to

    • kinguru
    • Not Ranked
    • Joined on 05-10-2007
    • Posts 8
    • Points 160

    Re: How do I use the Repeater + provider datasource with getpaged?

     Hello!

     

    Can I get LAST page from datasource using GetPaged select method without data reloading?

    Another words, I want to determine total rows count, determine through it pages count and ask datasource to return me the last page rows only.

     

     

     

    Thanks! 

     

    • Post Points: 35
  • 10-08-2007 8:03 AM In reply to

    • evolved
    • Top 50 Contributor
    • Joined on 12-27-2004
    • South River, NJ
    • Posts 96
    • Points 1,840

    Re: How do I use the Repeater + provider datasource with getpaged?

     Why don't you just sort the results backwards and use the first page? Or create a view that has the table in the reverse sort order and work against that.

    http://www.jheidt.com
    ------------------------------
    Member of the .NetTiers team
    http://www.nettiers.com
    ------------------------------

    • Post Points: 5
Page 1 of 1 (9 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems