473,714 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.D ataSetName = "myDataSet"

(.............. ..)
Me.DataView1.Ta ble = Me.MyDataSet1.i tm
CType(Me.MyData Set1,
System.Componen tModel.ISupport Initialize).End Init()
CType(Me.DataVi ew1,
System.Componen tModel.ISupport Initialize).End Init()

(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.Fil lDataSet(MyData Set1)
DataGrid1.DataB ind()
End If

End Sub
Nov 19 '05 #1
5 1440
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. DataGridSortCom mandArgs.SortEx pression,
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.D ataSetName = "myDataSet"

(.............. ..)
Me.DataView1.Ta ble = Me.MyDataSet1.i tm
CType(Me.MyData Set1,
System.Componen tModel.ISupport Initialize).End Init()
CType(Me.DataVi ew1,
System.Componen tModel.ISupport Initialize).End Init()
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.Fil lDataSet(MyData Set1)
DataGrid1.DataB ind()
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. DataGridSortCom mandArgs.SortEx pression,
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.D ataSetName = "myDataSet"

(.............. ..)
Me.DataView1.Ta ble = Me.MyDataSet1.i tm
CType(Me.MyData Set1,
System.Componen tModel.ISupport Initialize).End Init()
CType(Me.DataVi ew1,
System.Componen tModel.ISupport Initialize).End Init()
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.Fil lDataSet(MyData Set1)
DataGrid1.DataB ind()
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.
DataGridSortCom mandArgs.SortEx pression, 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.D ataSetName = "myDataSet"

(.............. ..)
Me.DataView1.Ta ble = Me.MyDataSet1.i tm
CType(Me.MyData Set1,
System.Componen tModel.ISupport Initialize).End Init()
CType(Me.DataVi ew1,
System.Componen tModel.ISupport Initialize).End Init()
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.Fil lDataSet(MyData Set1)
DataGrid1.DataB ind()
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_EditC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.EditC ommand
DataGrid1.EditI temIndex = e.Item.ItemInde x
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.
DataGridSortCom mandArgs.SortEx pression, 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.D ataSetName = "myDataSet"

(.............. ..)
Me.DataView1.Ta ble = Me.MyDataSet1.i tm
CType(Me.MyData Set1,
System.Componen tModel.ISupport Initialize).End Init()
CType(Me.DataVi ew1,
System.Componen tModel.ISupport Initialize).End Init()
(..........)
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
myComponent.Fil lDataSet(MyData Set1)
DataGrid1.DataB ind()
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
7778
by: taly | last post by:
Hi all how can I make the interface for the user so he can sort datagrid? thanks
1
8907
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 problem is that when you click the added column header it doesn't trigger the sort. The code : <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false"
3
8266
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 DataGrid until I found the value that matches the e.SortExpression and then grab the Header Name ... but I keep thinking/hoping there is an easier way. I have searched through all the e.* possibilities hoiping to find the Index # or something...
7
2464
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 Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here
3
2123
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: javascript:__doPostBack('dgDataGrid$_ctl1$_ctl1','') instead of actually posting back to the modal dialog and sorting the datagrid. ItemDataBound, ItemCommand events both work fine, only the SortCommand is producing this unwanted behavior.
4
1436
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 ------------ Protected Sub SortCommand_OnClick(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles DataGrid2.SortCommand
4
1510
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 VB.NET) that handles the SortCommand event of the data grid. I've included the declaration of the Sub below. EnableViewState is set to false; we reload the DataSource each time the page posts. Would anyone know why this DataGrid doesn't sort? ...
2
3671
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, then the Event button in the Properties window, and then double clicking in the "SortCommand" box. Then in the function that was created for me, I entered my code. Now, the datagrid will not sort. I planted a breakpoint on the first line of code...
1
1261
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 = "SELECT * FROM cards" Dim objConnection As New SQLConnection(strConnection) Dim objAdapter As New SQLDataAdapter(strSQL, objConnection) Dim objDataSet As New DataSet()
0
8801
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9174
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7953
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3158
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.