Home All Groups Group Topic Archive Search About
Author
16 Dec 2005 11:10 AM
mfr
I'm trying to implement sorting in a GridView. The GridView is connected to
an ObjectDataSource that uses a stored procedure to return the data.

I believe I've implemented everything correctly but the sorting does not work.

By tracing through the program
* In the gridviews OnSorting event handler, the
GridViewSortEventArgs.SortExpression is set correctly.
* In the select function called by the ObjectDataSource, the sort parameter
is set to an empty string
* In the gridview.Sorted handler, the GridView.SortExpression is also set to
an empty string.

I'm not doing anything in the gridview.onsorting handler - I thought about
setting the gridview.sortexpresssion but this is read-only.

Any clues as to why it isn't working would be appreciated. Below are
snippets from my code....


<asp:GridView ID="SightingsGridView" runat="server"
AutoGenerateColumns="false" AllowPaging="true" PageSize="20"
AllowSorting="true"
OnPageIndexChanging="SightingsGridView_PageIndexChanging"
OnSorting = "SightingsGridView_Sorting"
OnSorted =  "SightingsGridView_Sorted">
<Columns>
<asp:BoundField DataField = "SightingType" HeaderText = "Type"
SortExpression="Type"/>
<asp:BoundField DataField = "NetworkOwner" HeaderText = "Owner"
sortexpression="Owner"/>
</asp:GridView>



And in the code-behind page
// create an object source to link to the database and set the object
creating event handler

ObjectDataSource objectDataSource = new ObjectDataSource("ListSightings",
"GetList");
objectDataSource.ObjectCreating += new
ObjectDataSourceObjectEventHandler(objectDataSource_ObjectCreating);
objectDataSource.TypeName = "ListSightings";
objectDataSource.EnablePaging = true;
objectDataSource.StartRowIndexParameterName = "startRowIndex";
objectDataSource.MaximumRowsParameterName = "maximumRows";
objectDataSource.SelectCountMethod = "GetCount";
objectDataSource.SortParameterName = "Sortby";
SightingsGridView.DataSource = objectDataSource;



Regards,
Dave.

Author
17 Dec 2005 12:49 AM
Eric
I'm probably stating the obivous, but can you sort it in the source?
Otherwise you will have to use DataView.

rg,
Eric



Show quoteHide quote
"mfr" <m**@discussions.microsoft.com> schreef in bericht
news:A056228D-CDE5-49AD-A8C9-A9063B3BE48C@microsoft.com...
> I'm trying to implement sorting in a GridView. The GridView is connected
> to
> an ObjectDataSource that uses a stored procedure to return the data.
>
> I believe I've implemented everything correctly but the sorting does not
> work.
>
> By tracing through the program
> * In the gridviews OnSorting event handler, the
> GridViewSortEventArgs.SortExpression is set correctly.
> * In the select function called by the ObjectDataSource, the sort
> parameter
> is set to an empty string
> * In the gridview.Sorted handler, the GridView.SortExpression is also set
> to
> an empty string.
>
> I'm not doing anything in the gridview.onsorting handler - I thought about
> setting the gridview.sortexpresssion but this is read-only.
>
> Any clues as to why it isn't working would be appreciated. Below are
> snippets from my code....
>
>
> <asp:GridView ID="SightingsGridView" runat="server"
> AutoGenerateColumns="false" AllowPaging="true" PageSize="20"
> AllowSorting="true"
> OnPageIndexChanging="SightingsGridView_PageIndexChanging"
> OnSorting = "SightingsGridView_Sorting"
> OnSorted =  "SightingsGridView_Sorted">
> <Columns>
> <asp:BoundField DataField = "SightingType" HeaderText = "Type"
> SortExpression="Type"/>
> <asp:BoundField DataField = "NetworkOwner" HeaderText = "Owner"
> sortexpression="Owner"/>
> </asp:GridView>
>
>
>
> And in the code-behind page
> // create an object source to link to the database and set the object
> creating event handler
>
> ObjectDataSource objectDataSource = new ObjectDataSource("ListSightings",
> "GetList");
> objectDataSource.ObjectCreating += new
> ObjectDataSourceObjectEventHandler(objectDataSource_ObjectCreating);
> objectDataSource.TypeName = "ListSightings";
> objectDataSource.EnablePaging = true;
> objectDataSource.StartRowIndexParameterName = "startRowIndex";
> objectDataSource.MaximumRowsParameterName = "maximumRows";
> objectDataSource.SelectCountMethod = "GetCount";
> objectDataSource.SortParameterName = "Sortby";
> SightingsGridView.DataSource = objectDataSource;
>
>
>
> Regards,
> Dave.
>
Author
19 Dec 2005 9:56 AM
mfr
Eric,

My stored procedure will return the data in the correct sort order
(depending on which column has been clicked) but the sortexpression of the
clicked column isn't being passed to the select function that calls the
procedure.

The paging works fine and the start and count figure are passed to my stored
procedure as expected.

Regards,
Dave.

Show quoteHide quote
"Eric" wrote:

> I'm probably stating the obivous, but can you sort it in the source?
> Otherwise you will have to use DataView.
>
> rg,
> Eric
>
>
>
> "mfr" <m**@discussions.microsoft.com> schreef in bericht
> news:A056228D-CDE5-49AD-A8C9-A9063B3BE48C@microsoft.com...
> > I'm trying to implement sorting in a GridView. The GridView is connected
> > to
> > an ObjectDataSource that uses a stored procedure to return the data.
> >
> > I believe I've implemented everything correctly but the sorting does not
> > work.
> >
> > By tracing through the program
> > * In the gridviews OnSorting event handler, the
> > GridViewSortEventArgs.SortExpression is set correctly.
> > * In the select function called by the ObjectDataSource, the sort
> > parameter
> > is set to an empty string
> > * In the gridview.Sorted handler, the GridView.SortExpression is also set
> > to
> > an empty string.
> >
> > I'm not doing anything in the gridview.onsorting handler - I thought about
> > setting the gridview.sortexpresssion but this is read-only.
> >
> > Any clues as to why it isn't working would be appreciated. Below are
> > snippets from my code....
> >
> >
> > <asp:GridView ID="SightingsGridView" runat="server"
> > AutoGenerateColumns="false" AllowPaging="true" PageSize="20"
> > AllowSorting="true"
> > OnPageIndexChanging="SightingsGridView_PageIndexChanging"
> > OnSorting = "SightingsGridView_Sorting"
> > OnSorted =  "SightingsGridView_Sorted">
> > <Columns>
> > <asp:BoundField DataField = "SightingType" HeaderText = "Type"
> > SortExpression="Type"/>
> > <asp:BoundField DataField = "NetworkOwner" HeaderText = "Owner"
> > sortexpression="Owner"/>
> > </asp:GridView>
> >
> >
> >
> > And in the code-behind page
> > // create an object source to link to the database and set the object
> > creating event handler
> >
> > ObjectDataSource objectDataSource = new ObjectDataSource("ListSightings",
> > "GetList");
> > objectDataSource.ObjectCreating += new
> > ObjectDataSourceObjectEventHandler(objectDataSource_ObjectCreating);
> > objectDataSource.TypeName = "ListSightings";
> > objectDataSource.EnablePaging = true;
> > objectDataSource.StartRowIndexParameterName = "startRowIndex";
> > objectDataSource.MaximumRowsParameterName = "maximumRows";
> > objectDataSource.SelectCountMethod = "GetCount";
> > objectDataSource.SortParameterName = "Sortby";
> > SightingsGridView.DataSource = objectDataSource;
> >
> >
> >
> > Regards,
> > Dave.
> >
>
>
>