I have a generic list e.g:
public class Person
{
public string Name {get;set;}
public string loginId {get;set;}
public string ContactNo {get;set;}
public string City {get;set;}
public string Country {get;set;}
}
After filling the list, I bound the list to Repeater control. In HeaderTemplate of my repeater control I have defined LinkButton as:
<HeaderTemplate>
<tr>
<th width="100px">
<asp:LinkButton ID="lnk1" runat="server" CommandName="Sort" CommandArgument="Name" Text="Name"></asp:LinkButton>
</th>
<th width="150px">
<asp:LinkButton ID="lnk2" runat="server" CommandName="Sort" CommandArgument="loginId" Text="loginId"></asp:LinkButton>
</th>
<th width="100px">
<asp:LinkButton ID="lnk3" runat="server" CommandName="Sort" CommandArgument="City" Text="City"></asp:LinkButton>
</th>
</tr>
</HeaderTemplate>
When user click any of the link, it fires ItemCommand event. In my ItemCommand method, I check for the command and if its a sort then Sort the list based on the CommandArgument
.
Here is my command event:
protected void Repeater1_ItemCommand(object sender, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Sort")
{
string str= e.CommandArgument.ToString();
//var lst=ListPerson.OrderBy(c=>c.[PropertyName from CommandArgument ????]);
var lst=ListPerson.OrderBy(?????)
}
}
NOTE:ListPerson is my previously populated list of type Person.
Any help is appreciated.