Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 24th, 2008, 03:10 AM
Authorized User
 
Join Date: Dec 2007
Location: hyderabad, Andhra Pradesh, India.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default paging datalist

hi,
 i am trying to paging datalist. i am following Scottgus's method.in this method i taken .xsd to bind the data to datasource .To get solution i searched a lot in google.

Here is my code :

// method for ObjectDataSource

 Protected Sub ProductDataSource_Selected(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
        Dim productCount As Integer = e.OutputParameters("CategoryProductCount") '.toInt32()
        Dim categoryName As String = e.OutputParameters("CategoryName") '.ToString()
        Dim pageIndex As Integer = Convert.ToInt32(Request.QueryString("pageIndex"))
        Dim CategoryId As Integer = Convert.ToInt32(Request.QueryString("CategoryId"))
        Dim pageSize As Integer = Int32.Parse(ProductDataSource.SelectParameters("Nu mRows").DefaultValue)

        UpdateTitles(categoryName)
        UpdatePagerLocation(pageIndex, pageSize, productCount)
        UpdateNextPrevLinks(CategoryId, pageIndex, pageSize, productCount)

    End Sub


    Public Sub UpdatePagerLocation(ByVal pageIndex As Integer, ByVal pageSize As Integer, ByVal productCount As Integer)
        Dim currentStartRow As Integer = (pageIndex * pageSize) + 1
        Dim currentEndRow = (pageIndex * pageSize) + pageSize
        If (currentEndRow < productCount) Then
            currentEndRow = productCount
            PagerLocation.Text = currentStartRow & "-" & currentEndRow & " of " & productCount & " products"
        End If
    End Sub


    Public Sub UpdateNextPrevLinks(ByVal categoryId As Integer, ByVal pageIndex As Integer, ByVal pageSize As Integer, ByVal productCount As Integer)
        Dim navigationFormat As String = "productspage.aspx?dealsId={0}&pageIndex={1}"
        PreviousPageNav.HRef = String.Format(navigationFormat, categoryId, pageIndex - 1)
        PreviousPageNav.Visible = IIf((pageIndex > 0), True, False)


        NextPageNav.HRef = String.Format(navigationFormat, categoryId, pageIndex + 1)
        NextPageNav.Visible = IIf(((pageIndex + 1) * pageSize < productCount), True, False)
    End Sub


    Public Sub UpdateTitles(ByVal title As String)
        productHeader.Text = title
        Page.Title = "products:" + title
    End Sub

sql procedure is :

CREATE procedure GetProductsByCategoryId
  @CategoryId varchar(250),
  @pageIndex int,
  @NumRows int,
@CategoryName nvarchar(50) output,
  @categoryProductCount int output
as
begin
  set @categoryProductCount=(select count(*) from productDeals where productDeals.productCategory=@CategoryId)
  set @CategoryName=(select category from pro_category where category=@CategoryId)

 declare @startRowIndex int;
 set @startRowIndex =(@pageIndex * @NumRows) + 1;

with productEntries as (
select ROW_NUMBER() over (order by dealsId asc) as Row,count(*) over() as ResultRowCount,dealsId,productName,validityFrom,va lidityTo,product,dealPrice from productDeals
   where productCategory=@CategoryName)

  select * from
   productEntries where Row between @startRowIndex and @startRowIndex+@NumRows-1
End

//.aspx page
 <div>
     <asp:Label ID="productHeader" runat="server" />
        <asp:DataList ID="ProductDataList" DataSourceID="ProductDataSource" RepeatColumns="2" RepeatDirection="Horizontal" Runat="server" DataKeyField="dealsId" >
            <ItemTemplate>
                productName:
                <asp:Label ID="productNameLabel" runat="server" Text='<%# Eval("productName") %>'>
                </asp:Label><br />
                dealPrice:
                <asp:Label ID="dealPriceLabel" runat="server" Text='<%# Eval("dealPrice") %>'></asp:Label><br />
                validityFrom:
                <asp:Label ID="validityFromLabel" runat="server" Text='<%# Eval("validityFrom") %>'>
                </asp:Label><br />
                validityTo:
                <asp:Label ID="validityToLabel" runat="server" Text='<%# Eval("validityTo") %>'>
                </asp:Label><br /><br />
                         </ItemTemplate>

        </asp:DataList>
                <asp:ObjectDataSource ID="ProductDataSource" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetProducts" TypeName="MyDataLayerTableAdapters.productsTableAd apter" OnSelected="ProductDataSource_Selected" UpdateMethod="GetProducts" >
                    <SelectParameters>
                        <asp:QueryStringParameter DefaultValue="Mobiles" Name="CategoryId" QueryStringField="categoryId"
                            Type="String" />
                        <asp:Parameter Name="pageIndex" Type="Int32" DefaultValue="0" />
                        <asp:Parameter Name="NumRows" Type="Int32" DefaultValue="2" />
                        <asp:Parameter Direction="InputOutput" Name="CategoryName" Type="String" DefaultValue="empty" />
                        <asp:Parameter Direction="InputOutput" Name="categoryProductCount" Type="Object" DefaultValue="0" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="CategoryId" Type="String" />
                        <asp:Parameter Name="pageIndex" Type="Int32" />
                        <asp:Parameter Name="NumRows" Type="Int32" />
                        <asp:Parameter Direction="InputOutput" Name="CategoryName" Type="String" />
                        <asp:Parameter Direction="InputOutput" Name="categoryProductCount" Type="Object" />
                    </UpdateParameters>
                </asp:ObjectDataSource>
                <div id="Navigation" class="navigation" runat="server" >
                 <div id="leftnav">
                  <a id="PreviousPageNav" runat="server" > &lt;&lt;</a> &nbsp; <a id="NextPageNav" runat="server">&gt;&gt;</a> &nbsp;
                     <asp:Label ID="PagerLocation" runat="server" />&nbsp;
                 </div>&nbsp;
                    <div id="numnav">
                        &nbsp;</div>
                   </div>
    </div>


in my table i have 9 rows. i want to display two items per page so that i given pageindex as 0 and pagesize as 2.when i run products.aspx page its displaying only first two rows only.the pageidex is getting increment but page is not displaying after second record. what i do. if any one can suggest me that how can i get 3rd to 9th record .

thanks in advance.
__________________
shanwaj
Reply With Quote
  #2 (permalink)  
Old March 25th, 2008, 12:03 AM
Authorized User
 
Join Date: Dec 2007
Location: hyderabad, Andhra Pradesh, India.
Posts: 38
Thanks: 2
Thanked 0 Times in 0 Posts
Default

hi,
  paging datalist is working fine,i done it myself.
  In p2p.wrox.com many members asked how to do paging in datalist.our advanced members given good solutions to that.Mr.Scottgus has given a wonderful article.
please follow below mentioned link,

http://weblogs.asp.net/scottgu/archi...07/434787.aspx

dont mind i want to suggest every one that before asking help to our seniors we should do hardwork on it.Many members asked that they want paging datalist vb.net langauage right,above mentioned article was in c# ,you convert into vb.net. if you know the programming, its not at all a big problem to convert.

sorry if i hurted any one
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datalist with paging venkatu2005 ASP.NET 1.0 and 1.1 Professional 1 July 17th, 2008 01:10 AM
Datalist Paging webnathan ASP.NET 1.0 and 1.1 Basics 3 November 19th, 2007 11:11 AM
Datalist Paging nedo_786 ASP.NET 2.0 Professional 9 September 20th, 2007 04:32 AM
How to allow paging in datalist? okboy SQL Server 2005 1 January 21st, 2007 10:08 PM
Datalist Paging in C# caitydev ASP.NET 2.0 Basics 0 March 29th, 2006 06:53 AM



All times are GMT -4. The time now is 11:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.