protected void gvUsers_Sorting(object sender, GridViewSortEventArgs e) { // prop is null at this point, so the next line fails if (ListUsers.Count > 0) { string orderby = gvUsers.OrderBy; SortDirection direction = SortDirection.Ascending; if (orderby.ToLower().EndsWith("desc")) { direction = SortDirection.Descending; orderby = orderby.Split(' ')[0]; } List <Twitter.User> sortedList = null; if (orderby == Constants.GetVariableName(() => ListUsers[0].Index)) { if (direction == SortDirection.Ascending) { sortedList = ListUsers.OrderBy(x => x.Index).ToList(); } else { sortedList = ListUsers.OrderByDescending(x => x.Index).ToList(); } } else if (orderby == Constants.GetVariableName(() => ListUsers[0].ScreenName)) { if (direction == SortDirection.Ascending) { sortedList = ListUsers.OrderBy(x => x.ScreenName).ToList(); } else { sortedList = ListUsers.OrderByDescending(x => x.ScreenName).ToList(); } } else if (orderby == Constants.GetVariableName(() => ListUsers[0].ProfileImage)) { if (direction == SortDirection.Ascending) { sortedList = ListUsers.OrderBy(x => x.ProfileImage).ToList(); } else { sortedList = ListUsers.OrderByDescending(x => x.ProfileImage).ToList(); } } else if (orderby == Constants.GetVariableName(() => ListUsers[0].UserId)) { if (direction == SortDirection.Ascending) { sortedList = ListUsers.OrderBy(x => x.UserId).ToList(); } else { sortedList = ListUsers.OrderByDescending(x => x.UserId).ToList(); } } ListUsers = new BindingList <Twitter.User>(sortedList); BindData(); } }