DataTable.DefaultView.Sort Doesn't Seem To Be Working?
Feb 19, 2010
I populate a DataTable, then sort the DefaultView of that DataTable. When I set the DataTable as the source for my report, the sort doesn't work. here is the code (GetData returns a valid DataTable):
Dim dt As DataTable = a.GetData(Parm1, Parm2, Parm3)
If rbtSortByField1.Checked Then
dt.DefaultView.Sort = "Field1 ASC"
ElseIf rbtSortByField2.Checked Then
dt.DefaultView.Sort = "Field2 ASC"
ElseIf rbtSortByField3.Checked Then
dt.DefaultView.Sort = "Field3 ASC"
End If
rpt.SetDataSource(dt.DefaultView.Table)
'This also doesn't work
'rpt.SetDataSource(dt)
I'm looking for a way to sort the rows of a datatable without setting the DefaultView.Sort to a specific column. I have a datatable in session that users can add records to. I want them to be able to sort the data by clicking on a button. But new records added after that need to show up at the bottom of the list until the sort button is clicked again.
I have a Listview control that DataBind programatically... ie I am NOT using SqlDataSource or such... I am attempting to sort a column... clicking on a link button that fires the "Sorting" event. So, after cliking on the column heading... I end up in this routine, where I hardcoded the .Sort = values (just for testing). The code is executed... but the RESULT show via Listview remains the SAME. No change!
How to fix this? I've seen some other posts examples that uses this event (ListView1_Sorting) and then sort via LINQ. I am not ready to try that...
Just want to know why dsPaymentList.Tables[0].DefaultView.Sort does not work?
I have a datatable and I want to have a view on it with unique dates. The thing is that I want the date to be unique if the year,month and day are the same, I dont care for the exact time.
I now have:
Dim dtUniqueDates As System.Data.DataTable dtUniqueDates = dt.DefaultView.ToTable(True, "updatedate")
So in this case 12 february 2011 13:54 is different from 12 february 2011 15:54. But since year,month and day are the same I want them to be unique.
Is it possible that once I have created a datatable programatically, I can then sort that datatable before binding it to a asp:repeater? I have a number of records that I have to get from a com object that has not been eliminated. The com object populates an array, then I loop through the array to pull data from my datatbase, adding the db data to the datatable. Then I bind the datatable to a repeater.
1) the array is multidimensional 2) The COM object doesn't sort the data by company ID (which is what I need to do)
I have seq no col in the datatable.how can i order by the seq no so that re-arrage the datatable.or other method have the sort function.and then bind to repeater.
I have a repository that contains all of my LINQ queries for this project that I am working on. I am able to get the LINQ results to a DataTable and bind that to a gridview for displaying the data. Now I need to make the gridview sortable. I have set AllowSorting="true" and I have the OnSort event handled in a routine in the codebehind.
I have got a datatable which contains many columns in which three are main:
hotelid dshotelid hotelname
Some hotels contain only dshotelid, some contains only hotelid and some contain both dshotelid and hotelid.
I need sort in such way so that those hotels who got both dshotelid and hotelid should be on top and then those hotels who have got only dshotelid and at last those hotels who have got only hotelid...
How to Sort The datatable in asp.net. after binding the dataset values i have stored into one table how can i sort the values of the dataset in asp.net with C#
I am trying to sort a DataTable. If I declare a DataView and use the following approach it works perfectly:
Dim dt As DataTable = getData() Dim dv2 As New DataView(dt) dv2.Sort = "surname, name" dt = dv2.ToTable
I wanted to do this without using a DataView though if possible to reduce the impact on resources. I tried the following approach but it doesn't work. I might be writing the code wrong so
Dim dt As DataTable = getData() dt.DefaultView.Sort = "surname, name"
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:view plaincopy to clipboardprint?
now i use the dataview to sort the seq of datatable and bind to repeater, it can only display the seq correctly.but i found that it is not the actual database seq, when i remove the row from the datatable, it is not remove the record that i see from the UI.do i need to sort the seq to the actual datatable not the dataview.now i use the seq (int) in datatable to sort the datatable as belows:
The values are number but varchar, for example '100', '73', '87'. When i see the data this return 100, 87, 73, when should by 73, 87, 100 how can i sort the data????
Tried several different ways to do this but am just not seeing it. Proably a quick solution for someone more skilled than me.
I have a gridview generated from a datatable. One of the columns is "client name" whose data is generated from a class.
I added a link button for the column header that fires a sub that should sort the datagrid, but is not.
Here is the code I have so far that creates the gridview which works fine:
Private Sub PopulateCaseListGrid() 'Kill the existing DataSource, in case of a page reload gvCaseList.DataSource = Nothing 'Create a datatable with whatever column you want to use
I have a page which lists all the files in a particular folder (all PDFs), using a data-table and gridview.
I'm currently sorting this table by the filename (by using a dataview), which isn't that helpful, and I want the gridview of files sorted by the file created or file modified date (as recorded in Windows).
If that's not possible, a second option would be to extract the date from the file name string (no problem doing that), and sort the dataview/datatable or gridview based on that. Example Filename: DailySalesReport-1-15-2010. My only hangup with this is how do I sort on date, when it's a string value? Convert to date? How would I sort the whole dataset based on this converted value?
I want to orderby the list. Today date is on the top and then next date and all dates but when today date is passed then it comes on the end of the list. Is there any formal query in linq or some other code is used to achieve this?
08/01/2015 09/01/2015
but when today is passed then it automatically go to end and next today date is on the top
I have been struggling with this problem for a long time. Does anyone have any clue about this problem? I created a gridview and set the allowsorting to true. This gridview has four columns: Name, Position, StartDate, and EndDate. I want the gridview to be sorted on the EndDate.
Inside of the save event, I called the BindGrid() function to rebind the datasource to the gridview. The changes will shown immediately, but the problem is that the records are not sorting on EndDate. I have to refresh the page manually to get the view sorted.
the datatype in my database is Varchar, so that my gridview Sorting Function doesn't sort correct in sequence 1,2 3, 3 but 1,10,100, how can I sort in sequence 1,2,3,4 but no changing the datatype in database?
My Gridview sort is working only first time. My Gridview sort only first time when I click on any column
I want ASC > DESC
Again DESC > ASC
and Again ASC > DESC this way my sort should work
I have changed my code
I added Gridview binding to PAge_Load function
Code is below
Public Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim myUserInfo As GCS_User_Info = Session("UI") If Not Page.IsPostBack Then GRDView.DataSource = GetSortableData(String.Empty) 'System.Drawing.FontFamily.Families GRDView.DataBind()