locked
custom paging control RRS feed

  • Question

  • User637998132 posted

     

    i am using this http://www.codeproject.com/KB/custom-controls/CollectionPager.aspx to try and add paging to a repeater control.

    i am using a stongly typed dataset but i am stuck solid on this.

    i get exception Details: System.Web.HttpException: Cannot compute Count for a data source that does not implement ICollection.

     

     
    1    Imports System
    2 Imports Microsoft.VisualBasic
    3 Imports System.Collections
    4 Imports System.Data
    5 Imports System.Web
    6 Imports System.Web.UI
    7 Imports System.Web.UI.WebControls
    8 Imports Property_DataSet1TableAdapters
    9
    10
    11 ''' <summary>
    12 ''' Summary description for WebForm1.
    13 ''' </summary>

    14 Partial Class Default6
    15 Inherits System.Web.UI.Page
    16
    17 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    18 Dim Adapter As New Property_TableTableAdapter
    19 'CollectionPager1.DataSource = DirectCast((ObjectDataSourceList.[Select](DataSourceSelectArguments.Empty)), DataView)
    20 CollectionPager1.DataSource = Adapter.GetByLocationAndType(0, 0, 0, 0)
    21 'Let the Pager know what Control it needs to DataBind during the PreRender
    22 CollectionPager1.BindToControl = Repeater2
    23
    24 End Sub
    25 End Class

    26
    27

    Thursday, July 10, 2008 8:03 AM

Answers

  • User-1136466523 posted

    Hi,

    In your code, you can try the DefaultView property of a typed DataTable object. And then bind it to the datasource.

    Adapter.GetByLocationAndType(0, 0, 0, 0).DefaultView

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 17, 2008 3:02 AM

All replies

  • User-1136466523 posted

    Hi,

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>

    The underlying DataSource has to support the ICollection interface in order for the grid to perform automatic paging. ICollection requires a class to implement a Count property. ArrayList and DataView both support the interface, so you could use them as DataSources. Try to make sure the return type of Adapter.GetByLocationAndType() method.

    <o:p> </o:p>

    Other classes only support the IEnumerable interface. This allows them to be used as a DataSource but not as a paged data source.

    <o:p> </o:p>

    Thanks.

     

    Wednesday, July 16, 2008 2:12 AM
  • User637998132 posted

    The underlying DataSource has to support the ICollection interface in order for the grid to perform automatic paging. ICollection requires a class to implement a Count property. ArrayList and DataView both support the interface, so you could use them as DataSources. Try to make sure the return type of Adapter.GetByLocationAndType() method.
     

     

    thanks for that , could you paste some example code as to what i have to do to my  code to get it to work, i'm very new to asp.net vb so would be very greatful if you can show me what i need to do to get it to work. can i convert my stronly typed dataset to an icollection?

    Wednesday, July 16, 2008 3:52 AM
  • User-1136466523 posted

    Hi,

    In your code, you can try the DefaultView property of a typed DataTable object. And then bind it to the datasource.

    Adapter.GetByLocationAndType(0, 0, 0, 0).DefaultView

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 17, 2008 3:02 AM
  • User637998132 posted

    In your code, you can try the DefaultView property of a typed DataTable object. And then bind it to the datasource.

    Adapter.GetByLocationAndType(0, 0, 0, 0).DefaultView

     

     

    That worked to a certain degree...it does display the records and the paging. one problem is that i have filter controls on the page that reference the objectdatasource that i use to attach to the pager..

    i think because i have set this to  Adapter.GetByLocationAndType(0, 0, 0, 0).DefaultView on page load it overrides what the user has filtered ... for example one of the filters contains locations and should filter the results to only show properties in that location. i did have this working before i added the pager ... here is the code

     

     

    1    Imports System
    2    Imports Microsoft.VisualBasic
    3    Imports System.Collections
    4    Imports System.Data
    5    Imports System.Web
    6    Imports System.Web.UI
    7    Imports System.Web.UI.WebControls
    8    Imports Property_DataSet1TableAdapters
    9    
    10   
    11       ''' <summary>
    12       ''' Summary description for WebForm1.
    13       ''' </summary>
    14   Partial Class Default6
    15   
    16   
    17       Inherits System.Web.UI.Page
    18       
    19   
    20   
    21       Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    22   
    23   
    24           Dim Adapter As New Property_TableTableAdapter
    25           'CollectionPager1.DataSource = DirectCast((ObjectDataSourceList.[Select](DataSourceSelectArguments.Empty)), DataView)
    26           CollectionPager1.DataSource = Adapter.GetByLocationAndType(0, 0, 0, 0).DefaultView
    27   
    28           'Let the Pager know what Control it needs to DataBind during the PreRender
    29           CollectionPager1.BindToControl = Repeater2
    30   
    31           Repeater2.DataSource = CollectionPager1.DataSourcePaged
    32   
    33       End Sub
    34   
    35       
    36   End Class
    

      

    here is the code in the aspx page, please note the datasource i am using and the filters in the dropdowns.

     

     

    1    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" title="Untitled Page" %>
    2    
    3    <%@ Register assembly="CollectionPager" namespace="SiteUtils" tagprefix="cc1" %>
    4    
    5    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    6    </asp:Content>
    7    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    8    <div class="search">
    9    <div class="searchInner">
    10   <div class="SearchItem">
    11   <label>Minimum:</label>
    12       <asp:DropDownList ID="MinPrice" runat="server" AutoPostBack="True">
    13           <asp:ListItem Value="0">select min price</asp:ListItem>
    14           <asp:ListItem Value="20000">20,000</asp:ListItem>
    15           <asp:ListItem Value="50000">50,000</asp:ListItem>
    16           <asp:ListItem Value="80000">80,000</asp:ListItem>
    17           <asp:ListItem Value="100000">100,000</asp:ListItem>
    18           <asp:ListItem Value="150000">150,000</asp:ListItem>
    19           <asp:ListItem Value="200000">200,000</asp:ListItem>
    20           <asp:ListItem Value="250000">250,000</asp:ListItem>
    21           <asp:ListItem Value="500000">500,000</asp:ListItem>
    22           <asp:ListItem></asp:ListItem>
    23       </asp:DropDownList>
    24   </div>
    25   <div class="SearchItem">
    26   <label>Maximum:</label>
    27       <asp:DropDownList ID="maxprice" runat="server" AppendDataBoundItems="True" 
    28           AutoPostBack="True">
    29           <asp:ListItem Value="0">select max price</asp:ListItem>
    30                 <asp:ListItem Value="2000">20,000</asp:ListItem>
    31           <asp:ListItem Value="50000">500,000</asp:ListItem>
    32           <asp:ListItem Value="80000">80,000</asp:ListItem>
    33           <asp:ListItem Value="100000">100,000</asp:ListItem>
    34           <asp:ListItem Value="150000">150,000</asp:ListItem>
    35           <asp:ListItem Value="200000">200,000</asp:ListItem>
    36           <asp:ListItem Value="250000">250,000</asp:ListItem>
    37           <asp:ListItem Value="500000">500,000</asp:ListItem>
    38           <asp:ListItem Value="1000000">100,0000</asp:ListItem>
    39           <asp:ListItem></asp:ListItem>
    40       </asp:DropDownList>
    41   </div>
    42   <div class="SearchItem">
    43   <label>Type:</label>
    44       <asp:DropDownList ID="type" runat="server" AppendDataBoundItems="True" 
    45           DataSourceID="ObjectDataSource1" DataTextField="TypeOfProperty" 
    46           DataValueField="TypeID" AutoPostBack="True">
    47           <asp:ListItem Value="0">select type</asp:ListItem>
    48       </asp:DropDownList>
    49       <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
    50           OldValuesParameterFormatString="original_{0}" SelectMethod="GetByType" 
    51           TypeName="TypeBLL"></asp:ObjectDataSource>
    52   </div>
    53   <div class="SearchItem">
    54   <label>Location:</label>
    55       <asp:DropDownList ID="location" runat="server" DataSourceID="ObjectDataSource2" 
    56           DataTextField="Location" DataValueField="LocationID" 
    57           AutoPostBack="True" AppendDataBoundItems="True">
    58           <asp:ListItem Value="0">select location</asp:ListItem>
    59       </asp:DropDownList>
    60       <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
    61           OldValuesParameterFormatString="original_{0}" SelectMethod="GetLocation" 
    62           TypeName="LocationBLL"></asp:ObjectDataSource>
    63   </div>
    64   <div class="SearchItem">
    65   <label>Bedrooms:</label>
    66       <asp:DropDownList ID="bedrooms" runat="server">
    67           <asp:ListItem Value="0">select bedrooms</asp:ListItem>
    68           <asp:ListItem>1</asp:ListItem>
    69           <asp:ListItem>2</asp:ListItem>
    70           <asp:ListItem>3</asp:ListItem>
    71           <asp:ListItem>4</asp:ListItem>
    72           <asp:ListItem>5</asp:ListItem>
    73           <asp:ListItem></asp:ListItem>
    74       </asp:DropDownList>
    75   </div>
    76   </div>
    77   </div>
    78   <div class="Breadcrumb">
    79   <p>Home <span style="color:#CC0001; font-weight:bold;">></span> Property Search</p>
    80   
    81   </div>
    82     <div class="maincontent">
    83   <div class="leftbar">
    84   <div class="shortlist">
    85   <div class="shortlistTop"><!--no content--></div>
    86   <div class="shortlistcontent">
    87   <h2>ShortList</h2>
    88   <p>Properties in short list:0</p>
    89                                   <p>
    90                                       <asp:LoginView ID="LoginView1" runat="server">
    91                                           <AnonymousTemplate>
    92                                               YOU ARE NOT LOGEED IN
    93                                           </AnonymousTemplate>
    94                                       </asp:LoginView>
    95                                   </p>
    96   </div>
    97   <div class="shortlistBottom"><!--no content--></div>
    98   </div>
    99   
    100  </div>
    101  <div class="content">  
    102      
    103  
    104  <asp:Repeater ID="Repeater2" runat="server">
    105  <HeaderTemplate>
    106  <div class="SearchHeader"><!--no content --></div>
    107  </HeaderTemplate>
    108  <ItemTemplate>
    109  <div class="SearchListing">
    110  <img src="images/lTCP0002201.JPG" width="140" height="100" alt="" class="PropertyImage"/>
    111  <h1><%#DataBinder.Eval(Container.DataItem, "Title")%></h1>
    112  <div class="Details">
    113  <ul>
    114  <li>Price:<%# DataBinder.Eval(Container.DataItem,"Price")%></li>
    115  <li>Property:<%# DataBinder.Eval(Container.DataItem,"TypeOfProperty")%></li>
    116  <li>Location:<%#DataBinder.Eval(Container.DataItem, "Location")%> </li>
    117  <li>Bedrooms<%#DataBinder.Eval(Container.DataItem, "Bedrooms")%></li>
    118  </ul>
    119  </div>
    120  <p class="description"><%#DataBinder.Eval(Container.DataItem, "Description")%></p>
    121  <div class="links">
    122  <ul>
    123  <li>
    124      </li>
    125  <li><a href="Default3.aspx?PropertyID=<%# DataBinder.Eval(Container.DataItem, "PropertyID") %>" ><img src="images/Untitled-1_01.png" /></a></li>
    126  <li><a href="ArrangeViewing.aspx?PropertyID=<%# DataBinder.Eval(Container.DataItem, "PropertyID") %>"><img src="images/ArrangeViewing.png" /></a></li>
    127  <li><a href="#"><img src="images/AddToShortlist.png" /></a></li>
    128  <li><a href="#"><img src="images/PrintThisPage.png" /></a></li>
    129  <li><a href="MortgaeCalc.aspx=<%# DataBinder.Eval(Container.DataItem, "PropertyID") %>"><img src="images/MortgageCalc.png" /></a></li>
    130  </ul>
    131  </div>
    132  </div>
    133  </ItemTemplate>
    134  
    135      </asp:Repeater>
    136      
    137    
    138      <asp:ObjectDataSource ID="ObjectDataSourceList" runat="server" OldValuesParameterFormatString="original_{0}" 
    139          SelectMethod="GetByLocationAndType" TypeName="PropertyBLL" 
    140          InsertMethod="AddProperty" UpdateMethod="UpdateProperty">
    141          <UpdateParameters>
    142              <asp:Parameter Name="PropertyID" Type="Int32" />
    143              <asp:Parameter Name="LocationID" Type="Int32" />
    144              <asp:Parameter Name="TypeID" Type="Int32" />
    145              <asp:Parameter Name="Title" Type="String" />
    146              <asp:Parameter Name="Description" Type="String" />
    147              <asp:Parameter Direction="InputOutput" Name="Price" Type="Decimal" />
    148              <asp:Parameter Name="Bedrooms" Type="Int32" />
    149          </UpdateParameters>
    150          <SelectParameters>
    151              <asp:ControlParameter ControlID="MinPrice" Name="MinPrice" 
    152                  PropertyName="SelectedValue" Type="Int32" />
    153              <asp:ControlParameter ControlID="maxprice" Name="MaxPrice" 
    154                  PropertyName="SelectedValue" Type="Int32" />
    155              <asp:ControlParameter ControlID="location" Name="LocationID" 
    156                  PropertyName="SelectedValue" Type="Int32" />
    157              <asp:ControlParameter ControlID="type" Name="TypeID" 
    158                  PropertyName="SelectedValue" Type="Int32" />
    159          </SelectParameters>
    160          <InsertParameters>
    161              <asp:Parameter Name="LocationID" Type="Int32" />
    162              <asp:Parameter Name="TypeID" Type="Int32" />
    163              <asp:Parameter Name="Title" Type="String" />
    164              <asp:Parameter Name="Description" Type="String" />
    165              <asp:Parameter Direction="InputOutput" Name="Price" Type="Decimal" />
    166              <asp:Parameter Name="Bedrooms" Type="Int32" />
    167          </InsertParameters>
    168      </asp:ObjectDataSource>
    169      <div>
    170  
    171          <cc1:CollectionPager ID="CollectionPager1" runat="server" PageSize="3">
    172          </cc1:CollectionPager>
    173  
    174  </div>
    175  </div>
    176  <div class="rightbar">Right</div>
    177  </div>
    178  <div class="rule"><!--no content --></div>
    179  </asp:Content>
    
      
    Thursday, July 17, 2008 2:48 PM