473,378 Members | 1,411 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,378 software developers and data experts.

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(object sender, System.EventArgs e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCMD = new SqlCommand(sTODS);
sqlCMD.Connection = 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.Add("DataViewOriginal",dv);
dgSearchResults.DataSource=dv;
dgSearchResults.DataBind();
dgSearchResults.Visible = true;
}
else
{
dgSearchResults.Visible = false;
}
}

private void dgSearchResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
if(Page.Session["DataViewOriginal"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOriginal"];
dv.Sort=e.SortExpression;
dgSearchResults.DataSource=dv; //assign the source
dgSearchResults.DataBind();
}
}

Nov 17 '05 #1
4 2826
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****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.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(object sender, System.EventArgs e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCMD = new SqlCommand(sTODS);
sqlCMD.Connection = 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.Add("DataViewOriginal",dv);
dgSearchResults.DataSource=dv;
dgSearchResults.DataBind();
dgSearchResults.Visible = true;
}
else
{
dgSearchResults.Visible = false;
}
}

private void dgSearchResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
if(Page.Session["DataViewOriginal"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOriginal"];
dv.Sort=e.SortExpression;
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****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.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(object sender, System.EventArgs e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCMD = new SqlCommand(sTODS);
sqlCMD.Connection = 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.Add("DataViewOriginal",dv);
dgSearchResults.DataSource=dv;
dgSearchResults.DataBind();
dgSearchResults.Visible = true;
}
else
{
dgSearchResults.Visible = false;
}
}

private void dgSearchResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
if(Page.Session["DataViewOriginal"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOriginal"];
dv.Sort=e.SortExpression;
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****@discussions.microsoft.com> wrote in message
news:85**********************************@microsof t.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****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.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(object sender, System.EventArgs e)
> {
>
> string sTODS = "Select * From TaskOrder";
> SqlConnection sqlConn = new SqlConnection(connStr);
> SqlCommand sqlCMD = new SqlCommand(sTODS);
> sqlCMD.Connection = 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.Add("DataViewOriginal",dv);
> dgSearchResults.DataSource=dv;
> dgSearchResults.DataBind();
> dgSearchResults.Visible = true;
> }
> else
> {
> dgSearchResults.Visible = false;
> }
> }
>
> private void dgSearchResults_SortCommand(object source,
> System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> {
> if(Page.Session["DataViewOriginal"]!=null)
> {
> DataView dv=(DataView) Page.Session["DataViewOriginal"];
> dv.Sort=e.SortExpression;
> 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****@discussions.microsoft.com> wrote in message
news:FC**********************************@microsof t.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(object sender, System.EventArgs e)
{

string sTODS = "Select * From TaskOrder";
SqlConnection sqlConn = new SqlConnection(connStr);
SqlCommand sqlCMD = new SqlCommand(sTODS);
sqlCMD.Connection = 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.Add("DataViewOriginal",dv);
dgSearchResults.DataSource=dv;
dgSearchResults.DataBind();
dgSearchResults.Visible = true;
}
else
{
dgSearchResults.Visible = false;
}
}

private void dgSearchResults_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
if(Page.Session["DataViewOriginal"]!=null)
{
DataView dv=(DataView) Page.Session["DataViewOriginal"];
dv.Sort=e.SortExpression;
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
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
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...
7
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...
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...
19
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...
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...
2
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...
1
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...
4
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.