protected void gvUsers_Sorting(object sender, GridViewSortEventArgs e) { //re-run the query, use linq to sort the objects based on the arg. //perform a search using the constraints given //you could have this saved in Session, rather than requerying your datastore List <ADUCUser> users = ADUCUser.GetList(Membership.GetAllUsers(), Profile); if (users != null) { var param = Expression.Parameter(typeof(ADUCUser), e.SortExpression); var sortExpression = Expression.Lambda <Func <ADUCUser, object> >(Expression.Convert(Expression.Property(param, e.SortExpression), typeof(object)), param); if (GridViewSortDirection == SortDirection.Ascending) { gvUsers.DataSource = users.AsQueryable <ADUCUser>().OrderBy(sortExpression); GridViewSortDirection = SortDirection.Descending; } else { gvUsers.DataSource = users.AsQueryable <ADUCUser>().OrderByDescending(sortExpression); GridViewSortDirection = SortDirection.Ascending; } gvUsers.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { lblEditMsg.Visible = false; if (!IsPostBack) { //MembershipUserCollection allUsers = Membership.GetAllUsers(); MembershipUserCollection allUsersWithoutCurrent = Membership.GetAllUsers(); allUsersWithoutCurrent.Remove(User.Identity.Name); List <ADUCUser> list = ADUCUser.GetList(allUsersWithoutCurrent, Profile); ddlEditUser.DataSource = list; ddlEditUser.DataBind(); ((TextBox)cuwCreateUser.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text = rndPassword.GeneratePassword(10); } if (HttpContext.Current.Items["username"] != null && HttpContext.Current.Items["password"] != null) { string username = HttpContext.Current.Items["username"].ToString(); string password = HttpContext.Current.Items["password"].ToString(); tcUserManagement.ActiveTabIndex = 1; cuwCreateUser.ActiveStepIndex = 1; cuwCreateUser.CompleteSuccessText = String.Format("{0} oprettet med password: {1}", username, password);; } }
protected void lnkbtnShowUsers_Click(object sender, EventArgs e) { gvUsers.DataSource = ADUCUser.GetList(Membership.GetAllUsers(), Profile); gvUsers.DataBind(); lnkbtnShowUsers.Visible = false; }