By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

dymanicly sort a record set with a datagrid sortcommand

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
> 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 discussion thread is closed

Replies have been disabled for this discussion.