Change
Me.DsContactDetails1.qryPOCReview.DefaultView.Sort() = e.SortExpression
To
Me.DsContactDetails1.Tables(0).DefaultView.Sort() = e.SortExpression
Thanks for your input, however, I get the same result.
This issue was resolved by setting the grid datasource property in Visual Studio to Unbound. Sort Logic worked fine after that. Apparently you can't have it both ways, you can either hardwire the grid datasource using VS. Or set it dynamically in the code, but the grid.databind() will use the VS setting even if you've changed the datasource dynamically for manipulation purposes. I recommend that you initially hardcode in VS during initial datagrid development then change the setting to Unbound when you start writing the support code. Maybe someone using VS 2005 can comment whether this is still an issue in the new version. Here is the final code (enhanced to use the VIEWSTATE for variable storage):
PrivateSub Page_Load(ByVal senderAs System.Object,ByVal eAs System.EventArgs)HandlesMyBase.Load
'Put user code to initialize the page here
If IsPostBack =FalseThen
viewstate("POCSort") = "Name"
viewstate("POCFilter") = "None"
viewstate("POCPgIndex") = 0
POCDataBind()
EndIf
EndSub
PrivateSub DataGrid1_PageIndexChanged(ByVal sourceAsObject, _
ByVal eAs System.Web.UI.WebControls.DataGridPageChangedEventArgs) _
Handles DataGrid1.PageIndexChanged
Me.Trace.Write("Contact Review.aspx", "Inside PageIndexChanged")
viewstate("POCPgIndex") = e.NewPageIndex
POCDataBind()
EndSub
PrivateSub DataGrid1_SortCommand(ByVal sourceAsObject, _
ByVal eAs System.Web.UI.WebControls.DataGridSortCommandEventArgs) _
Handles DataGrid1.SortCommand
Me.Trace.Write("Contact Review.aspx", "Inside DataGrid1_SortCommand")
viewstate("POCSort") = e.SortExpression
POCDataBind()
EndSub
PrivateSub POCDataBind()
Me.Trace.Write("Contact Review.aspx", "Inside POCDataBind")
Dim strPOCSortAsString =CStr(ViewState("POCSort"))
Dim strPOCFilterAsString =CStr(ViewState("POCFilter"))
Dim intPOCPgIndexAs Int32 =CInt(viewstate("POCPgIndex"))
Dim intCntRecAs Int32
'Dim ds As New System.Data.DataSet
'Dim da As New System.Data.SqlClient.SqlDataAdapter
Dim dvAsNew DataView
Me.Trace.Write("Contact Review.aspx", "POCSort=" & strPOCSort)
Me.Trace.Write("Contact Review.aspx", "POCFilter=" & strPOCFilter)
Me.Trace.Write("Contact Review.aspx", "POCPgIndex=" & Str(intPOCPgIndex))
'da = Me.SqlDataAdapter1
'ds = Me.DsContactDetails1
intCntRec =Me.SqlDataAdapter1.Fill(Me.DsContactDetails1, "qryPOCReview")
dv =Me.DsContactDetails1.Tables("qryPOCReview").DefaultView
If Len(strPOCSort) > 0Then
Me.Trace.Write("Contact Review.aspx", "Inside Sort")
dv.Sort = strPOCSort
EndIf
If (Len(strPOCFilter) > 0And (strPOCFilter <> "None"))Then
dv.RowFilter = strPOCFilter
EndIf
Me.DataGrid1.DataSource = dv
'Me.DataGrid1.DataMember = "qryPOCReview"
Me.DataGrid1.CurrentPageIndex = intPOCPgIndex
Me.DataGrid1.DataBind()
Me.LabelPages.Text = "Page " & Str(Me.DataGrid1.CurrentPageIndex + 1) & " of " & Str(Me.DataGrid1.PageCount)
Me.LabelRecords.Text = Str(intCntRec) & " Records Returned"
'Page.DataBind()
EndSub
Hi, try this
Private Sub DataGrid1_SortCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) _
Handles DataGrid1.SortCommand
Me.SqlDataAdapter1.Fill(Me.DsContactDetails1, "qryPOCReview")
Me.DsContactDetails1.qryPOCReview.DefaultView.Sort() = e.SortExpression
DataGrid1.DataBind()EndSub
Hope this works
No comments:
Post a Comment