.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

Datatable sort in a particular order

Posted By:      Posted Date: October 22, 2010    Points: 0   Category :ASP.Net

How do I sort a data table based on a particular column which has integer values in ascending order?


I wrote this:

leadtable.DefaultView.Sort = "Id"

But it doesnt seem to work, it displays fine but when i get try to get the values of the sorted datatable in an array they dont come in an sorted ordere

Datatble is defined as:


  • leadtable = New DataTable("LeadTable")   
  •         Dim leadid As New DataColumn("Id")   
  •         leadi

    View Complete Post

  • More Related Resource Links

    What is the meaning of Ascending\descending sort order of a column within an index

    When I add a new index I can also specify the "sort order" as ascending or descending. What does it mean? does it affect performance? does it mean that the binary search tree will be set in a certain way?

    Dynamic Data Entity Framework: Initial Sort Order for Views

    Hello Steve,I'm trying to set an initial sort order for my View (not table) in Dynamic Data using Entity Framework 2. I have updated my Model and Imported the View. Now I'm trying to use the DisplayColumn attibutebut it's not working.[DisplayColumn("Product", "ParsingOrder", true)]Fabio

    Dundas Map - Legend sort order

    ello, We are using Dundas Maps together with Reporting Services 2008. Now we have come across a problem which we are not able to solve ourselves.   We produce a map showing each countries “ReportingFormat”. The SQL in the background  has the “order by ReportFormat” clause.   The values available in “ReportFormat” are shown in the legend. So far everything looks fine and the values within the legend are ordered correctly (E2B, Intdis, Not specified). See the picture http://img340.imageshack.us/i/correctorderfrompreview.jpg/   We therefore deploy the report and open it up in Internet Explorer but now the order of the legend has changed and is shown as (Intdis, Not specified, E2B). See the picture http://img816.imageshack.us/i/incorrectorderfromie.jpg/   We have tried to set the sorting also within the map (not only within the SQL) but the same problem remained although we are not sure we set that sorting correctly . We are not sure that we found the series collection where we could set the sort order. It is all a bit confusing when working with the maps.   As a final solution we tried to change the available values in “ReportFormat” but then the order was even more confusing. See table below; Available values (ReportFormat) Order in legend in Visual studio preview Order in legend in Internet

    order by sort both select in union



    I have DropDownList that Show all groups. in that, I want to show "select one group" as default in DDL. for that i used code below. but it sort all return data and "select one group" will not be the first line. How can i fix it?

    Best Regards. Morteza


    	SELECT   -1 as id,'select one group' as groupName
    	SELECT   id, groupName
    	FROM     [group] 
    	order by groupNam

    SSRS 2005 and Sort Order

    I have a table and want to sort the 1st column which is called "WorkType" in a particular order. At present it looks like this.

    Admin Tasks
    Leave & Public Holiday

    managed metadata sort order for swedish


    Sort order for managed metadata is not as expected, for instance Swedish letters Å and Ä are sorted as A

    The properties for the standard language is set to swedish and explicit sort order is not set.

    Is this a bug, or are we doing something wrong?


    Microsoft SharePoint Server 2010 (14.0.4763.1000)

    Language Pack for SharePoint, Project Server and Office Web Apps 2010 - Swedish/svenska (14.0.4763.1000)

    Persist sort order in datagrid



    I've got multiple datagrids in the application I'm currently working on. Their ItemSource can be updated with new content on server notifications. When this happens, the ItemSource is being replaced by a new one (would it be better to update the content of the ItemSource - which is much more complicated for this case of figure - instead of binding a new one?)

    When the new ItemSource is being bound, the sorting of the grid is being lost. I've solved this behaviour by saving the sorting before setting the new binding and restoring it after the new binding has been done. Below you'll find the static methods used for that:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Windows.Controls;
    using System.Windows.Data;
    using Telecontrol.SIPPR.Client.Commons.DataObjects;
    namespace Telecontrol.SIPPR.Client.Commons.Utils
      public static class DataGridUtil

    SharePoint 2010 library sort order is incorrect.


    When sorting by name in a SharePoint 2010 library, numeric results are sorting incorrectly. For instance "122_Test" will sort in front of "13_Test". I know at one point years ago Windows Explorer had the same issue, but when viewing the same library by using the Open with Explorer option, Windows Explorer correctly displays the results. Has anyone encountered this issue, and if so have you found a fix?


    Tim Vander Kooi

    In RB 2.0 how to sort in ascending/descending order as default?

    I have column say of Provider Type which I want to be ordered when report is run so that all other columns are ordered according to the order of the Provider Type values.

    DataTable and it's Gridview - A Column Order Question


    Well, I've been developing with gridviews for quite some time now.  Just recently I came across a situation that has me stumped.  Here's how the gridview has been working for me.


    1.      A stored procedure from the database is called (three parameters are passed (reporttype, name, location)

    2.     The data is retrieved using the SqlDataAdapter to fill a Datatable


    4.     Columns are created programmatically as it reads the DataTable results (headertext, datafield, and dataformatstring are set at runtime)

    5.     The Gridview triggers the databind event - and voila it works.


    My dilemma is this:  the stored procedure (that I haven't developed) returns a various set of columns and column order.  I have one report type that does the following:


    ReportType 1:  column orders returned in the following order when running directly in SQL

                col B, col C, col D, col E, col A


    when I run the report through my gridview, the column order is as follows:


    WPF: how to make a GridView only sort on one column as ascending order?


    We use GridView inside the Listview. We need the grid view alwasy sort on one column ascending order and not allow to click column header to change it.

    Is there a easy way to achieve it in Xaml?

    If not possible, how to achieve it in code behind?



    Sort datatable


    How do I sort a data table based on a particular column which has integer values in ascending order?


    I wrote this:

    'Sort the datatable based on sequence id

    leadtable.DefaultView.Sort ="Id"

    But it doesnt seem to work

    Datatble is defined as:

    leadtable = New DataTable("LeadTable")
            Dim leadid As New DataColumn("Id")
            leadid.DataType = GetType(Integer)
            leadid.Unique = True
            leadid.AllowDBNull = False
            leadid.Caption = "Id"
            Dim leadname As New DataColumn("Name")
            leadname.DataType = GetType(System.String)
            leadname.AllowDBNull = False
            Dim leadsizeget As New DataColumn("Size")
            leadsizeget.DataType = GetType(Integer)
            leadsizeget.AllowDBNull = False
            leadtable.PrimaryKey = New DataColumn() {leadid}


    How can I use ORDER BY by passing different columns and sort orders?


    Hi all

    Here is what I am trying to do:

    declare @dateBegin as datetime, @dateEnd as datetime
    declare @column as varchar(30), @order as varchar(4)
    set @dateBegin = null
    set @dateEnd  = null
    set @column  = 'created'
    set @order   = 'DESC'
    	(@dateBegin is null or startTime >= @dateBegin) and (@dateEnd is null or endTime <= @dateEnd)

    list dropdown sort order


    i have a list in that i have a column called startdate (date field) which has dropdown values showing as ascending, descending, empty then it is showing all the dates in ascending order i want to show this in descending order in the dropdown , can you please help how can i get this done, please let me know if you don't understand i will explain further

    thanks in advance for the help

    How to sort GridView?

    In this article I will discuss how to sort columns in grid and more. At the end it will help answer some very frequently asked questions like following

    How to bind GridView and DropDownList controls using DataTable object

    In .net framework 2.0, you can load a DataTable in memory by consuming a data source using a DataReader. In this version you will find the flexibility in accessing the DataReader means write access code once and use again and again using DataReader. To see the functionality of DataTable consider an example that is created using VS2005.
    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