472,353 Members | 1,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

dymanicly sort a record set with a datagrid sortcommand

I'm using VS.net. I have created a component with the basic set of database
commands. This component returns a record set that is bound to a datagrid. I
want to add a dynamic sort, but am not sure how to do this. If the query were
on the same webform this would not be a problem, i'd jist add it to the
select string.
but..... using the component designer in vs.net i'm not sure how to do this,
nor am i sure how to call the fill with the sort parameter. I will provide
the code if necessary.
My main purpose is to learn to use the designer to the full extent it was
intended.

again here are my main issues.
1. how do i setup the order by parameter in the component designer (or if
can't how to manuelly)
2. how to call the component and/or the fill with the order by parameter.

I am (still) new to vs and .net.
Any help would be appreciated.
Thank You
kes

ok:
the code for the initial fill is below. Sorry about the length.
Protected myComponent As New Component1

(.............)
Me.MyDataSet1.DataSetName = "myDataSet"

(................)
Me.DataView1.Table = Me.MyDataSet1.itm
CType(Me.MyDataSet1,
System.ComponentModel.ISupportInitialize).EndInit( )
CType(Me.DataView1,
System.ComponentModel.ISupportInitialize).EndInit( )

(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.FillDataSet(MyDataSet1)
DataGrid1.DataBind()
End If

End Sub
Nov 19 '05 #1
5 1346
You need to handle the Sort event on the DataGrid. In there you typically
use a DataView on a DataTable (from a DataSet) and set its Sort property.
The Sort propery says which column to sort by and this is passed as the parameter
to the Sort event on the DataGrid. DataGridSortCommandArgs.SortExpression,
IIRC. This comes from your DataGrid's Comumns collection -- the SortExpression
property on the columns. When the user selects the column header the string
you've configured for the coulumn is passed to your event. Use this to do
your sorting with the DataView.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I'm using VS.net. I have created a component with the basic set of
database
commands. This component returns a record set that is bound to a
datagrid. I
want to add a dynamic sort, but am not sure how to do this. If the
query were
on the same webform this would not be a problem, i'd jist add it to
the
select string.
but..... using the component designer in vs.net i'm not sure how to do
this,
nor am i sure how to call the fill with the sort parameter. I will
provide
the code if necessary.
My main purpose is to learn to use the designer to the full extent it
was
intended.
again here are my main issues.
1. how do i setup the order by parameter in the component designer (or
if
can't how to manuelly)
2. how to call the component and/or the fill with the order by
parameter.
I am (still) new to vs and .net.
Any help would be appreciated.
Thank You
kes
ok:
the code for the initial fill is below. Sorry about the length.
Protected myComponent As New Component1
(.............)

Me.MyDataSet1.DataSetName = "myDataSet"

(................)
Me.DataView1.Table = Me.MyDataSet1.itm
CType(Me.MyDataSet1,
System.ComponentModel.ISupportInitialize).EndInit( )
CType(Me.DataView1,
System.ComponentModel.ISupportInitialize).EndInit( )
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.FillDataSet(MyDataSet1)
DataGrid1.DataBind()
End If
End Sub


Nov 19 '05 #2
That worked, however i have another problem. When i select Edit (command) the
item being edited is not the item selected. My guess is that the sort is
being set to the default value and the current index is selecting what ever
is in it's place for edit. How can i fix that?
"Brock Allen" wrote:
You need to handle the Sort event on the DataGrid. In there you typically
use a DataView on a DataTable (from a DataSet) and set its Sort property.
The Sort propery says which column to sort by and this is passed as the parameter
to the Sort event on the DataGrid. DataGridSortCommandArgs.SortExpression,
IIRC. This comes from your DataGrid's Comumns collection -- the SortExpression
property on the columns. When the user selects the column header the string
you've configured for the coulumn is passed to your event. Use this to do
your sorting with the DataView.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I'm using VS.net. I have created a component with the basic set of
database
commands. This component returns a record set that is bound to a
datagrid. I
want to add a dynamic sort, but am not sure how to do this. If the
query were
on the same webform this would not be a problem, i'd jist add it to
the
select string.
but..... using the component designer in vs.net i'm not sure how to do
this,
nor am i sure how to call the fill with the sort parameter. I will
provide
the code if necessary.
My main purpose is to learn to use the designer to the full extent it
was
intended.
again here are my main issues.
1. how do i setup the order by parameter in the component designer (or
if
can't how to manuelly)
2. how to call the component and/or the fill with the order by
parameter.
I am (still) new to vs and .net.
Any help would be appreciated.
Thank You
kes
ok:
the code for the initial fill is below. Sorry about the length.
Protected myComponent As New Component1
(.............)

Me.MyDataSet1.DataSetName = "myDataSet"

(................)
Me.DataView1.Table = Me.MyDataSet1.itm
CType(Me.MyDataSet1,
System.ComponentModel.ISupportInitialize).EndInit( )
CType(Me.DataView1,
System.ComponentModel.ISupportInitialize).EndInit( )
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.FillDataSet(MyDataSet1)
DataGrid1.DataBind()
End If
End Sub


Nov 19 '05 #3
What does your edit event do? It should just set the EditItemIndex to be
the index the Edit event passes. In your case is the item being editied
even on the page? Or do none of them show up as being editable?

-Brock
DevelopMentor
http://staff.develop.com/ballen
That worked, however i have another problem. When i select Edit
(command) the item being edited is not the item selected. My guess is
that the sort is being set to the default value and the current index
is selecting what ever is in it's place for edit. How can i fix that?

"Brock Allen" wrote:
You need to handle the Sort event on the DataGrid. In there you
typically use a DataView on a DataTable (from a DataSet) and set its
Sort property. The Sort propery says which column to sort by and this
is passed as the parameter to the Sort event on the DataGrid.
DataGridSortCommandArgs.SortExpression, IIRC. This comes from your
DataGrid's Comumns collection -- the SortExpression property on the
columns. When the user selects the column header the string you've
configured for the coulumn is passed to your event. Use this to do
your sorting with the DataView.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I'm using VS.net. I have created a component with the basic set of
database
commands. This component returns a record set that is bound to a
datagrid. I
want to add a dynamic sort, but am not sure how to do this. If the
query were
on the same webform this would not be a problem, i'd jist add it to
the
select string.
but..... using the component designer in vs.net i'm not sure how to
do
this,
nor am i sure how to call the fill with the sort parameter. I will
provide
the code if necessary.
My main purpose is to learn to use the designer to the full extent
it
was
intended.
again here are my main issues.
1. how do i setup the order by parameter in the component designer
(or
if
can't how to manuelly)
2. how to call the component and/or the fill with the order by
parameter.
I am (still) new to vs and .net.
Any help would be appreciated.
Thank You
kes
ok:
the code for the initial fill is below. Sorry about the length.
Protected myComponent As New Component1
(.............)
Me.MyDataSet1.DataSetName = "myDataSet"

(................)
Me.DataView1.Table = Me.MyDataSet1.itm
CType(Me.MyDataSet1,
System.ComponentModel.ISupportInitialize).EndInit( )
CType(Me.DataView1,
System.ComponentModel.ISupportInitialize).EndInit( )
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.FillDataSet(MyDataSet1)
DataGrid1.DataBind()
End If
End Sub


Nov 19 '05 #4
this problem only happens on the first click on an edit item. If i scroll to
the item again on page 3 i can edit it and the correct items are available.
It appears that the order is going back to the origional sort order.
here is my edit sub.
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
End Sub
thanks
kes
"Brock Allen" wrote:
What does your edit event do? It should just set the EditItemIndex to be
the index the Edit event passes. In your case is the item being editied
even on the page? Or do none of them show up as being editable?

-Brock
DevelopMentor
http://staff.develop.com/ballen
That worked, however i have another problem. When i select Edit
(command) the item being edited is not the item selected. My guess is
that the sort is being set to the default value and the current index
is selecting what ever is in it's place for edit. How can i fix that?

"Brock Allen" wrote:
You need to handle the Sort event on the DataGrid. In there you
typically use a DataView on a DataTable (from a DataSet) and set its
Sort property. The Sort propery says which column to sort by and this
is passed as the parameter to the Sort event on the DataGrid.
DataGridSortCommandArgs.SortExpression, IIRC. This comes from your
DataGrid's Comumns collection -- the SortExpression property on the
columns. When the user selects the column header the string you've
configured for the coulumn is passed to your event. Use this to do
your sorting with the DataView.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I'm using VS.net. I have created a component with the basic set of
database
commands. This component returns a record set that is bound to a
datagrid. I
want to add a dynamic sort, but am not sure how to do this. If the
query were
on the same webform this would not be a problem, i'd jist add it to
the
select string.
but..... using the component designer in vs.net i'm not sure how to
do
this,
nor am i sure how to call the fill with the sort parameter. I will
provide
the code if necessary.
My main purpose is to learn to use the designer to the full extent
it
was
intended.
again here are my main issues.
1. how do i setup the order by parameter in the component designer
(or
if
can't how to manuelly)
2. how to call the component and/or the fill with the order by
parameter.
I am (still) new to vs and .net.
Any help would be appreciated.
Thank You
kes
ok:
the code for the initial fill is below. Sorry about the length.
Protected myComponent As New Component1
(.............)
Me.MyDataSet1.DataSetName = "myDataSet"

(................)
Me.DataView1.Table = Me.MyDataSet1.itm
CType(Me.MyDataSet1,
System.ComponentModel.ISupportInitialize).EndInit( )
CType(Me.DataView1,
System.ComponentModel.ISupportInitialize).EndInit( )
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.FillDataSet(MyDataSet1)
DataGrid1.DataBind()
End If
End Sub


Nov 19 '05 #5
> It appears that the order is going back to the origional sort order.

Yeah, it's up tp you to remember the sort order across postbacks. Store that
info in ViewState explicitly in your page.

-Brock
DevelopMentor
http://staff.develop.com/ballen


Nov 19 '05 #6

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

Similar topics

3
by: taly | last post by:
Hi all how can I make the interface for the user so he can sort datagrid? thanks
1
by: Webgour | last post by:
Hi, I'm tring to add a column to a datagrid with a linkbutton as header that can be used to sort the column. The column and the linkbutton are...
3
by: DigHazuse | last post by:
relative noob. i'm trying to get/display the column Header name that the user clicks to sort on the DataGrid. I know that i could take the...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub...
3
by: Raymond Lewallen | last post by:
I have a modal dialog displaying a datagrid control. Click on the column header to sort the datagrid opens a new window with the following in the...
4
by: DC Gringo | last post by:
Can someone show me how to turn this into a bi-directional sort allowing ascending and descending using the default datagrid allowsorting attribute?...
4
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've...
2
by: Joey | last post by:
I have an asp.net 1.1 C# web application with a datagrid. I set the datagrid's "AllowSorting" property to "True". Then I created a sort function...
1
by: 276q | last post by:
Trying to use the sortcommand in my datagrid, the subroutine "Sort_Grid" error message is prompting: Name 'objDataView' is not declared....
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.