protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridDataItem) { GridDataItem item = (GridDataItem)e.Item; PersonWithUser user = (PersonWithUser)e.Item.DataItem; string personId = ((HiddenField)item.FindControl("hfPersonId")).Value; bool isPrimaryExisting = false; string userName = string.Empty; if (user.User != null) { userName = (string.IsNullOrEmpty(user.User.Name)) ? string.Empty : user.User.Name; } //add primary site if any for the person Label primarySite = new Label(); primarySite = (Label)item.FindControl("lblPrimarySite"); primarySite.CssClass = "bold"; primarySite.Text = GetPrimarySite(personId); if (!string.IsNullOrEmpty(primarySite.Text)) { isPrimaryExisting = true; primarySite.Text += "<img src=../App_Themes/default/icons/star_16.png />"; } else { isPrimaryExisting = false; } //add secondary sites if any for the person. Label sites = new Label(); sites = (Label)item.FindControl("lblSecondarySites"); sites.Text = GetSecondarySites(personId, isPrimaryExisting); //append modal popup on the delete link. LinkButton lnkBtnDelete = new LinkButton(); lnkBtnDelete = (LinkButton)item.FindControl("lnkBtnDelete"); lnkBtnDelete.OnClientClick = "showDeleteUserPopup('" + personId + "','" + userName + "');"; } }
/// <summary> /// A Custom list of PersonWithUser constructed by searching the concatenated primary and secondary sites. Acts like a custom filter. /// </summary> /// <param name="personsAndUsers"></param> /// <param name="siteName"></param> protected void AddSiteToList(List <PersonWithUser> personsAndUsers, string siteName) { if (!string.IsNullOrEmpty(siteName)) { //setting the DS to original list to perform filtering. Only assign it once when this function is called in loop for ',' seperated list. if (RadGrid1.DataSource != originalDS) { RadGrid1.DataSource = originalDS; RadGrid1.DataBind(); } //loop through the radgrid rows.Combine primary and secondary sites and check if site name exists in it. foreach (GridDataItem item in RadGrid1.Items) { string userName = ((LinkButton)item["LoginId"].FindControl("imgBtnView")).Text; Label lblPrimarySite = (Label)item["PrimarySite"].FindControl("lblPrimarySite"); Label lblSecondarySites = (Label)item["PrimarySite"].FindControl("lblSecondarySites"); string sites = lblPrimarySite.Text + lblSecondarySites.Text; //if site name is existing in the concatenated string then add it to the PersonUser list. if (!string.IsNullOrEmpty(userName) && sites.ToLower().Contains(siteName.ToLower())) { Person person = PersonManager.GetPersonByUserName(userName); User user = MembershipManager.GetUserByName(userName); Site defaultSite = PersonManager.GetDefaultSiteByPerson(person); if (defaultSite == null) { defaultSite = new Site(); } if (person != null && user != null) { PersonWithUser personUser = new PersonWithUser() { Person = person, User = user, PrimarySite = defaultSite }; personsAndUsers.Add(personUser); } } } } }