473,398 Members | 2,212 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

sorting a datagrid

Hello!

I need help in making my datagrid sortable by clicking a column header.

In the datagrid's property builder, Allow Sorting is checked. I am using a
Bound column and it's Sort Expression is set to the same value as the Data
Field value. But I dont know how to implement:

private void dgResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{

}

Please help.
Nov 17 '05 #1
1 1269
Hi,

How you fill the datagrid?, are you using a datatable?

If you're using a datatable you can use this code:

//When you get the data from (for instance :database)

DataView dv = new DataView();
dv=Yourdatatable.DefaultView;
Page.Session.Add("DataViewOriginal",dv);//put into the session the view
this.DataGrid1.DataSource=dv;//assign the data source
this.DataGrid1.DataBind();
//In your sortCommand method
if(Page.Session["DataViewOriginal"]!=null) //if exists the dataview in the
session
{
DataView dv=(DataView) Page.Session["DataViewOriginal"]; //take the view
dv.Sort=e.SortExpression;//sort the view by the name of the column header
clicked
this.DataGrid1.DataSource=dv; //assign the source
this.DataBind(); //show the info
}
Hope this helps.
Regards.
josema.

"Newbie" wrote:
Hello!

I need help in making my datagrid sortable by clicking a column header.

In the datagrid's property builder, Allow Sorting is checked. I am using a
Bound column and it's Sort Expression is set to the same value as the Data
Field value. But I dont know how to implement:

private void dgResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{

}

Please help.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
3
by: melanieab | last post by:
Hi, I'm programatically sorting in a datagrid. When a column header is clicked, the sort happens twice for some reason, making it looks like it only sorts in descending order. I can tell it...
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
2
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
8
by: simchajoy2000 | last post by:
I thought the only thing I had to do to disable column sorting in VB.NET was to set datagrid.AllowSorting = False. Unfortunately this has never worked for me. I discovered another set of code...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.