473,794 Members | 2,738 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sorting a datagrid in descending order

i am able to allow the user to sort the columns of my datagrid, but only in
ascending order. is there a way to allow sorting in descending order? thanks
in advance.

private void Page_Load(objec t sender, System.EventArg s e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(c onnStr);
SqlCommand sqlCMD = new SqlCommand(sTOD S);
sqlCMD.Connecti on = sqlConn;
sqlConn.Open();
SqlDataAdapter adapter = new SqlDataAdapter( sqlCMD);
DataSet ds = new DataSet();
adapter.Fill(ds );
dgSearchResults .DataSource = ds.Tables[0];
int tableRowCount = ds.Tables[0].Rows.Count;
if (tableRowCount != 0)
{
DataView dv = new DataView();
dv=ds.Tables[0].DefaultView;
Page.Session.Ad d("DataViewOrig inal",dv);
dgSearchResults .DataSource=dv;
dgSearchResults .DataBind();
dgSearchResults .Visible = true;
}
else
{
dgSearchResults .Visible = false;
}
}

private void dgSearchResults _SortCommand(ob ject source,
System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
{
if(Page.Session["DataViewOrigin al"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOrigin al"];
dv.Sort=e.SortE xpression;
dgSearchResults .DataSource=dv; //assign the source
dgSearchResults .DataBind();
}
}

Nov 17 '05 #1
4 2864
hi

I don;t know how you are declaring the datagrid itself, but all you have
to do is add an ASC or DESC to the SortExpression.

IIRC the SortCommand of the datagrid does not allow to especify it, so you
may will need to find another approach or a work around. like keeping in
session the last kind of sorting you did and just do the opposite.

let me know if you need some ideas.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Newbie" <Ne****@discuss ions.microsoft. com> wrote in message
news:FC******** *************** ***********@mic rosoft.com...
i am able to allow the user to sort the columns of my datagrid, but only in
ascending order. is there a way to allow sorting in descending order?
thanks
in advance.

private void Page_Load(objec t sender, System.EventArg s e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(c onnStr);
SqlCommand sqlCMD = new SqlCommand(sTOD S);
sqlCMD.Connecti on = sqlConn;
sqlConn.Open();
SqlDataAdapter adapter = new SqlDataAdapter( sqlCMD);
DataSet ds = new DataSet();
adapter.Fill(ds );
dgSearchResults .DataSource = ds.Tables[0];
int tableRowCount = ds.Tables[0].Rows.Count;
if (tableRowCount != 0)
{
DataView dv = new DataView();
dv=ds.Tables[0].DefaultView;
Page.Session.Ad d("DataViewOrig inal",dv);
dgSearchResults .DataSource=dv;
dgSearchResults .DataBind();
dgSearchResults .Visible = true;
}
else
{
dgSearchResults .Visible = false;
}
}

private void dgSearchResults _SortCommand(ob ject source,
System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
{
if(Page.Session["DataViewOrigin al"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOrigin al"];
dv.Sort=e.SortE xpression;
dgSearchResults .DataSource=dv; //assign the source
dgSearchResults .DataBind();
}
}

Nov 17 '05 #2
there are 8 columns (all sortable). i'm not sure using 8 session variables to
store everything is the way to go.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
hi

I don;t know how you are declaring the datagrid itself, but all you have
to do is add an ASC or DESC to the SortExpression.

IIRC the SortCommand of the datagrid does not allow to especify it, so you
may will need to find another approach or a work around. like keeping in
session the last kind of sorting you did and just do the opposite.

let me know if you need some ideas.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Newbie" <Ne****@discuss ions.microsoft. com> wrote in message
news:FC******** *************** ***********@mic rosoft.com...
i am able to allow the user to sort the columns of my datagrid, but only in
ascending order. is there a way to allow sorting in descending order?
thanks
in advance.

private void Page_Load(objec t sender, System.EventArg s e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(c onnStr);
SqlCommand sqlCMD = new SqlCommand(sTOD S);
sqlCMD.Connecti on = sqlConn;
sqlConn.Open();
SqlDataAdapter adapter = new SqlDataAdapter( sqlCMD);
DataSet ds = new DataSet();
adapter.Fill(ds );
dgSearchResults .DataSource = ds.Tables[0];
int tableRowCount = ds.Tables[0].Rows.Count;
if (tableRowCount != 0)
{
DataView dv = new DataView();
dv=ds.Tables[0].DefaultView;
Page.Session.Ad d("DataViewOrig inal",dv);
dgSearchResults .DataSource=dv;
dgSearchResults .DataBind();
dgSearchResults .Visible = true;
}
else
{
dgSearchResults .Visible = false;
}
}

private void dgSearchResults _SortCommand(ob ject source,
System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
{
if(Page.Session["DataViewOrigin al"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOrigin al"];
dv.Sort=e.SortE xpression;
dgSearchResults .DataSource=dv; //assign the source
dgSearchResults .DataBind();
}
}


Nov 17 '05 #3
hi

you need only one.

or two at the most, one to decide which column and the other to decide
asc/desc if in a postback the column var is the same you change the asc/desc
if not change the column and do not change the asc/desc

is it clear now?

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Newbie" <Ne****@discuss ions.microsoft. com> wrote in message
news:85******** *************** ***********@mic rosoft.com...
there are 8 columns (all sortable). i'm not sure using 8 session variables
to
store everything is the way to go.

"Ignacio Machin ( .NET/ C# MVP )" wrote:
hi

I don;t know how you are declaring the datagrid itself, but all you
have
to do is add an ASC or DESC to the SortExpression.

IIRC the SortCommand of the datagrid does not allow to especify it, so
you
may will need to find another approach or a work around. like keeping in
session the last kind of sorting you did and just do the opposite.

let me know if you need some ideas.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Newbie" <Ne****@discuss ions.microsoft. com> wrote in message
news:FC******** *************** ***********@mic rosoft.com...
>i am able to allow the user to sort the columns of my datagrid, but only
>in
> ascending order. is there a way to allow sorting in descending order?
> thanks
> in advance.
>
> private void Page_Load(objec t sender, System.EventArg s e)
> {
>
> string sTODS = "Select * From TaskOrder";
> SqlConnection sqlConn = new SqlConnection(c onnStr);
> SqlCommand sqlCMD = new SqlCommand(sTOD S);
> sqlCMD.Connecti on = sqlConn;
> sqlConn.Open();
> SqlDataAdapter adapter = new SqlDataAdapter( sqlCMD);
> DataSet ds = new DataSet();
> adapter.Fill(ds );
> dgSearchResults .DataSource = ds.Tables[0];
> int tableRowCount = ds.Tables[0].Rows.Count;
> if (tableRowCount != 0)
> {
> DataView dv = new DataView();
> dv=ds.Tables[0].DefaultView;
> Page.Session.Ad d("DataViewOrig inal",dv);
> dgSearchResults .DataSource=dv;
> dgSearchResults .DataBind();
> dgSearchResults .Visible = true;
> }
> else
> {
> dgSearchResults .Visible = false;
> }
> }
>
> private void dgSearchResults _SortCommand(ob ject source,
> System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
> {
> if(Page.Session["DataViewOrigin al"]!=null)
> {
> DataView dv=(DataView) Page.Session["DataViewOrigin al"];
> dv.Sort=e.SortE xpression;
> dgSearchResults .DataSource=dv; //assign the source
> dgSearchResults .DataBind();
> }
> }
>


Nov 17 '05 #4
i already fixed the problem - thanks

"Ignacio Machin ( .NET/ C# MVP )" wrote:
hi

I don;t know how you are declaring the datagrid itself, but all you have
to do is add an ASC or DESC to the SortExpression.

IIRC the SortCommand of the datagrid does not allow to especify it, so you
may will need to find another approach or a work around. like keeping in
session the last kind of sorting you did and just do the opposite.

let me know if you need some ideas.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Newbie" <Ne****@discuss ions.microsoft. com> wrote in message
news:FC******** *************** ***********@mic rosoft.com...
i am able to allow the user to sort the columns of my datagrid, but only in
ascending order. is there a way to allow sorting in descending order?
thanks
in advance.

private void Page_Load(objec t sender, System.EventArg s e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(c onnStr);
SqlCommand sqlCMD = new SqlCommand(sTOD S);
sqlCMD.Connecti on = sqlConn;
sqlConn.Open();
SqlDataAdapter adapter = new SqlDataAdapter( sqlCMD);
DataSet ds = new DataSet();
adapter.Fill(ds );
dgSearchResults .DataSource = ds.Tables[0];
int tableRowCount = ds.Tables[0].Rows.Count;
if (tableRowCount != 0)
{
DataView dv = new DataView();
dv=ds.Tables[0].DefaultView;
Page.Session.Ad d("DataViewOrig inal",dv);
dgSearchResults .DataSource=dv;
dgSearchResults .DataBind();
dgSearchResults .Visible = true;
}
else
{
dgSearchResults .Visible = false;
}
}

private void dgSearchResults _SortCommand(ob ject source,
System.Web.UI.W ebControls.Data GridSortCommand EventArgs e)
{
if(Page.Session["DataViewOrigin al"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOrigin al"];
dv.Sort=e.SortE xpression;
dgSearchResults .DataSource=dv; //assign the source
dgSearchResults .DataBind();
}
}


Nov 17 '05 #5

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

Similar topics

9
3632
by: p0wer | last post by:
Let's suppose I have this sample document: <root> <entry id="1" <date>2003-08-03</date> <param_1>5</param_1> <param_2>10</param_2> </entry> <entry id="2"> ...
1
1429
by: Deep Silent Ocean | last post by:
Hi All I have one specific question for DataGrid In the Form Load event of the Form, I am binding data with DataGrid. On clicking Row the CurrentRowIndex is updated and it gives me correct rowindex. But if, I click on Column the data gets sorted in ascending or
7
4233
by: Pete Davis | last post by:
A different question this time. I have a DataGrid bound to a collection. Is there any way for me to allow sorting? The DataGrid.AllowSorting=true doesn't work, but that's probably because it can't assume the data types and thus can't sort them. I thought about implementing IComparable, but I don't see how that would work since it doesn't apply generically to all the fields/properties of the class. Thanks.
3
3127
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 sorts twice because I inserted a messagebox in the dgMouse (MouseUp) event. Before ok is pressed, the table changes from the order it was loaded to ascending order. After ok is pressed, it goes to descending. The code is below. Any idea why...
19
25471
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to sort columns based on the column header the user has clicked in both Ascending and Descending formats.
8
15181
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 that seems to work for 99% of the cases where I need to disable datagrid column sorting: Private Sub datagrid_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagrid.MouseDown Dim pt As New Point(e.X,...
2
7236
by: jediknight | last post by:
Hi, I have a listview which has columns of text and columns of numerical data. I need to be able to sort these columns into ascending/desending order whenever the user clicks on the column header. The text columns are sorted correctly but the numerical columns seem not to get sorted properly. For example I get the following result when I try to sort a numerical
1
7192
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar methods or syntax to a less experienced perl coder. I will post links to online resources you can read if necessary. Experienced perl coders might find nothing new or useful contained in this article. Short Review In part one I showed you some...
4
1858
by: rajtalent | last post by:
hi all, I want to sort the colum when clicks the columnheader using vb.net 2005 .But i receive the following error "Error 1 Overload resolution failed because no accessible 'New' accepts this number of arguments. " and my code is Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick If e.Column <> sortColumn Then sortColumn = e.Column...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10212
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9035
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6777
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3720
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2919
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.