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

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

Gridview Sorting with SqlDataSource

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


I had a previous post (found here for reference: http://forums.asp.net/p/1573740/3954537.aspx#3954537) Where I was wanting to hide/assign gridviews and datasource dynamically to reduce the page load time. I now have a user requesting that one of those Gridviews be sortable. I have already gone through and added the sort Expression to each column that is created in the code behind. 

I also added a Gridview Sorting Handler

Protected Sub billingGridview_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs) Handles billingGridView.Sorting

But, when I rebind the data, how to I fill in the sort direction and sort Field? The datasource gets its information from a Stored Proc that does not have an Order By (parameter) in it. The websites I have been reading say to use a datatable or dataview and send the sort field and direction to the query. If I dont do all this in the code behind and allow sorting, the gridview is able to handle sorting itself. Is there any way to do this from the code behind? Or am I going to have to rework this with a query that contains a parameter for the sort direction and field?



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.

Sorting Gridview using Jquery with ASP.NET

I want to show how to sorting a gridview using a Jquery in ASP.NET, it is a flexible client-side table sorting. We have known that Jquery is a new kind of Javascript Library. You can find detail of Jquery in this site http://jquery.com/ there are lot of example with documentation and also allow free download a latest version.

Sorting Gridview using Jquery with ASP.NET

used table sorter plug-in which has written by Christian Bach can found http://tablesorter.com/docs/ . It is really cool plug-in and user can allow to download and customization as their wish.

I test this example in Visual Studio 2005. Some of other requirement needed is download a latest version of Jquery from official website and table sorter plug-in which can found as I mention above website.

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 Data in a GridView Web Server Control

The GridView control provides built-in sorting functionality without requiring any coding. You can further customize the sort functionality of the GridView control by using custom SortExpression property values for columns as well as by using the Sorting and Sorted events

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'.

Binding GridView with SqlDataSource at runtime?


Hi, I want to create a generic page which contains a gridview and sqldatasource. I want to put these two controls on .aspx (C#) page but bind them at runtime. It should have selectcommand, updatecommand, deletecommand and insertcommand. Stored procedures are created for that. Help is needed to make it. Please post some link or code. Regards, ap.

Gridview Sorting and Page Orientation


Hi there,

I have looked at several posts on Gridview sorting but can't seem to get it to work in my code. I am using Subsonic objects as the DataSource. Every time I click on a page or sorting link it does a postback but the page orientation is left at the top, not where the gridview is on the page. Is there a way around this?

This is the code I have written for it:

        protected void PublicNoticeGridview_Sorting(Object sender, GridViewSortEventArgs e)
            MidvaleSiteDBDB db = new MidvaleSiteDBDB();
            SqlQuery pubNoticeQuery = db.Select.From<publicnotice>();

Gridview Update outside of SqlDatasource


Is it possible to use a SQLDataSource to populate a gridview but not use the SQLDataSource for Updating?

I wanted to add the update code in the Gridview_RowUpdating event since it is a complex update I need to do.

I get this message when i click the update button

Updating is not supported by data source 'SqlDataSource1' unless UpdateCommand is specified.

Return value from SqlDataSource in GridView ?

Hi, everyone. I have textbox for searching a Names in My database. I return the information from the Select Statement in  GridView, but i want to know the number of affecter rows. How to do that?

Gridview (bound by ObjectDataSource) Sorting - VB.NET

Hello.. I have a gridview being data bound by an objectdatasource which points to a BLL/DAL.  I have paging and sorting enabled within the gridview. I have the fields configured in the look/fell I want from a templatefield.  This templatefield has the sort expression (date) I want things to be sorted by. All this works as it should and I have no issues with it. But, the issue is that when I click on the header to sort asc/desc by date, I have to click on it twice for it switch to descending order.  E.g.  I hit the webpage and it lists all the information in the gridview, sorted by date, ascending order.  If I want to sort by descending order, I have to click the date header twice in order for the gridview to sort the information in descending order; the clicks cause a post-back and the whole screen is refreshed. Any ideas why this may be occurring?  Thanks.. -Jeff  

Up Down GridView Icon Image for Column Sorting

I'm trying to add an Ascending and Descending sort direction Icon Image next to the header text of my ASP.NET 2.0 Gridview Columns.I've searched and found some examples that seem to do this but have had difficult time recoding them from C# to VB or some just seemed overly complex for what I want to do.Does anyone have a simple VB solution for sort icons?Thanks,Ethan   

Sorting in Data GridView using c#

Sallam & Hi to all,well i m making a project in asp .net c# i used data gridview which is bound at run time after many calculations... problem occured when i want to sort it.. anybody help me...ThanksSaqib

Binding Web Service Result in asp:gridview and enable sorting(paiging)

Hello everyoneI have web service and gridviewI'm binding it without problemcode: protected void Page_Load(object sender, EventArgs e) { GetCallsService wservice = new GetCallsService(); List<Call> list = wservice.getCalls(2); GridView1.DataSource = list; //GridView1.AllowSorting = true; GridView1.DataBind(); } But I want to enable sorting and(or) paging.   GridView1.AllowSorting = true; this doen't solves problem.everything worls fine if I'm usign sqlDatasource but when datasource is web service it doesn't wokdoes enyone know solution?

Textbox -> value -> gridview -> Sqldatasource?

Hi guys. I have textbox that searches for first or last name. Result show in gridview. But when add value in text box and push my button Find nothing happen. Here code: aspx:   ........ <asp:GridView runat="server" AllowPaging="True"                   AutoGenerateColumns="False" DataKeyNames="MobileNum"                   DataSourceID="SqlDataSource5" style="font-family: Verdana"                          onselectedindexchanged="GridView1_SelectedIndexChanged">         <Columns>                         <asp:BoundField DataField="FNAME" HeaderText="FNAME" SortExpression="FNAME" />             <asp:BoundField DataField="LNAME" HeaderText="LNAME" SortExpression="LNAME" />          &nb
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