protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); // Dummy control to which we parent all the data item controls Control containerControl = new Control(); IEnumerable dataItems = ViewData.Eval(Name) as IEnumerable; bool hasData = false; if (dataItems != null) { int index = 0; foreach (object dataItem in dataItems) { hasData = true; RepeaterItem repeaterItem = new RepeaterItem(index, dataItem) { ViewData = new ViewDataDictionary(dataItem), }; ItemTemplate.InstantiateIn(repeaterItem); containerControl.Controls.Add(repeaterItem); index++; } } if (!hasData) { // If there was no data, instantiate the EmptyDataTemplate Control emptyDataContainer = new Control(); EmptyDataTemplate.InstantiateIn(emptyDataContainer); containerControl.Controls.Add(emptyDataContainer); } Controls.Add(containerControl); containerControl.DataBind(); }
public static void DataBindLayoutTemplate(ListView listView) { listView.ThrowIfNull(() => new ArgumentNullException("listView")); // Create a databound layout template. var template = new Control(); listView.LayoutTemplate.InstantiateIn(template); template.DataBind(); // Remove the existing, non-databound layout template. listView.Controls.RemoveAt(0); // Add the databound layout template. listView.Controls.Add(template); }
public string RenderControlToHtml(System.Web.UI.Control controlToRender) { string retValue = null; controlToRender.Visible = true; System.Text.StringBuilder sb = new System.Text.StringBuilder(); using (System.IO.StringWriter stWriter = new System.IO.StringWriter(sb, System.Globalization.CultureInfo.InvariantCulture)) { using (System.Web.UI.HtmlTextWriter htmlWriter = new System.Web.UI.HtmlTextWriter(stWriter)) { controlToRender.DataBind(); controlToRender.RenderControl(htmlWriter); htmlWriter.Flush(); stWriter.Flush(); retValue = sb.ToString(); } // End Using htmlWriter } // End Using stWriter return(retValue); } // End Function RenderControlToHtml
/// <summary>Applies editor modifications after creating the control.</summary> /// <param name="editor">The editor to modify.</param> public virtual void Modify(Control editor) { if (this.DataBind) editor.DataBind(); if (this.Focus) editor.Focus(); }
/// <summary> /// Binds all data to the control /// </summary> /// <param name="c">Control</param> public void DataBind(Control c) { if (c is MultiView) { MultiView mv = (MultiView)c; foreach (View v in mv.Views) { ActionControl(v.ID, ControlActionType.Hide); } ActionControl(mv.Views[mv.ActiveViewIndex].ID, ControlActionType.Show); } else { _bindedControls.Add(c); c.DataBind(); } }
public void InstantiateIn(Control container) { var names = Set.Split('|'); int i = 0, n; foreach (var name in names) { if (name == "*") { while (i < TemplateControls.Count) Add(container, TemplateControls[i++]); } else if (int.TryParse(name, out n)) { while (i < TemplateControls.Count && n > 0) Add(container, TemplateControls[i++]); } else { var icon = Icons.New(name); if (icon != null) { if (!string.IsNullOrEmpty(CommandArgument)) icon.CommandArgument = CommandArgument; Add(container, icon); } } } instantiatedContainer = container; container.DataBind(); }
public void Methods_Deny_Unrestricted () { Control c = new Control (); c.DataBind (); Assert.IsNull (c.FindControl ("mono"), "FindControl"); Assert.IsFalse (c.HasControls (), "HasControls"); c.RenderControl (writer); Assert.IsNotNull (c.ResolveUrl (String.Empty), "ResolveUrl"); c.SetRenderMethodDelegate (new RenderMethod (SetRenderMethodDelegate)); #if NET_2_0 c.ApplyStyleSheetSkin (page); Assert.IsNotNull (c.ResolveClientUrl (String.Empty), "ResolveClientUrl"); #endif c.Dispose (); }
protected override void CreateChildControls() { Controls.Clear(); if( StatusNameTemplate != null ) { String dispName = OrderLineStatusUtil.DisplayName(Status); var statusNameContainer = new OrderLineStatusNameContainer( OrderLineId, dispName ); StatusNameTemplate.InstantiateIn( statusNameContainer ); Controls.Add( statusNameContainer ); statusNameContainer.DataBind(); } if( ReactionInfoTemplate != null && ClientReaction.HasValue ) { var reaction = (OrderLineChangeReaction)ClientReaction.Value == OrderLineChangeReaction.Accept ? ( !string.IsNullOrEmpty( DisplayAccept ) ? DisplayAccept : OrderLineChangeReaction.Accept.ToTextOrName() ) : ( !string.IsNullOrEmpty( DisplayDecline ) ? DisplayDecline : OrderLineChangeReaction.Decline.ToTextOrName() ); var reactionInfoContainer = new ReactionInfoContainer( reaction, ClientReactionTime.Value ); ReactionInfoTemplate.InstantiateIn( reactionInfoContainer ); Controls.Add( reactionInfoContainer ); reactionInfoContainer.DataBind(); } //Показываем кнопки только для клиента if( ReactionCommandsTemplate != null && ClientReactionPending && SiteContext.Current.User.Role == SecurityRole.Client ) { var container = new Control(); ReactionCommandsTemplate.InstantiateIn( container ); Controls.Add( container ); container.DataBind(); } }