protected void gvClubs_RowDataBound(object sender, GridViewRowEventArgs e) { if (e != null && e.Row.RowType == DataControlRowType.DataRow) { ViewClub vc = (ViewClub)e.Row.FindControl("viewClub1"); vc.ActiveClub = (Club)e.Row.DataItem; } }
public static string PopulateClub(int idClub) { StringBuilder sb = new StringBuilder(); try { // We have no Page, so things like Page_Load don't get called. // We fix this by faking a page and calling Server.Execute on it. This sets up the form and - more importantly - causes Page_load to be called on loaded controls. using (Page p = new FormlessPage()) { p.Controls.Add(new HtmlForm()); using (StringWriter sw1 = new StringWriter(CultureInfo.InvariantCulture)) HttpContext.Current.Server.Execute(p, sw1, false); HttpRequest r = HttpContext.Current.Request; if (!r.IsLocal && !r.UrlReferrer.Host.EndsWith(Branding.CurrentBrand.HostName, StringComparison.OrdinalIgnoreCase)) { throw new MyFlightbookException("Unauthorized attempt to populate club!"); } Club c = Club.ClubWithID(idClub); if (c == null) { return(string.Empty); } ViewClub vc = (ViewClub)p.LoadControl("~/Controls/ClubControls/ViewClub.ascx"); vc.LinkToDetails = true; vc.ActiveClub = c; p.Form.Controls.Add(vc); // Now, write it out. using (StringWriter sw = new StringWriter(sb, CultureInfo.InvariantCulture)) { using (HtmlTextWriter htmlTW = new HtmlTextWriter(sw)) { vc.RenderControl(htmlTW); } } } } catch (MyFlightbookException ex) { sb.Append(ex.Message); } return(sb.ToString()); }