Yes you can do it. This is how you do it.
Assuming you have a GridView that calls the entries from the BusinessLayer method. I will take the UserManager example as a business level proxy class.
[DataObjectAttribute()] public static class UserManager { [DataObjectMethod(DataObjectMethodType.Select, true)] public static UserCollection GetUsers() { return UserDB.GetAll(); } [DataObjectMethod(DataObjectMethodType.Select, false)] public static UserCollection GetUsers(string sortExpression) { UserCollection users = UserDB.GetAll(); users.Sort(new EntityComparer<User>(sortExpression)); return users; } }
Look at this line of code in the overloaded GetUsers method.
users.Sort(new EntityComparer<User>(sortExpression));
I wrote a Generic Comparer implementation for my business objects. EntityComparer is just a general class that implements the IComparer interface. You can write your own implementation of Comparer [which implements the IComparer interface] and name it as the code above.
This is what my GridView looks like ..
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ObjectDataSource1"> <Columns> <asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" /> <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" /> <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" /> <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" SortExpression="CompanyName" /> </Columns> </asp:GridView> <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetUsers" TypeName="FilePark.BusinessLayer.UserManager"></asp:ObjectDataSource>
Also note that the GridView will pass sortExpression after the postback and will call the overloaded method.
this. __curious_geek
source share