SqlDataSource remote paging

  1. #1

    SqlDataSource remote paging

    I found many requests: give a working example of sqldatasource+gridview+PagingToolbar for remotepaging. All Post - reply: refer to sqldataobject example - easy to remake. But not all. I so understood that paging support is built in sqldataobject. in general - an example if can make - show please! !
    Last edited by geoffrey.mcgill; Oct 24, 2013 at 3:49 PM.
  2. #2
    Only retrieve one page from the database

    Eg MS SQLServer
    For 2012 you can use OFFSET and for 2008 use RowNumber()
    http://blog.sqlauthority.com/2013/04...of-sql-server/

    The implementation i Ext.NET is trivial and explained in the demos

    If you are using other software please let us know

    hth /Peter
  3. #3
    Quote Originally Posted by plykkegaard View Post
    Only retrieve one page from the database



    The implementation i Ext.NET is trivial and explained in the demos



    hth /Peter
    Thanks.. its nice .. but i study ext.net only 2 week and this not trivial for me.. and asp.net 3 week only.. :)
    please show full example sqldatasource+gridview+PagingToolbar for remote paging if possible.

    Tnanks..
  4. #4
    Check this article for paging on the SQL server
    http://www.4guysfromrolla.com/articles/031506-1.aspx

    And this sample should give you a headstart with remote paging
    https://examples2.ext.net/#/GridPane...h_Remote_Data/

    hth /Peter
  5. #5
    Quote Originally Posted by plykkegaard View Post
    Check this article for paging on the SQL server
    http://www.4guysfromrolla.com/articles/031506-1.aspx

    And this sample should give you a headstart with remote paging
    https://examples2.ext.net/#/GridPane...h_Remote_Data/

    hth /Peter
    i see that post and example, but i dont understand where i write SQL req ?
    example - Local Paging..

    i think after click on button Next in ToolBarPage - call reload function Store with parameter № first row and count row ..

    and refresh row in grid view.

    please full working sample - its better for me.

    ps
    replace in next code Example - for call Ajax req for get next row from SQL server in Object and
    in row code data.Add(new {field = "Value" + (i + 1)}); add them to object data?


    List<object> data = new List<object>(limit);

    for (int i = start; i < start + limit; i++)
    {
    data.Add(new {field = "Value" + (i + 1)});
    }

    e.Total = 8000; // set total row?
    Last edited by asics167; Oct 25, 2013 at 10:26 AM. Reason: continue
  6. #6
    When I created my first app I started with this sample to get data from the database
    https://examples2.ext.net/#/GridPane...SqlDataSource/

    I assume you are retreiving data from the Microsoft SQL Server?

    The current source I have is too complex to send you the full sample you're requesting

    - Peter
  7. #7
    Quote Originally Posted by plykkegaard View Post
    When I created my first app I started with this sample to get data from the database
    https://examples2.ext.net/#/GridPane...SqlDataSource/

    I assume you are retreiving data from the Microsoft SQL Server?

    The current source I have is too complex to send you the full sample you're requesting

    - Peter
    Yes from MS SQL

    may be you help me rewrite my code with Page?

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPaging.aspx.cs" Inherits="WebApplication1.WebForm4" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        
        
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:FD_DAT_0_8_0_copy_02_10_2013ConnectionString %>" 
                SelectCommand="SELECT Birthday, UID, Surname,Name,MiddleName
                                                  ,rowNum, (rowNum / 20) + 1 as pageNum
                                                FROM (
                                                    SELECT a.Birthday,UID, Surname,Name,MiddleName
                                                       , Row_Number() OVER (order by surname) as rowNum
                                                    FROM regPatients a
          
        
                                                ) x
                                            WHERE (rowNum / 20) + 1 =  @page">
                <SelectParameters>
                         <asp:Parameter Name="page" Type="Int32" />
                </SelectParameters>
    
            </asp:SqlDataSource>
    
    
         <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:GridPanel 
                runat="server" 
                ID="GridPanel1" 
                Title="Patient" 
                Frame="true"
                Height="300">
                <Store>
                    <ext:Store 
                        ID="Store1" 
                        runat="server" 
                       
                        DataSourceID="SqlDataSource1">
                      
                        
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
                        <Model>
                            <ext:Model ID="Model1" runat="server" IDProperty="Patient">
                                <Fields>
                                    <ext:ModelField Name="Birthday" Type="Date"/>
                                    <ext:ModelField Name="UID" />
                                    <ext:ModelField Name="Surname" />
                                    <ext:ModelField Name="Name" />
                                    <ext:ModelField Name="MiddleName"  />
                                    <ext:ModelField Name="rowNum"  />
                                    <ext:ModelField Name="pageNum" />
                                 
                                </Fields>
                            </ext:Model>
                        </Model>
                      </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:DateColumn ID="DateColumn1" runat="server" DataIndex="BirthDate" Text="BirthDate" Width="110" Format="yyyy-MM-dd" /> 
                        <ext:Column ID="Column2" runat="server" DataIndex="UID" Text="UID" Width="150" />
                        <ext:Column ID="Column3" runat="server" DataIndex="Surname" Text="Surname" Width="150" />
                        <ext:Column ID="Column4" runat="server" DataIndex="Name" Text="Name" Width="150" />
                        <ext:Column ID="Column5" runat="server" DataIndex="MiddleName" Text="MiddleName" Width="100" />
                        <ext:Column ID="Column6" runat="server" DataIndex="rowNum" Text="rowNum" Width="100" />
                        <ext:Column ID="Column7" runat="server" DataIndex="pageNum" Text="pageNum"  Width="100" />
                        
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server">
                    
                    </ext:GridView>
                </View>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Multi" />
                </SelectionModel>
                    
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolbar1" 
                        runat="server"                      
                        DisplayInfo="true" 
                        DisplayMsg="Displaying patient {0} - {1} of {2}" 
                        EmptyMsg="No patient to display" 
                        />
                </BottomBar>
            </ext:GridPanel>
            
            <ext:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    when Page load i see in FireBug
    GET http://localhost:55042/TestPaging.aspx - Load content Page
    POST http://localhost:55042/TestPaging.aspx - Request data? what call procedure name ?
    submitDirectEventConfig={"config":{"extraParams":{ "page":1,"start":0,"limit":25}}} -- where set this parameter?
    i dont understand this.. :(
  8. #8

    my exaple with sqlDataSource

    1. Create Stored Proc in Database for read Table for Page :

    CREATE PROCEDURE dbo.GetListPatientsbyPage
    @LimitC INT,
    @PageC int,
    @TotalC int output
    
    AS
    BEGIN
      SELECT Birthday, UID, Surname,Name,MiddleName
      ,rowNum, (rowNum / @LimitC) + 1 as pageNum
        FROM (
            SELECT a.Birthday,UID, Surname,Name,MiddleName
               , Row_Number() OVER (order by surname) as rowNum
            FROM regPatients a
          
        
        ) x
        WHERE (rowNum / @LimitC) + 1 =  @pageC
        
       set @TotalC=(Select count(*)   FROM regPatients a with (nolock))
                                             
    END
    where 3 parameter:
    @LimitC - Row Per Page
    @PageC - number Page
    @TotalC - count all rows in request

    2.
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PatientCabinet.aspx.cs" Inherits="PatientCabinet.PatientCabinet" %>
    
    <%@ Import Namespace="System.Data"  %>
    <%@ Import Namespace="System.Data.SqlClient"  %>
    <%@ Import Namespace="System.Collections.Generic" %>
     
    <script runat="server">
      
        StoreReadDataEventArgs e; 
    
        protected void db_onSelecting(object sender, SqlDataSourceCommandEventArgs e)
        {
         
        //   on selecting set number page - not woking - why??
       //     SqlDataSource1.SelectParameters["pagec"].DefaultValue = this.e.Page.ToString();
    
        }
    
        protected void db_onSelected(object sender, SqlDataSourceStatusEventArgs e)
        {
          
              (this.Store1.Proxy[0] as PageProxy).Total = (int) e.Command.Parameters["@TotalC"].Value; // set total row after select from db
        }
    
       
        protected void Pat_ReadData(object sender, StoreReadDataEventArgs e)
        {
          
            this.e = e; //? for set in onselecting event - from example - but not working
       
            SqlDataSource1.SelectParameters["pageC"].DefaultValue  =e.Page.ToString(); // set page number before request
        
        }
    
    </script>
    
    <!DOCTYPE html>
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
         
         
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" OnSelecting="db_onSelecting"
                OnSelected="db_onSelected" SelectCommandType="StoredProcedure" 
                ConnectionString="<%$ ConnectionStrings:FDConnectionString %>" 
                SelectCommand="dbo.getListPatientsbyPage">
                 
                <SelectParameters>
                         
                         <asp:QueryStringParameter Name="LimitC" Type="Int32" QueryStringField="LimitC" DefaultValue="15" />
                         <asp:QueryStringParameter Name="PageC" Type="Int32"  QueryStringField="PageC"  DefaultValue="1"/>
                         <asp:parameter name="TotalC" type="Int32" direction="Output" defaultvalue="0" />
                  
                </SelectParameters>
     
            </asp:SqlDataSource>
     
     
         <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:GridPanel
                runat="server"
                ID="GridPanel1"
                Title="Patient"
                Frame="true"
                Height="300">
                <Store>
                    <ext:Store
                        ID="Store1"
                        runat="server"
                        DataSourceID="SqlDataSource1"
                        OnRefreshData="Store_RefreshData"
                        OnReadData="Pat_ReadData"
                
                         >
    
                        <Proxy>
                            <ext:PageProxy />
                        </Proxy>
    
                        <Model>
                            <ext:Model ID="Model1" runat="server" IDProperty="Patient">
                                <Fields>
                                    <ext:ModelField Name="Birthday" Type="Date"/>
                                    <ext:ModelField Name="UID" />
                                    <ext:ModelField Name="Surname" />
                                    <ext:ModelField Name="Name" />
                                    <ext:ModelField Name="MiddleName"  />
                                    <ext:ModelField Name="rowNum"  />
                                    <ext:ModelField Name="pageNum" />
                                   
                                </Fields>
                            </ext:Model>
                        </Model>
                         
                      </ext:Store>
                </Store>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:DateColumn ID="DateColumn1" runat="server" DataIndex="BirthDate" Text="BirthDate" Width="110" Format="yyyy-MM-dd" /> 
                        <ext:Column ID="Column2" runat="server" DataIndex="UID" Text="UID" Width="150" />
                        <ext:Column ID="Column3" runat="server" DataIndex="Surname" Text="Surname" Width="150" />
                        <ext:Column ID="Column4" runat="server" DataIndex="Name" Text="Name" Width="150" />
                        <ext:Column ID="Column5" runat="server" DataIndex="MiddleName" Text="MiddleName" Width="100" />
                        <ext:Column ID="Column6" runat="server" DataIndex="rowNum" Text="rowNum" Width="100" />
                        <ext:Column ID="Column7" runat="server" DataIndex="pageNum" Text="pageNum"  Width="100" />
                    
                    </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="GridView1" runat="server">
                     
                    </ext:GridView>
                </View>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" Mode="Multi" />
                </SelectionModel>
                     
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolbar1"
                        runat="server"                     
                        DisplayInfo="true"
                        DisplayMsg="Displaying patient {0} - {1} of {2}"
                        EmptyMsg="No patient to display"
                        />
                </BottomBar>
            </ext:GridPanel>
             
            <ext:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    Its work fine!
    one moment - why not working set number page ( @pagec) in selecting event ? i don understand.. :)

Similar Threads

  1. GridPanel Remote Paging with SqlDatasource
    By Aod47 in forum 1.x Help
    Replies: 1
    Last Post: Oct 25, 2013, 6:00 AM
  2. Replies: 6
    Last Post: Nov 03, 2012, 10:48 PM
  3. Replies: 11
    Last Post: Jun 13, 2012, 4:53 PM
  4. [CLOSED] LinqDataSource and remote paging
    By John_Writers in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 28, 2011, 11:22 AM
  5. [CLOSED] grid remote paging
    By krzak in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 06, 2011, 3:47 PM

Posting Permissions