Sorting in Gridview .net 2.0

Posts   
 
    
NickEales
User
Posts: 2
Joined: 06-Nov-2005
# Posted on: 08-Nov-2005 22:51:33   

I've databound the Gridview to my ObjectDatasource this is populated through my entity manager class which returns a sorted entitycollection.

 <asp:ObjectDataSource ID="SkillDataSource" runat="server" SelectMethod="getSkillsByProfessionID"
                    TypeName="NickEales.BuildBot.BL.SkillManager" SortParameterName="sorterString">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ProfessionDropDown" Name="selectedProfessionID"
                            PropertyName="SelectedValue" Type="Int32" />
                    </SelectParameters>
                </asp:ObjectDataSource>
<asp:GridView ID="SkillGrid" runat="server" Width="100%" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SkillDataSource" CellPadding="2" ForeColor="Black" GridLines="None" BackColor="LightGoldenrodYellow">
<asp:TemplateField ShowHeader="False" SortExpression="CastTime" HeaderText="Cast">
                            <ItemTemplate>
                                <asp:Label Text='<%# Eval("CastTime") %>' runat="server" />&nbsp;<asp:Image ID="Image1" runat="server" ImageUrl="~/images/icons/casttime.gif" />
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right" />
                        </asp:TemplateField>

The sort expression is passed through to the manager object where it sorts the entity collection through the Sort(SortExpression, Direction, Compare) method. How exactly do I get the direction from the sort expression as the only thing which is passed through this string is the field to sort on.

I'd prefer not to do any kind of eventhandling just yet as I'm doing this project as a testcase to see how much can actually be done at design-time with LLBLgen and the VS.Net 2005.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 09-Nov-2005 15:05:35   

The sort expression is passed through to the manager object where it sorts the entity collection through the Sort(SortExpression, Direction, Compare) method. How exactly do I get the direction from the sort expression as the only thing which is passed through this string is the field to sort on.

I'm afraid I didn't understand your question However the EntityCollection Sort function, has the following definition

public void Sort(string propertyName, ListSortDirection direction, IComparer comparerToUse);

propertyName (property to sort on) direction (the sort direction) comparerToUse (The comparer to use. If null, it will use the default comparer.)

NickEales
User
Posts: 2
Joined: 06-Nov-2005
# Posted on: 09-Nov-2005 16:28:26   

My question is:

How do I get the sort direction from the gridview in design-time without resorting to picking it up as a parameter of a sorting handler.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Nov-2005 15:03:00   

You should maintain the sort direction at run time.

Please refer to the following link: http://www.dotnetbips.com/09D319DD-9FD0-471A-A791-E295E9F5F39B.aspx?articleid=7