472,968 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Keeping sort order on a Gridview while another is sorted.

When I do a sorta on 1 table, then the other table goes back to the original
order.

What can I set so, it keeps the order of the other current gridview's order.

I set all the gridview values in my 'onpageload' in the cs file.
Feb 14 '07 #1
12 3749
On Feb 14, 3:06 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
When I do a sorta on 1 table, then the other table goes back to the original
order.

What can I set so, it keeps the order of the other current gridview's order.

I set all the gridview values in my 'onpageload' in the cs file.
Have you tried create different views from the same data table:

DataView view1 = new DataView(YourDataTable);
view1.Sort = "ColumnNameToBeSorted ASC";
Grid1.DataSource = view1;
Grid1.DataBind();

DataView view2 = new DataView(YourDataTable);
view2.Sort = "SomeOtherColumnNameToBeSorted ASC";
Grid2.DataSource = view2;
Grid2.DataBind();

Feb 14 '07 #2

"Quoc Linh" <le********@yahoo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
On Feb 14, 3:06 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
When I do a sorta on 1 table, then the other table goes back to the
original
order.

What can I set so, it keeps the order of the other current gridview's
order.

I set all the gridview values in my 'onpageload' in the cs file.

Have you tried create different views from the same data table:

DataView view1 = new DataView(YourDataTable);
view1.Sort = "ColumnNameToBeSorted ASC";
Grid1.DataSource = view1;
Grid1.DataBind();

DataView view2 = new DataView(YourDataTable);
view2.Sort = "SomeOtherColumnNameToBeSorted ASC";
Grid2.DataSource = view2;
Grid2.DataBind();
I'm not sure if that would help. I'm guessing it has something to do with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the current
gridview settings?
Feb 15 '07 #3
"Cindy Lee" <ci******@hotmail.comwrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
I'm not sure if that would help. I'm guessing it has something to do with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the current
gridview settings?
Two ways:

1) Store the sort order in ViewState

2) Use Ajax

Also, make sure that any code you don't want to run on postback is
surrounded by if (!IsPostback) {...}
Feb 15 '07 #4
Cindy Lee wrote:
"Quoc Linh" <le********@yahoo.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
>On Feb 14, 3:06 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
>>When I do a sorta on 1 table, then the other table goes back to the
original
>>order.

What can I set so, it keeps the order of the other current gridview's
order.
>>I set all the gridview values in my 'onpageload' in the cs file.
Have you tried create different views from the same data table:

DataView view1 = new DataView(YourDataTable);
view1.Sort = "ColumnNameToBeSorted ASC";
Grid1.DataSource = view1;
Grid1.DataBind();

DataView view2 = new DataView(YourDataTable);
view2.Sort = "SomeOtherColumnNameToBeSorted ASC";
Grid2.DataSource = view2;
Grid2.DataBind();


I'm not sure if that would help. I'm guessing it has something to do with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the current
gridview settings?
Each DataView maintains its own sort order, so in the page load link
each table to its own DataView, just as

Quoc Linh showed you.

T

Feb 15 '07 #5

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:eb**************@TK2MSFTNGP03.phx.gbl...
"Cindy Lee" <ci******@hotmail.comwrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
I'm not sure if that would help. I'm guessing it has something to do
with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the current
gridview settings?

Two ways:

1) Store the sort order in ViewState

2) Use Ajax

Also, make sure that any code you don't want to run on postback is
surrounded by if (!IsPostback) {...}

I use the (!IsPostback), but everytime I use Gridviews, I get an empty
dataset when I sort.
Is there a command that sets the current viewstate, to the last one?

DataView pageview = ViewState[currentView]???
GridView2.DataSource = pageview??
Feb 15 '07 #6
On Feb 14, 6:21 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
"Mark Rae" <m...@markNOSPAMrae.comwrote in message

news:eb**************@TK2MSFTNGP03.phx.gbl...
"Cindy Lee" <cindy...@hotmail.comwrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
I'm not sure if that would help. I'm guessing it has something to do
with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the current
gridview settings?
Two ways:
1) Store the sort order in ViewState
2) Use Ajax
Also, make sure that any code you don't want to run on postback is
surrounded by if (!IsPostback) {...}

I use the (!IsPostback), but everytime I use Gridviews, I get an empty
dataset when I sort.
Is there a command that sets the current viewstate, to the last one?

DataView pageview = ViewState[currentView]???
GridView2.DataSource = pageview??
Getting an empty dataset in postback is by-designed because the server
won't persist anything unless you save your dataset in ViewState or
Session variable, otherwise, you'll risk re-querying the database to
rebuild your dataset in every postback. The ViewState however won't
persist object that is not serializabled, which the DataSet is, but
not the DataView. The problem with saving a dataset to a page's
ViewState is the content of the dataset is embedded in the page, which
will severely hinder performance in every postback (Imagine 1 million
rows converted to gibberish text that embedded in your page, un-
neccessarily increase the size of your page to be render in the
browser...)

I particularly don't like sorting a grid that requires postback.
Plainly put, it sucks. There are existing javascripts that would help
you do that.

Quoc Linh

Feb 15 '07 #7

Here's a couple links that I think might help you:

Read more about Javascript and ASP.Net:
http://www.builderau.com.au/program/...9130406,00.htm

ASP.Net grid are actually rendered as HTML table with built-in
javascript functions. Use this javascript library to sort your html
table.
http://kryogenix.org/code/browser/sorttable/

Quoc Linh

Feb 15 '07 #8

"Quoc Linh" <le********@yahoo.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
On Feb 14, 6:21 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
"Mark Rae" <m...@markNOSPAMrae.comwrote in message

news:eb**************@TK2MSFTNGP03.phx.gbl...
"Cindy Lee" <cindy...@hotmail.comwrote in message
>news:Od**************@TK2MSFTNGP04.phx.gbl...
I'm not sure if that would help. I'm guessing it has something to
do
with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the
current
gridview settings?
Two ways:
1) Store the sort order in ViewState
2) Use Ajax
Also, make sure that any code you don't want to run on postback is
surrounded by if (!IsPostback) {...}
I use the (!IsPostback), but everytime I use Gridviews, I get an empty
dataset when I sort.
Is there a command that sets the current viewstate, to the last one?

DataView pageview = ViewState[currentView]???
GridView2.DataSource = pageview??

Getting an empty dataset in postback is by-designed because the server
won't persist anything unless you save your dataset in ViewState or
Session variable, otherwise, you'll risk re-querying the database to
rebuild your dataset in every postback. The ViewState however won't
persist object that is not serializabled, which the DataSet is, but
not the DataView. The problem with saving a dataset to a page's
ViewState is the content of the dataset is embedded in the page, which
will severely hinder performance in every postback (Imagine 1 million
rows converted to gibberish text that embedded in your page, un-
neccessarily increase the size of your page to be render in the
browser...)

I particularly don't like sorting a grid that requires postback.
Plainly put, it sucks. There are existing javascripts that would help
you do that.

Quoc Linh
So to enable sorting on the gridview is useless if you have more than 1
table?
Then most people sort on the dataTable before it's binded and have sortable
= false on the gridview.
I guess I could have a session varible of the sort column for each table.
Eventually I'll probably use AJAX, but I don't have the time to set it up
right now.

Oh, also of note, I take my data from an XML stream, so it's not tied into
the database.



Feb 15 '07 #9
On Feb 15, 10:49 am, "Cindy Lee" <cindy...@hotmail.comwrote:
"Quoc Linh" <lequocl...@yahoo.comwrote in message

news:11**********************@l53g2000cwa.googlegr oups.com...
On Feb 14, 6:21 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
"Mark Rae" <m...@markNOSPAMrae.comwrote in message
>news:eb**************@TK2MSFTNGP03.phx.gbl...
"Cindy Lee" <cindy...@hotmail.comwrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
I'm not sure if that would help. I'm guessing it has something to
do
with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the
current
gridview settings?
Two ways:
1) Store the sort order in ViewState
2) Use Ajax
Also, make sure that any code you don't want to run on postback is
surrounded by if (!IsPostback) {...}
I use the (!IsPostback), but everytime I use Gridviews, I get an empty
dataset when I sort.
Is there a command that sets the current viewstate, to the last one?
DataView pageview = ViewState[currentView]???
GridView2.DataSource = pageview??
Getting an empty dataset in postback is by-designed because the server
won't persist anything unless you save your dataset in ViewState or
Session variable, otherwise, you'll risk re-querying the database to
rebuild your dataset in every postback. The ViewState however won't
persist object that is not serializabled, which the DataSet is, but
not the DataView. The problem with saving a dataset to a page's
ViewState is the content of the dataset is embedded in the page, which
will severely hinder performance in every postback (Imagine 1 million
rows converted to gibberish text that embedded in your page, un-
neccessarily increase the size of your page to be render in the
browser...)
I particularly don't like sorting a grid that requires postback.
Plainly put, it sucks. There are existing javascripts that would help
you do that.
Quoc Linh

So to enable sorting on the gridview is useless if you have more than 1
table?
Then most people sort on the dataTable before it's binded and have sortable
= false on the gridview.
I guess I could have a session varible of the sort column for each table.
Eventually I'll probably use AJAX, but I don't have the time to set it up
right now.

Oh, also of note, I take my data from an XML stream, so it's not tied into
the database.
Oh, also of note, I take my data from an XML stream, so it's not tied into
the database.
However method you used to populate your dataset, you'll have to
repopulate them if you don't persist your dataset in Session or
ViewState, it's your choice of implementation.

The rest is setting up break points in your code and see which objects
you cared about is still valid and which isn't. Especially check out
value of yourGrid.DataSource property in the next postback.

Page_Load(...)
{

if (!IsPostBack)
{
//Initial page load code gets execute here, only once (in most
cases)
}
else
{
//Code you want ONLY happen in post-back
}

//Code you want to happen, regardless of page loading or post back

}

Set your breakpoint in these blocks and see how they got triggered
when you perform an action on the client. I think it will be clear
then which object is available to you and which is not.

Another trick is after your page is rendered by the server, do a View
Source to view the source in the page, to see how your asp.net
controls are convert to its html equivalent by the server.

Good luck,

Quoc Linh

Feb 15 '07 #10

"Quoc Linh" <le********@yahoo.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
On Feb 15, 10:49 am, "Cindy Lee" <cindy...@hotmail.comwrote:
"Quoc Linh" <lequocl...@yahoo.comwrote in message

news:11**********************@l53g2000cwa.googlegr oups.com...
On Feb 14, 6:21 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
"Mark Rae" <m...@markNOSPAMrae.comwrote in message
news:eb**************@TK2MSFTNGP03.phx.gbl...
"Cindy Lee" <cindy...@hotmail.comwrote in message
>news:Od**************@TK2MSFTNGP04.phx.gbl...
I'm not sure if that would help. I'm guessing it has something
to
do
with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the
current
gridview settings?
Two ways:
1) Store the sort order in ViewState
2) Use Ajax
Also, make sure that any code you don't want to run on postback is
surrounded by if (!IsPostback) {...}
I use the (!IsPostback), but everytime I use Gridviews, I get an
empty
dataset when I sort.
Is there a command that sets the current viewstate, to the last one?
DataView pageview = ViewState[currentView]???
GridView2.DataSource = pageview??
Getting an empty dataset in postback is by-designed because the server
won't persist anything unless you save your dataset in ViewState or
Session variable, otherwise, you'll risk re-querying the database to
rebuild your dataset in every postback. The ViewState however won't
persist object that is not serializabled, which the DataSet is, but
not the DataView. The problem with saving a dataset to a page's
ViewState is the content of the dataset is embedded in the page, which
will severely hinder performance in every postback (Imagine 1 million
rows converted to gibberish text that embedded in your page, un-
neccessarily increase the size of your page to be render in the
browser...)
I particularly don't like sorting a grid that requires postback.
Plainly put, it sucks. There are existing javascripts that would help
you do that.
Quoc Linh
So to enable sorting on the gridview is useless if you have more than 1
table?
Then most people sort on the dataTable before it's binded and have
sortable
= false on the gridview.
I guess I could have a session varible of the sort column for each
table.
Eventually I'll probably use AJAX, but I don't have the time to set it
up
right now.

Oh, also of note, I take my data from an XML stream, so it's not tied
into
the database.
Oh, also of note, I take my data from an XML stream, so it's not tied
into
the database.

However method you used to populate your dataset, you'll have to
repopulate them if you don't persist your dataset in Session or
ViewState, it's your choice of implementation.

The rest is setting up break points in your code and see which objects
you cared about is still valid and which isn't. Especially check out
value of yourGrid.DataSource property in the next postback.

Page_Load(...)
{

if (!IsPostBack)
{
//Initial page load code gets execute here, only once (in most
cases)
}
else
{
//Code you want ONLY happen in post-back
}

//Code you want to happen, regardless of page loading or post back

}

Set your breakpoint in these blocks and see how they got triggered
when you perform an action on the client. I think it will be clear
then which object is available to you and which is not.

Another trick is after your page is rendered by the server, do a View
Source to view the source in the page, to see how your asp.net
controls are convert to its html equivalent by the server.

Good luck,

Quoc Linh
Thanks, the postback call just does 1 gridview
__doPostBack('GridView2', 'Sort$col1)

is there anyway to remember the last postback variables. I have no problem
with storing the data in a session variable or a view state, because my olap
queries take a long time.
Feb 15 '07 #11
On Feb 15, 12:31 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
"Quoc Linh" <lequocl...@yahoo.comwrote in message

news:11**********************@m58g2000cwm.googlegr oups.com...
On Feb 15, 10:49 am, "Cindy Lee" <cindy...@hotmail.comwrote:
"Quoc Linh" <lequocl...@yahoo.comwrote in message
>news:11**********************@l53g2000cwa.googleg roups.com...
On Feb 14, 6:21 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
"Mark Rae" <m...@markNOSPAMrae.comwrote in message
>news:eb**************@TK2MSFTNGP03.phx.gbl...
"Cindy Lee" <cindy...@hotmail.comwrote in message
news:Od**************@TK2MSFTNGP04.phx.gbl...
I'm not sure if that would help. I'm guessing it has something
to
do
with
calling it on page load and how the post backs work.
Sorting always does a postback, so is there a way to keep the
current
gridview settings?
Two ways:
1) Store the sort order in ViewState
2) Use Ajax
Also, make sure that any code you don't want to run on postback is
surrounded by if (!IsPostback) {...}
I use the (!IsPostback), but everytime I use Gridviews, I get an
empty
dataset when I sort.
Is there a command that sets the current viewstate, to the last one?
DataView pageview = ViewState[currentView]???
GridView2.DataSource = pageview??
Getting an empty dataset in postback is by-designed because the server
won't persist anything unless you save your dataset in ViewState or
Session variable, otherwise, you'll risk re-querying the database to
rebuild your dataset in every postback. The ViewState however won't
persist object that is not serializabled, which the DataSet is, but
not the DataView. The problem with saving a dataset to a page's
ViewState is the content of the dataset is embedded in the page, which
will severely hinder performance in every postback (Imagine 1 million
rows converted to gibberish text that embedded in your page, un-
neccessarily increase the size of your page to be render in the
browser...)
I particularly don't like sorting a grid that requires postback.
Plainly put, it sucks. There are existing javascripts that would help
you do that.
Quoc Linh
So to enable sorting on the gridview is useless if you have more than 1
table?
Then most people sort on the dataTable before it's binded and have
sortable
= false on the gridview.
I guess I could have a session varible of the sort column for each
table.
Eventually I'll probably use AJAX, but I don't have the time to set it
up
right now.
Oh, also of note, I take my data from an XML stream, so it's not tied
into
the database.
Oh, also of note, I take my data from an XML stream, so it's not tied
into
the database.
However method you used to populate your dataset, you'll have to
repopulate them if you don't persist your dataset in Session or
ViewState, it's your choice of implementation.
The rest is setting up break points in your code and see which objects
you cared about is still valid and which isn't. Especially check out
value of yourGrid.DataSource property in the next postback.
Page_Load(...)
{
if (!IsPostBack)
{
//Initial page load code gets execute here, only once (in most
cases)
}
else
{
//Code you want ONLY happen in post-back
}
//Code you want to happen, regardless of page loading or post back
}
Set your breakpoint in these blocks and see how they got triggered
when you perform an action on the client. I think it will be clear
then which object is available to you and which is not.
Another trick is after your page is rendered by the server, do a View
Source to view the source in the page, to see how your asp.net
controls are convert to its html equivalent by the server.
Good luck,
Quoc Linh

Thanks, the postback call just does 1 gridview
__doPostBack('GridView2', 'Sort$col1)

is there anyway to remember the last postback variables. I have no problem
with storing the data in a session variable or a view state, because my olap
queries take a long time.
I think I might know why you're puzzled. The checking for IsPostBack
isn't straight forward. Try the following logic:

///////////////////////////////////////////////////
///// In your Page_Load event ///////

protected override void Page_Load(object sender, EventArgs e)
{

DataSet MyDataSet;

if (!IsPostBack)
{
MyDataSet = PerformSomeMethodToPopulateMyDataSet(); //This populate
the dataset once and gets executed once
//Persist in in Session
Session["MyDataSet"] = MyDataSet;
}

//Here, expects Session["MyDataSet"] is valid, always, when page_load
event is triggerd
if (Session["MyDataSet"] == null)
{
throw new ArgumentNullException("Expects Session[\"MyDataSet\"] to
have a value.");
}

//Retrieved the saved dataset
MyDataSet = (DataSet) Session["MyDataSet"];

//Bind to grid, executes every time.
// It's your choice to bind to view for sorting or filtering purpose
myGrid.DataSource = MyDataSet;
myGrid.DataBind;

} //ends page_load

HTH,
Quoc Linh

Feb 15 '07 #12
Thanks for all the help. It was my bad, I should have looked more at the
sorting functions that I use (I use custom ones). So I changed those a
little on my sorting event: (Also I like putting my data in a session
variable cus my page loads better)

protected void gridView1_Sorting(object sender, GridViewSortEventArgs e)
{
GridViewSortExpression1 = e.SortExpression;
int pageIndex = GridView1.PageIndex;
GridView1.DataSource = SortDataTable1(GridView1.DataSource as
DataTable, false);
Session["DS1"] = GridView1.DataSource;
GridView1.DataBind();
GridView1.PageIndex = pageIndex;
if (Session["DS2"] != null)
{
GridView2.DataSource = Session["DS2"];
GridView2.DataBind();
}

}
Feb 15 '07 #13

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

Similar topics

2
by: binary-nomad | last post by:
Hello, To followup my last post, how do I keep a field in a table already sorted. eg. if a field in it going to have values like "10", "3330" and "1", I want the row with the "1' first in the...
3
by: happy | last post by:
/* Book name : The prodessional programmers guide to C File name : E:\programs\tc\iti01\ch09\main\01setupm.c Program discription: file setuping -up -Version 01-ver01-W Logic ...
11
by: Leon | last post by:
I have six textbox controls on my webform that allows the user to enter any numbers from 1 to 25 in any order. However, I would like to sort those numbers from least to greatest before sending them...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
2
by: adrian.chandler | last post by:
Hi all, I have been using letter and symbol codes such as GNU< GNU\ GNU} GNUł in an Access table. I was surprised to see that when the table was sorted on this field, the order is: GNUł...
2
by: Daves | last post by:
I have a gridview displaying News items and fetches the data through a (little complicated) sql stored procedure... The sorting seems to be done in the gridview since there is no sorting...
2
by: Patrick | last post by:
I got a page that loads a xml file into a treeview control. I want it to sort the data before sending it to the treeview control is that possible? <root> <level1 name="" src="" order="0">...
18
by: xahlee | last post by:
Last year, i've posted a tutorial and commentary about Python and Perl's sort function. (http://xahlee.org/perl-python/sort_list.html) In that article, i discussed a technique known among...
1
by: Aeric | last post by:
I have read the following topic: sorting dataset and I am facing the same issue. I am designing a report. I have fill a dataset with the results from a query. From the results, I used to set...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.