Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid Column Sorting

Status
Not open for further replies.

karth23

Programmer
May 23, 2002
13
US
Public Sub SortCommand_OnClick(ByVal Source As Object, ByVal E As DataGridSortCommandEventArgs)

DsAddressBook1 = Session("dsAddressUSA")
Dim dv As DataView = DsAddressBook1.ADDRESS_LST.DefaultView
dv.Sort = E.SortExpression
dgUSA.DataSource = dv
dgUSA.DataBind()

End Sub

The above Code not working for Sorting in DataGrid
I have
Allowsorting="True" and
SorExpression in BoundColumn

Is there any way to Sort DataGrid Columns

Karthik Bala
 
Here is a basic sort sub you might try. It uses a session variable "i" to determine whether sort in ascending order or descending order. It flips back and forth as you click on the grid sort link. In your code, I assume that DsAddressBook1 is a dataset and ADDRESS_LST is a table in the dataset.

This datagrid sorting sub is in regular use and poses no problems.

Good luck.

Private Sub SortGrid(Obj As Object, e As DataGridSortCommandEventArgs)

Dim dv As New DataView(DsAddressBook1.Tables("ADDRESS_LST"))

If Session("i")=1 then

dv.Sort = e.SortExpression & " ASC": Session("i")=0

Else

dv.Sort = e.SortExpression & " DESC": Session("i")=1

End If

dgUSA.DataSource = dv
dgUSA.DataBind()

End Sub
 
Here's a FAQ with an extension of the datagrid with sorting built right in.

You do have to tell it to allow sorting. Directions are in the FAQ on how to set it up and use it.

faq855-2026

:)
paul
penny1.gif
penny1.gif
 
I tried using "SortGrid" Still I am not getting my columns sorted.

Karthik Bala
 
Kart: probably not worth stating but in your first post you wrote "SorExpression" and this should be "SortExpression"...I'm sure you already knew that but just in case....

When I put in AllowSorting="True" and then insert the ..."Sortexpression="field_name"/> into the boundcolumn of the Grid it sorts without problem...
 
Sorry I wrongly typed SorExpression. It should be SortExpression.

I had given SortExpression="Field_Name" all my bounded columns.

Still I am trying to Resolve it.

Waiting for Solution.

Karthik Bala
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top