Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.Net GridView with ObjectDataSource Paging not working properly

Posted on 2010-11-25
3
Medium Priority
?
718 Views
Last Modified: 2012-05-10
Dear Friends,

Thanks for all the assistance given till date and really appreciate a lot for the same.
Last 2 days I have been trying to master the GridView with ObjectDatasource and posted a few issues in this regard. Still a few issue remains and need all your generous help to sort the same.

The GridView with ObjectDatasource I am trying to learn has got a paging issue and I dont know how to sort this out. The first page when loaded looks perfect. The paging problem starts with the subsequent pages.
There are about 34 records in table and pagesize is set to 8. But when I click on the page link 2 it shows the last record.

The complete code with .aspx, .aspx.cs, BL, DL , SP, table structure and test data is uploaded. Please help to find a solution.
Thank you.

CodeDetails.txt
0
Comment
Question by:MadhuMenong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Accepted Solution

by:
MadhuMenong earned 0 total points
ID: 34221446
Dear All,

Found the solution to my promble with was in Stored Procedure "SupplierSearch".

The changed version of the stored procedure is given below:

The error was in the below line which I commented.

--IF @StartRowIndex > 0
--      SET @StartRowIndex =  (@StartRowIndex - 1)  * @MaximumRows




Create PROCEDURE [dbo].[SupplierSearch]
(
        @SupplierName           VARCHAR(50) = NULL, -- default to NULL
        @SupplierCity           INT = NULL,
        @SupplierCountry        INT = NULL,
        @SupplierEmail          VARCHAR(50) = NULL,
        @StartRowIndex                  INT,
        @MaximumRows                  INT,
        @TotalRows                        INT OUTPUT
)
AS
BEGIN
      
DECLARE @first_id int, @startRow INT
DECLARE @StringCity VARCHAR(20)
DECLARE @StringCountry VARCHAR(20)

--IF @StartRowIndex > 0
--      SET @StartRowIndex =  (@StartRowIndex - 1)  * @MaximumRows

IF @StartRowIndex = 0
      SET @StartRowIndex = 1
ELSE
      SET @StartRowIndex = @StartRowIndex + 1



IF RTRIM(@SupplierName)='' OR @SupplierName IS NULL
      SET @SupplierName = '%'
ELSE
      SET @SupplierName = @SupplierName + '%'
      
IF RTRIM(@SupplierEmail)='' OR @SupplierEmail IS NULL
      SET @SupplierEmail = '%'
ELSE
      SET @SupplierEmail = @SupplierEmail + '%'
      
IF RTRIM(@SupplierCity)='' OR @SupplierCity = 0 OR @SupplierCity IS NULL
      SET @StringCity = '%'
ELSE
      SET @StringCity = CONVERT(VARCHAR(20),@SupplierCity)
            
IF RTRIM(@SupplierCountry)='' OR @SupplierCountry = 0 OR @SupplierCountry IS NULL
      SET @StringCountry = '%'
ELSE
      SET @StringCountry = CONVERT(VARCHAR(20),@SupplierCountry)
      

 
       
        SET ROWCOUNT @StartRowIndex
       
        SELECT @first_id = SupplierID FROM Supplier Where
                        (@SupplierName IS NULL OR [SupplierName] LIKE @SupplierName) AND -- If passed only applies to filter
                --(SupplierCity = IsNull(@SupplierCity,SupplierCity)) AND
                --(SupplierCountry = IsNull(@SupplierCountry,SupplierCountry)) AND
               
                 (SupplierCity like @StringCity) AND
                (SupplierCountry like @StringCountry) AND
               
                (@SupplierEmail IS NULL OR SupplierEmail LIKE @SupplierEmail)  
        ORDER BY SupplierID
               
       --PRINT Convert(varchar(30),@first_id) + ' - First ID'
               
            SET ROWCOUNT @MaximumRows
            
        SELECT s.SupplierID, s.SupplierName,ci.CityName AS SupplierCity, co.CountryName AS SupplierCountry,
        s.SupplierEmail,s.SupplierTelephone,s.SupplierAddress1 + ' ' + s.SupplierAddress2 as Address
          FROM Supplier s, City ci, Country co WHERE
                        s.SupplierCity = ci.CityID AND s.SupplierCountry = co.CountryID And
                (@SupplierName IS NULL OR [SupplierName] LIKE @SupplierName) AND -- If passed only applies to filter
--                (SupplierCity = IsNull(@SupplierCity,SupplierCity)) AND
--                (SupplierCountry = IsNull(@SupplierCountry,SupplierCountry)) AND

                         (SupplierCity like @StringCity) AND
                (SupplierCountry like @StringCountry) AND
                (@SupplierEmail IS NULL OR SupplierEmail LIKE @SupplierEmail) AND
                (SupplierID >= @first_id) ORDER BY SupplierID
       
        SET ROWCOUNT 0
       
       
        SELECT @TotalRows = COUNT(*) FROM Supplier
          WHERE
                (@SupplierName IS NULL OR [SupplierName] LIKE @SupplierName) AND -- If passed only applies to filter
--                (SupplierCity = IsNull(@SupplierCity,SupplierCity)) AND
--                (SupplierCountry = IsNull(@SupplierCountry,SupplierCountry)) AND

                        (SupplierCity like @StringCity) AND
                (SupplierCountry like @StringCountry) AND
                (@SupplierEmail IS NULL OR SupplierEmail LIKE @SupplierEmail)
         
       -- PRINT Convert(varchar(30),@TotalRows) + ' - Total Rows'    
       
END

0
 

Author Closing Comment

by:MadhuMenong
ID: 34255627
Bcouz I located the problem and solved it.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question