Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 28th, 2005, 12:55 PM
Registered User
 
Join Date: Sep 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid sorting

Hi Guys,

I am struggling with sorting the datagrid along with paging...

here is my code. Everything works fine expect the sorting thing...i am not sure how to get hold of user entered values...am i not sure if i calling the sort function correctly...

Code:
<script language="VB" runat="server">
Protected strSQL AS String

Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
CodeSearchList.CurrentPageIndex = 0
BindData()
End Sub

Sub BindData()
Dim DS As DataSet
Dim SqlConn As SqlConnection
Dim Sqlda as SqlDataAdapter
Dim strConnection As String
Try

strConnection=ConfigurationSettings.AppSettings("conString")
SqlConn = New SqlConnection(strConnection)
strSQL= "Select * from SubConsultant where ((CODE LIKE '%" +Codetxtbox.text+ "%') OR Description LIKE '%" +Codetxtbox.text+ "%'))"

Sqlda = New SqlDataAdapter(strSQL, SqlConn)

DS = new DataSet()
Sqlda.Fill(DS,"LookupCodes")
If DS.Tables(0).Rows.Count > 0 Then
CodeSearchList.DataSource = DS.Tables("LookupCodes")
CodeSearchList.DataBind()
CodeSearchList.Visible = True
else
Response.Write ("No Records Found")
CodeSearchList.Visible = False
end if
Catch ex AS Exception

Response.Write(ex.ToString & "<br>")
Finally
SqlConn.Close()
End Try
End Sub

Sub CodeSearchList_Paging(sender As Object, e As DataGridPageChangedEventArgs)
CodeSearchList.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub

Sub SortCommand_OnClick(Source As Object, E As DataGridSortCommandEventArgs)
strSQL = strSQL & " ORDER BY " & E.SortExpression
BindData()
End Sub

</script>
Thanks in advance...

 
Old September 30th, 2005, 11:44 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

In your sortcommand sub, you need to refill your dataset, if that is what you are using for your datasource then rebind your grid. Everthing else looks ok.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting a datagrid trekmp ADO.NET 7 December 18th, 2004 06:56 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
DataGrid Sorting spm74 ASP.NET 1.0 and 1.1 Basics 3 May 26th, 2004 08:52 AM
Sorting a Datagrid - Help Please! Pauline VS.NET 2002/2003 0 August 29th, 2003 06:20 AM
DataGrid Sorting Example SPRIBob BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 10 July 30th, 2003 09:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.