EnableSortingandPagingCallback when

J

jobs

I have a gridview that is refreshes when a dropdown is selected outside
of it. Sorting is enabled on the gridview but not working.

I read that I should set EnableSortingandPagingCallback to true to fix
the error:

The GridView 'GridView1' fired event Sorting which wasn't handled

However, I am now getting:

Callbacks are not supported on CommandField when the select button is
enabled because other controls on your page that are dependent on the
selected value of 'RatePlanGridView' for their rendering will not
update in a callback. Turn callbacks off on 'RatePlanGridView'.

Paging on the gridview appears to work fine, because I added these:

Protected Sub RatePlanGridView_PageIndexChanged(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
RatePlanGridView.PageIndexChanged
.. and I rebind (but I don't see code to set the new page)

End If

Protected Sub RatePlanGridView_PageIndexChanging(ByVal sender As
Object, ByVal e As GridViewPageEventArgs) Handles
RatePlanGridView.PageIndexChanging
RatePlanGridView.PageIndex = e.NewPageIndex
RatePlanGridView.DataBind()
End Sub


I get the noted error under

Protected Sub RouteCodesList_SelectedIndexChanged
when I attempt to bind.


The gridview is configured as follows:

<asp:GridView ID="RatePlanGridView" runat="server"
AutoGenerateColumns="False" DataKeyNames="RouteCode"
Width="700px" SkinID="GridView"
AllowPaging="True" AllowSorting="true" ShowFooter="true"
PagerSettings-Mode="NumericFirstLast">


Is there an event for sorting I should set, and will I have to take of
sorting myself?
 
J

jobs

onsorting="Gridview_sorting"

and

Protected Sub GridView_Sorting(ByVal sender As Object, ByVal e As
GridViewSortEventArgs)
...

End Sub



Can somebody point me in the right direction in how to finish this, I
presume with e.sortdirection and/or e.sortexpression. I found some C#
code I tried to convert, but vb.net knows nothing about
ConversionHelpers or CovertSortDirectionToSQL. I am unclear about how
the sorting is even going to work.

Protected Sub RatePlanGridView_Sorting(ByVal sender As Object,
ByVal e As GridViewSortEventArgs)
Dim dataTable As DataTable =
CType(ConversionHelpers.AsWorkaround(RatePlanGridView.DataSource,
GetType(DataTable)), DataTable)
If Not (dataTable Is Nothing) Then
Dim dataView As DataView = New DataView(dataTable)
dataView.Sort = e.SortExpression + " " +
ConvertSortDirectionToSql(e.SortDirection)
RatePlanGridView.DataSource = dataView
RatePlanGridView.DataBind()
End If
 
J

jobs

The Grid displays with multiple rows. I select to sort of a particular
field and the below event is fired, but DataTable is Nothing so code is
skipped.


Protected Sub ChargeGridView_Sorting(ByVal sender As Object, ByVal e
As GridViewSortEventArgs)
Dim dataTable As DataTable = CType(ChargeGridView.DataSource,
DataTable)
If Not (dataTable Is Nothing) Then '****** (THIS IS ALWAYS
FALSE) ****
Dim dataView As DataView = New DataView(dataTable)
dataView.Sort = e.SortExpression + " " + e.SortDirection
Response.Write(e.SortExpression + " " + e.SortDirection)
ChargeGridView.DataSource = dataView
ChargeGridView.DataBind()
End If
End Sub

The GridView:

<asp:GridView ID="ChargeGridView" runat="server"
AutoGenerateColumns="False" DataKeyNames="RouteCode"
Width="700px" SkinID="GridView"
AllowPaging="True" AllowSorting="true"
OnSorting="ChargeGridView_Sorting" ShowFooter="true"
PagerSettings-Mode="NumericFirstLast">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top