Return GridView sort to default

D

David C

I have an asp GridView that has the SqlDataSource below.

<asp:SqlDataSource ID="SqlvwRepairOrdersOpen" runat="server"
ConnectionString="<%$ ConnectionStrings:MgmtConnectionString %>"
SelectCommand="SELECT [RecordID], [RepairOrderID], [Problems],
[TasksToDo], [Customer], [Vehicle], [Expected], [ROTotal], [JobSize],
[PartsCount], [Payor], [SortGroup], [Parts], [InsuranceID] FROM
[vw_RepairOrdersOpen] ORDER BY [SortGroup], [RepairOrderID] DESC">
</asp:SqlDataSource>

I also have a CheckBox control with ID of ckNormalSort and when it is
checked, I want the GridView to go back to the initial sort from the
SqlDataSource. I have tried the code below in both Page_Load and in the
CheckChanged event of the checkbox and neither works. How can this be
accomplished? Thanks.

David


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If ckNormalSort.Checked = True Then
SqlvwRepairOrdersOpen.SelectCommand = "SELECT [RecordID],
[RepairOrderID], [Problems], [TasksToDo], [Customer], [Vehicle], [Expected],
[ROTotal], [JobSize], [PartsCount], [Payor], [SortGroup], [Parts],
[InsuranceID] FROM [vw_RepairOrdersOpen] ORDER BY [SortGroup],
[RepairOrderID] DESC"
SqlvwRepairOrdersOpen.DataBind()
End If
End Sub
 
M

miher

David C said:
I have an asp GridView that has the SqlDataSource below.

<asp:SqlDataSource ID="SqlvwRepairOrdersOpen" runat="server"
ConnectionString="<%$ ConnectionStrings:MgmtConnectionString %>"
SelectCommand="SELECT [RecordID], [RepairOrderID], [Problems],
[TasksToDo], [Customer], [Vehicle], [Expected], [ROTotal], [JobSize],
[PartsCount], [Payor], [SortGroup], [Parts], [InsuranceID] FROM
[vw_RepairOrdersOpen] ORDER BY [SortGroup], [RepairOrderID] DESC">
</asp:SqlDataSource>

I also have a CheckBox control with ID of ckNormalSort and when it is
checked, I want the GridView to go back to the initial sort from the
SqlDataSource. I have tried the code below in both Page_Load and in the
CheckChanged event of the checkbox and neither works. How can this be
accomplished? Thanks.

David


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If ckNormalSort.Checked = True Then
SqlvwRepairOrdersOpen.SelectCommand = "SELECT [RecordID],
[RepairOrderID], [Problems], [TasksToDo], [Customer], [Vehicle],
[Expected], [ROTotal], [JobSize], [PartsCount], [Payor], [SortGroup],
[Parts], [InsuranceID] FROM [vw_RepairOrdersOpen] ORDER BY [SortGroup],
[RepairOrderID] DESC"
SqlvwRepairOrdersOpen.DataBind()
End If
End Sub

Hi,
I hope i got Your problem right: You have a sortable gridview and You want
to reset the sorting.
In that case You can simply reset the SortExpression of the gridview, just
by calling the Sort method of it with string.Empty.
Hope You find this useful.
-Zsolt
 
D

David C

miher said:
David C said:
I have an asp GridView that has the SqlDataSource below.

<asp:SqlDataSource ID="SqlvwRepairOrdersOpen" runat="server"
ConnectionString="<%$ ConnectionStrings:MgmtConnectionString %>"
SelectCommand="SELECT [RecordID], [RepairOrderID], [Problems],
[TasksToDo], [Customer], [Vehicle], [Expected], [ROTotal], [JobSize],
[PartsCount], [Payor], [SortGroup], [Parts], [InsuranceID] FROM
[vw_RepairOrdersOpen] ORDER BY [SortGroup], [RepairOrderID] DESC">
</asp:SqlDataSource>

I also have a CheckBox control with ID of ckNormalSort and when it is
checked, I want the GridView to go back to the initial sort from the
SqlDataSource. I have tried the code below in both Page_Load and in the
CheckChanged event of the checkbox and neither works. How can this be
accomplished? Thanks.

David


Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If ckNormalSort.Checked = True Then
SqlvwRepairOrdersOpen.SelectCommand = "SELECT [RecordID],
[RepairOrderID], [Problems], [TasksToDo], [Customer], [Vehicle],
[Expected], [ROTotal], [JobSize], [PartsCount], [Payor], [SortGroup],
[Parts], [InsuranceID] FROM [vw_RepairOrdersOpen] ORDER BY [SortGroup],
[RepairOrderID] DESC"
SqlvwRepairOrdersOpen.DataBind()
End If
End Sub

Hi,
I hope i got Your problem right: You have a sortable gridview and You
want to reset the sorting.
In that case You can simply reset the SortExpression of the gridview, just
by calling the Sort method of it with string.Empty.
Hope You find this useful.
-Zsolt

That was it. Thank you.

David
 
Top