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

Question about grids and sorting

I'm trying to make a sortable grid. I get the grid the first time the
page loads, then I click on the column name, and the page reloads with
an empty grid (only headers are shown). Any idea?

This is the code:

private void Page_Load(object sender, System.EventArgs e)
{

if ( !IsPostBack)
{

daEvents.Fill(dsEvents);
dgEvents.DataBind();
}
}

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

daEvents.Fill(dsEvents);
dsEvents.eventsTBL.DefaultView.Sort = e.SortExpression;
dgEvents.DataBind();

}
Jul 21 '05 #1
2 1388
Adriank:

Your dataset is probably being reset at the post back. Just to be safe, try
adding the Dataset to Session state when you first populate it. Then use the
SessionState dataset when you try to sort. Here's a sample routine I used
which uses the session variable "Data_Table" which is stored when I first
load the grid:

First, set the sort command of the grid to this sub:

Private Sub dglogs_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dglogs.SortCommand
BindData(e.SortExpression)
End Sub

Then set the allow sort to true.

Now just create a new view based on the DataTable or dataset stored in
session state. I create a new dataview each time in this example, but you
could store the view in state as well and just change the sort criteria.

Protected Sub BindData(ByVal sortField As String)
Try
If cboPages.SelectedItem.Value = "All" Then
dglogs.AllowPaging = False
Else
dglogs.AllowPaging = True
dglogs.PageSize = CType(cboPages.SelectedItem.Value, Int32)
End If
Dim dvw As DataView
dvw = CType(Session("Data_Table"), DataTable).DefaultView
dvw.Sort = sortField
dglogs.DataSource = dvw
dglogs.DataBind()
Catch sq As SqlException
Console.Write(sq.ToString)
Catch exc As System.Exception
Console.WriteLine(exc.ToString)
End Try

End Sub
"adriank" <ad*****@jazo.org.il> wrote in message
news:ca*************************@posting.google.co m...
I'm trying to make a sortable grid. I get the grid the first time the
page loads, then I click on the column name, and the page reloads with
an empty grid (only headers are shown). Any idea?

This is the code:

private void Page_Load(object sender, System.EventArgs e)
{

if ( !IsPostBack)
{

daEvents.Fill(dsEvents);
dgEvents.DataBind();
}
}

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

daEvents.Fill(dsEvents);
dsEvents.eventsTBL.DefaultView.Sort = e.SortExpression;
dgEvents.DataBind();

}

Jul 21 '05 #2
Adriank:

Your dataset is probably being reset at the post back. Just to be safe, try
adding the Dataset to Session state when you first populate it. Then use the
SessionState dataset when you try to sort. Here's a sample routine I used
which uses the session variable "Data_Table" which is stored when I first
load the grid:

First, set the sort command of the grid to this sub:

Private Sub dglogs_SortCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles
dglogs.SortCommand
BindData(e.SortExpression)
End Sub

Then set the allow sort to true.

Now just create a new view based on the DataTable or dataset stored in
session state. I create a new dataview each time in this example, but you
could store the view in state as well and just change the sort criteria.

Protected Sub BindData(ByVal sortField As String)
Try
If cboPages.SelectedItem.Value = "All" Then
dglogs.AllowPaging = False
Else
dglogs.AllowPaging = True
dglogs.PageSize = CType(cboPages.SelectedItem.Value, Int32)
End If
Dim dvw As DataView
dvw = CType(Session("Data_Table"), DataTable).DefaultView
dvw.Sort = sortField
dglogs.DataSource = dvw
dglogs.DataBind()
Catch sq As SqlException
Console.Write(sq.ToString)
Catch exc As System.Exception
Console.WriteLine(exc.ToString)
End Try

End Sub
"adriank" <ad*****@jazo.org.il> wrote in message
news:ca*************************@posting.google.co m...
I'm trying to make a sortable grid. I get the grid the first time the
page loads, then I click on the column name, and the page reloads with
an empty grid (only headers are shown). Any idea?

This is the code:

private void Page_Load(object sender, System.EventArgs e)
{

if ( !IsPostBack)
{

daEvents.Fill(dsEvents);
dgEvents.DataBind();
}
}

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

daEvents.Fill(dsEvents);
dsEvents.eventsTBL.DefaultView.Sort = e.SortExpression;
dgEvents.DataBind();

}

Jul 21 '05 #3

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

Similar topics

2
by: orekinbck | last post by:
Hi There Using C# forms, I have a main screen that contains 2 data grids. * The data grids are connected to ArrayLists (each grid has its own ArrayList) * The data grids are intended for...
6
by: Paul | last post by:
Hi I have 2 data grids and several controls on a web page. The grids will vary in size, just wondering if the lower grid could be covered by part of the upper grid depending on its size or is there...
7
by: Sean | last post by:
I need a generic collection that will do the following key/value/value or index/value/value basically I need a multidimensional generic Collection if that is even possible!
4
by: Richard Carpenter | last post by:
Considering a typical scenario where the user is presented a list of customers and, upon selecting one and clicking a button, they are then presented with a new page depicting the orders for that...
3
by: Jordan | last post by:
Hey Peoples, I'm wonderg if there is a way to make a subclass of wx.grid.Grid in which the coloumn labels for the grid appear on the bottom of the grid instead of the top. 1 2 3 4 5 a| | ...
1
by: richard | last post by:
OK, I have got bi-directional datagrid sorting down, have a created a nice sorting class. My question, how can I add sorting to more than one datagrid on the same page? Everything I have tried has...
1
by: zafar | last post by:
hi every one, In my database picture is saved, i am using sql server 2000 and VB.net 2005. When I search the record, I need that the picture should also be shown in the grid ( i am using ultra grid...
4
by: jm1 | last post by:
Longtime lurker... first post. These forums have already helped a lot, so thanks. I have a design issue that is probably easy to figure out for someone with a little more DB experience than myself....
6
by: gaya3 | last post by:
Hi all, can anyone pl say how to sort the particular column in dojo grids by default... For example.. If i'm having columns like... col1,col2,col3,col4,col5 in the grid.. "col3" should be...
0
by: omgdork | last post by:
Hi! I'm having trouble on how to proceed with inserting data that are in parent and child gridviews. I have a gridview with nested gridviews that looks like this: ...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
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.