473,383 Members | 1,821 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,383 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 1419
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 added programmatically (see below). However the...
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 e.SortExpression and spin through the Columns on 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 DataGrid1_SortCommand: -------------------- Private...
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 location: ...
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? FYI, Session("source") is an sqldataadapter...
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 created in the code-behind a method (Sub - I'm using...
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 for it by selecting the datagrid in the designer,...
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. ''''''''' Sub bindSwGrid() Dim strSQL As String =...
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: 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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.