.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Paging and sorting using different columns

Posted By:      Posted Date: September 26, 2010    Points: 0   Category :ASP.Net


Situation: SQL database, Linq to SQL class a ASP.NET page with a LinqDataSource and a gridview.

The table has a ID field, a date field and a Serialnr field.

In my Grid I like to Page on the datefield but to sort on the serialnr field (or a selectable other field.)

Is that possible? Standard the paging is always done on the sort field and when you select a different sort field the page jumps back to the first page, and paging is then done over the sorted column.


View Complete Post

More Related Resource Links

AJAX GridView Paging and Sorting using C# in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Sorting/Paging : 'REAL' AJAX with Asp.Net Series

This is a continuation of my 'REAL' AJAX with Asp.Net (not Asp.Net AJAX) series posts for those of us trying to stop relying on Asp.Net 'AJAX'.

Ok, nothing too dramatic to start things off, we are going to make some tabled data sortable and pagable all without using a bit of postback. Not only that, but it is going to be incredibly easy!

Sorting GridView Columns Manually

We all know that GridView columns can be sorted automatically when SQLDataSource is being used. But what if you are not using SqlDataSource to populate the GridView. Sorting the GridView manually is pretty straight forward task take a look at the code below

Manually sorting and paging Gridview without using datasource control

Many a times while working with Gridview we want to work with the paging and sorting functionality without using any datasource control. Gridview is flexible enough to perform these tasks without the use of any datasource control and only a few lines of code.

Optimized Paging and Sorting in ASP.NET GridView

In this article I am going to demonstrate what are the performance drawbacks of using conventional way to page and sort your GridView and then I will demonstrate 'An Optimized way to implement Paging and Sorting'.

How to handle sorting and paging when objectdatasource is being built dynamically?

i am building my objectdatasource dynmically when certain buttons are clicked on the page.. and with that the gridview is being displayed with the results of the objectdatasource that was built. So my gridview code looks like this: <asp:GridView ID="GridView1" runat="server" Visible="False" Width="85%"> <EmptyDataTemplate> There are no results for your search. Please try again. </EmptyDataTemplate> </asp:GridView> How can i enable sorting and paging if the datasource is being built on button click event?

maintain sorting data during paging

when i sort the grid and it is display in sorted order and when i go to next page it will show data in default order. how to maintain sorting order duing paging

Set the sorting properties of gridview true but still columns are not becoming links



I have to do a sorting on headers of the gridview.

i have set the sorting property to true and also implemented the onsorting event.

But my headers are not coming up as links,what could be the reason?

Paging on a different column than the sorting column



Situation: SQL database, Linq to SQL class a ASP.NET page with a LinqDataSource and a gridview.

The table has a ID field, a date field and a Serialnr field.

In my Grid I like to Page on the datefield but to sort on the serialnr field ( or a selectable other field).

Is that possible? Standard the paging is always done on the sort field and when you select a different sort field the page jumps back to the first page., and paging is then done over that sorted column.



Sorting and Paging in DataGrid which is inside asp:wizard



Would it be possible to do Sorting and Paging in a DataGrid, My dataGrid is place inside an asp:wizard which is inside an Update Panel.

<asp:UpdatePanel ID="upEditusr" runat="server">
<asp:Wizard ID="Wizard1" runat="server" CssClass="wizUsrAccess" displaycancelbutton="True" 
              oncancelbuttonclick="OnCancelButtonClick" onfinishbuttonclick="OnFinishButtonClick" OnNextButtonClick="OnNextButtonClick" ActiveStepIndex="0" BorderWidth="1px" DisplaySideBar="false">
               <asp:Label ID="SideBarInfo" OnPreRender="InitSideBarLbl" runat="server" /> 
               <asp:DataList ID="SideBarList" OnPreRender="LoadSideBar" RepeatLayout="Flow" Style="display:none;" runat="server"> 
                       <asp:LinkButton ID="SideBarButton" Visible="false" runat="server"></asp:LinkButton> 
                   <SelectedItemStyle Font-Bold="True"  />            

Gridview cancel,sorting,paging


Please can you give me the code for gridview sorting,paging and cancel and please also explain methe code for each line.....otherwise i wont understand the code

SPGridView grouping not working with sorting or paging


Anybody can help with the issue here? I have a SPGridView using ObjectDataSource with grouping, sorting and paging enabled. Once i clicked on the next button or the sort header, it's give the "An unexpected error has occurred." on screen. 

Error in the 12 hive logs
Application error when access /Web Pages/TestGridView.aspx, Error=Value cannot be null.  Parameter name: container
at System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName)
at Microsoft.SharePoint.WebControls.SPGridView.OnRowCreated(GridViewRowEventArgs args)
at System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource)
at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at Microsoft.SharePoint.WebControls.SPGridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
at System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls()
at System.Web.UI.Control.EnsureChildControls()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()

Sorting or Grouping by "External Data" columns secondary fields - only possible for certain value ty


I have a BCS connection to an external system that provides various external data types.

I'm now adding an "External Data" column to a SharePoint list, selecting multiple fields of an external data type to be added as list columns. These fields have different data types, in my case string, DataTime and Boolean.

Editing the list view settings, I can only select the external entity as a whole, or it's Boolean fields for either "Sort By" or "Group By". The other fields are not offered for selection.

Is there any restrictions on which secondary fields of an external data type are supported for either sorting or grouping? Or is there something wrong in the definition of some of the external data type fields?

Thanks in advance for any help on this issue...

Run javascript before sorting or paging the datagrid


Here is what I am trying to do;

I want it so that when the user clicks on the datagrid column headers to sort the records, or when they go to page the datagrid, that a confirmation pop-up appears first, confirming that their changes are going to be lost (unless they click "Cancel").

I have the confirmation pop-up scripted in Javascript and is added to the controls on the page using

onClientClick="return ConfirmDiscardChanges();"

How do I attach this to a datagrid header and to the pager?

Do the columns need to be Template columns and the header text being hyperlink?  If so, how do I set it up so it will, if the user clicks "OK" in the confirmation pop-up,  still sort?


Custom paging sorting stored procedure problem



I want to make my gridview enable for custom paging and sorting. I started to follow a tutorial and write the Stored procedure.

But my stored procedure seems not to be working. here it is:

ALTER PROCEDURE [dbo].[USP_getStudentsEmail]
    @sortExpression nvarchar(100),
    @startRowIndex int,
    @maximumRows int,
    @receiver nvarchar(38)

IF LEN(@sortExpression) = 0
    SET @sortExpression = 'SendDate'

DECLARE @sql nvarchar(4000)
SET @sql = 'Select *
	Select m.Body,m.Subject,m.SendDate,m.SenderProfile,m.Receiver AS Receiver,m.ID,s.FirstName,ROW_NUMBER() OVER (ORDER BY '+ @sortExpression + ') AS RowRank 
	from Message m INNER JOIN StudentProfile s ON m.Sender=s.UserId
) AS OrderedEmails
            WHERE     m.Receiver= '+ CONVERT(nvarchar(38), @receiver) + 'AND RowRank > ' + CONVERT(nvarchar(10), @startRowIndex) +
                ' AND RowRank <= (' + CONVERT(nvarchar(10), @startRowIndex) + ' + '
                + CONVERT(nvarchar(10), @maximumRows) +')'

EXEC sp_executesql @sql

I tried to run this by the following line

exec USP_getStudentsEmail 'SendDate',1,1,'5ed19f91-eeb7-4c6a-b564-98c8dd83e18c'

but it says  

Incorrect syntax near 'd19f91'-

can anybody help

Any Paging, Sorting Gridview solution out there that will fit my needs????????????


Hi all,

I have found and tested many samples out there and later realized they were not working because my Gridview is actually binding to a DataTable.
The reason for that is that before binding it I am adding extra columns in my DataTable.

I am looking for a good sample code which will show me how to show a Gridview with Sorting and Paging features. I know that can easily be done with SqlDataSource, ObjectDataSrouce or even LINQ to SQL but since I am modifying the Table structure on the fly I am not sure how to implement Paging and Sorting in this situation.

Here is part of my code:

		//Load New values from table
		DataTable dtNewRecords = FillDataGridView_JobHistory(dateBegin, dateEnd, jobName, clientName);

		if ( dtNewRecords != null )
			//Finally bind the gridview
			GridView2.DataSource = dtNewRecords;

			//Sort by the selected column
			dtNewRecords.DefaultView.Sort = (String)ViewState["SortExpression"] + " " + (String)ViewState["SortDirection"];

Thank you!

How to implement paging and sorting in asp.net Gridview control?

In this article, I will explore how to implement paging and sorting in gridview control without using sql and object data sources.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend