Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6077273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:42:09+00:00 2026-05-23T10:42:09+00:00

I have been trying to find a good solution googling around and i am

  • 0

I have been trying to find a good solution googling around and i am having little success on my current project to implement custom paging and Sorting on an ASp GridView Control (.NET 4.0).

This is the most current site i have attempted to use as a base to complete this task:
http://www.codeproject.com/KB/webforms/GridViewCustomPaging.aspx

The biggest problem i have with this solution is that his example FirstID is an integer also his ProductID and I am using GUID’s as my uniqueidentifier. This is obviously causing issues when I try to order by this or anything like that. I tried using another colum (AesExt varchar(50) ) but that is not working either, basically, it keeps saving the top row row for some reason. I also need to implement sorting, so when i get the procedure back in C#, I am stuffing it into a Datatable and using DataView to do the sorting. I was wondering if anyone out there had a better solution for this scenario they could share or show me what I am doing in correctly. I was also trying to find a good way to do the sorting in the procedure, but it won’t work because my boss wanted extension as varchar(50) because there are none entries (personally i think it should be 0). So when I try to sort by AesExt, when i want to convert to int so the sort works right, it will blow up at none and i know looping in a procedure is a no no, so I’m stuck doing that in C# code I think.

Store procedure

USE [Inventory]
GO
/****** Object:  StoredProcedure [dbo].[usp_GetExtList]    Script Date: 06/26/2011 21:07:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[usp_GetExtList]
    -- Add the parameters for the stored procedure here
@startRowIndex INT,
@maximumRows INT, 
@sortExpression AS VARCHAR(50),
@sortDirection AS VARCHAR(50),
@totalRows INT OUTPUT

AS

DECLARE @first_id INT
DECLARE @startRow INT

SET @startRowIndex =  ((@startRowIndex - 1)  * @maximumRows) +1

IF @startRowIndex = 1 
SET @startRowIndex = 1


SET ROWCOUNT @startRowIndex

SELECT @first_id = AesExt FROM ExtItem 

PRINT @first_id
SET ROWCOUNT @maximumRows

SELECT ExtensionGUID, AesExt,Name FROM ExtItem WHERE 
AesExt >= @first_id

/*ORDER BY CASE WHEN @sortExpression ='Name' AND @sortDirection = 'Ascending' THEN Name
                END ASC,
         CASE WHEN @sortExpression = 'Name' AND @sortDirection='Descending' THEN Name
                END DESC,
         CASE WHEN @sortExpression = 'AesExt' AND @sortDirection = 'Ascending' THEN AesExt
                END ASC,
         CASE WHEN @sortExpression = 'AesExt' AND @sortDirection='Descending' THEN AesExt
                END DESC,
         CASE WHEN @sortExpression = 'AgentExt' AND @sortDirection = 'Ascending' THEN AgentExt
                END ASC,
         CASE WHEN @sortExpression = 'AgentExt' AND @sortDirection='Descending' THEN AgentExt
                END DESC
 */

     SET ROWCOUNT 0

— Get the total rows

SELECT @totalRows = COUNT(ExtensionGUID) FROM Extitem

C# Code

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindData();
    }

    #region BIND DATA

    private void BindData()
    {
        string connectionString = @"Server=localhost\SQLEXPRESS;" + "Database=Inventory;Trusted_Connection=true";

        SqlConnection myConnection = new SqlConnection(connectionString);
        SqlCommand myCommand = new SqlCommand("usp_GetExtList", myConnection);

        myCommand.CommandType = CommandType.StoredProcedure;

        myCommand.Parameters.AddWithValue("@startRowIndex", currentPageNumber);
        myCommand.Parameters.AddWithValue("@maximumRows", PAGE_SIZE);
        myCommand.Parameters.AddWithValue("@sortExpression", SortExpression);
        myCommand.Parameters.AddWithValue("@sortDirection", GridViewSortDirection);
        myCommand.Parameters.Add("@totalRows", SqlDbType.Int, 4);
        myCommand.Parameters["@totalRows"].Direction =
                           ParameterDirection.Output;

        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(myCommand);

        //DataSet ds = new DataSet();
       // ad.Fill(ds);
        DataTable dataTable = new DataTable();
        sqlDataAdapter.Fill(dataTable);

        DataView dataView = new DataView(dataTable);
        dataView.Sort = "AesExt ASC";
        gvProducts.DataSource = dataView;
        gvProducts.DataBind();

        // get the total rows 
        double totalRows = (int)myCommand.Parameters["@totalRows"].Value;

        lblTotalPages.Text = CalculateTotalPages(totalRows).ToString();

        lblCurrentPage.Text = currentPageNumber.ToString();

        if (currentPageNumber == 1)
        {
            Btn_Previous.Enabled = false;

            if (Int32.Parse(lblTotalPages.Text) > 0)
            {
                Btn_Next.Enabled = true;
            }
            else
                Btn_Next.Enabled = false;

        }

        else
        {
            Btn_Previous.Enabled = true;

            if (currentPageNumber == Int32.Parse(lblTotalPages.Text))
                Btn_Next.Enabled = false;
            else Btn_Next.Enabled = true;
        }
    }

Any help is greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:42:09+00:00Added an answer on May 23, 2026 at 10:42 am

    This has been abandoned and we are now using Select Top as the stored procedure. Word to the wise when using a GridView… it’s all or nothing, so we are just going to use it to make it look nice and handle all the data handling

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to find a good solution to this problem for a
I have been looking around for hours trying to find a clear simple solution
I have been trying to find a good guide to create a templated control.
I have been trying to find a solution to this one but could not
I have been trying to find decent Image Acquisition + Image Processing solution at
I have been trying to find if i can easily isolate and test azure
I have been trying to find ways to solve the problem. Firebug said syntax
I have been trying to find out how game engines deal with asset compression.
I have been trying to find a code snippet to do an unsharp mask
I have been trying to find out why the following lines of code do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.