Exemplo n.º 1
0
        public override void InitializeCell(
            DataControlFieldCell cell,
            DataControlCellType cellType,
            DataControlRowState rowState,
            int rowIndex)
        {
            if (cellType == DataControlCellType.DataCell)
               {
                    var control = new DynamicControl() { DataField = DataField };

                    // Copy various properties into the control
                    control.UIHint = UIHint;
                    control.HtmlEncode = HtmlEncode;
                    control.NullDisplayText = NullDisplayText;

                    // this the default for DynamicControl and has to be
                    // manually changed you do not need this line of code
                    // its there just to remind us what we are doing.
                    control.Mode = DataBoundControlMode.ReadOnly;

                    cell.Controls.Add(control);
               }
               else
               {
                    base.InitializeCell(cell, cellType, rowState, rowIndex);
               }
        }
        /// <summary>
        /// See base class documentation
        /// </summary>
        public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType,
                                            DataControlRowState rowState, int rowIndex)
        {
            base.InitializeCell(cell, cellType, rowState, rowIndex);

            if (cellType == DataControlCellType.DataCell)
            {
                DynamicControl control = CreateDynamicControl();
                control.DataField = DataField;
                control.Mode      = DetermineControlMode(rowState);

                // Copy various properties into the control
                if (_customApplyFormatInEditModeSet)
                {
                    control.ApplyFormatInEditMode = ApplyFormatInEditMode;
                }
                if (_customConvertEmptyStringToNullSet)
                {
                    control.ConvertEmptyStringToNull = ConvertEmptyStringToNull;
                }
                control.DataFormatString = DataFormatString;
                if (ViewState["HtmlEncode"] == null)
                {
                    // There is no Column in Design Mode
                    if (!DesignMode)
                    {
                        control.HtmlEncode = Column.HtmlEncode;
                    }
                }
                else
                {
                    control.HtmlEncode = HtmlEncode;
                }
                control.NullDisplayText = NullDisplayText;
                control.UIHint          = UIHint;
                control.ValidationGroup = ValidationGroup;

                // Pass it all the extra declarative attributes that we got
                control.SetAttributes(_attributes);

                ConfigureDynamicControl(control);

                cell.Controls.Add(control);
            }
        }
Exemplo n.º 3
0
        public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
        {
            if (cellType == DataControlCellType.Header || cellType == DataControlCellType.Footer)
            {
                base.InitializeCell(cell, cellType, rowState, rowIndex);
                return;
            }

            DynamicControl dc = new DynamicControl();

            dc.ApplyFormatInEditMode    = ApplyFormatInEditMode;
            dc.ConvertEmptyStringToNull = ConvertEmptyStringToNull;
            dc.Column           = MyColumn;
            dc.DataField        = DataField;
            dc.DataFormatString = DataFormatString;
            dc.HtmlEncode       = HtmlEncode;
            dc.Mode             = (rowState & DataControlRowState.Edit) != 0 ? DataBoundControlMode.Edit :
                                  (rowState & DataControlRowState.Insert) != 0 ? DataBoundControlMode.Insert : DataBoundControlMode.ReadOnly;
            dc.NullDisplayText = NullDisplayText;
            dc.UIHint          = UIHint;
            dc.InternalSetAttributes(attributes);

            cell.Controls.Add(dc);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Find the field template for a column within the current naming container
 /// </summary>
 public static Control FindFieldTemplate(this Control control, string columnName)
 {
     return(control.FindControl(DynamicControl.GetControlIDFromColumnName(columnName)));
 }
Exemplo n.º 5
0
        //-------------------------------------------------------------------------------------------
        protected override void OnLoad(EventArgs e)
        {
            IEnumerable<MetaColumn> columns = Table.GetScaffoldColumns(this.Mode, this.ContainerType);

               List<string> Groups = new List<string>();
               foreach (MetaColumn column in columns)
               {
                    this.currentColumn = column;

                    var groupattribute = column.GetAttribute<ColumnGroupAttribute>();
                    HtmlGenericControl tabContent = (HtmlGenericControl)GeneralControls;
                    if (groupattribute != null)
                    {
                         string groupId = groupattribute.GroupName.Replace(" ", "_");
                         if (!Groups.Contains(groupId))
                         {
                              Groups.Add(groupId);

                              var div = new HtmlGenericControl("div");
                              div.ID = groupId;
                              Tabs.Controls.Add(div);

                              LiteralControl tab = new LiteralControl();
                              tab.Text = "<li><a href=\"#" + div.ClientID + "\">" + groupattribute.GroupName + "</a></li>";
                              tabheader.Controls.Add(tab);
                         }
                         tabContent = (HtmlGenericControl)Tabs.FindControl(groupId);
                    }

                    HtmlGenericControl cellLine = new HtmlGenericControl("div");
                    cellLine.Attributes["class"] = "formLine";
                    tabContent.Controls.Add(cellLine);

                    HtmlGenericControl cellLabel = new HtmlGenericControl("div");
                    cellLabel.Attributes["class"] = "formLabel";
                    cellLabel.InnerText = column.DisplayName + ":";
                    cellLine.Controls.Add(cellLabel);

                    HtmlGenericControl cellData = new HtmlGenericControl("div");
                    cellData.Attributes["class"] = "formData";
                    var dynamicControl = new DynamicControl()
                    {
                         Mode = Mode,
                         DataField = column.Name,
                         ValidationGroup = this.ValidationGroup
                    };
                    cellData.Controls.Add(dynamicControl);
                    cellLine.Controls.Add(cellData);

                    HtmlGenericControl br = new HtmlGenericControl("div");
                    br.Style["clear"] = "both";
                    br.Style["height"] = "1px";
                    cellLine.Controls.Add(br);
               }

               var clearDiv = new HtmlGenericControl("div");
               clearDiv.InnerHtml = "&nbsp;";
               clearDiv.Style["clear"] = "both";
               GeneralControls.Controls.Add(clearDiv);

               //if (tabheader.Controls.Count == 1)
               //{
               //     tabheader.Controls.Clear();
               //}
               //else
               {
                    string script = "<script type='text/javascript'>$(document).ready(function () { $(\"#tableControl\").tabs(); });</script>";
                    ScriptManager.RegisterStartupScript(Page, GetType(), "TableControlInit", script, false);
               }
        }
		public override void InitializeCell (DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex)
		{
			if (cellType == DataControlCellType.Header || cellType == DataControlCellType.Footer) {
				base.InitializeCell (cell, cellType, rowState, rowIndex);
				return;
			}

			DynamicControl dc = new DynamicControl ();
			dc.ApplyFormatInEditMode = ApplyFormatInEditMode;
			dc.ConvertEmptyStringToNull = ConvertEmptyStringToNull;
			dc.Column = MyColumn;
			dc.DataField = DataField;
			dc.DataFormatString = DataFormatString;
			dc.HtmlEncode = HtmlEncode;
			dc.Mode = (rowState & DataControlRowState.Edit) != 0 ? DataBoundControlMode.Edit :
				(rowState & DataControlRowState.Insert) != 0 ? DataBoundControlMode.Insert : DataBoundControlMode.ReadOnly;
			dc.NullDisplayText = NullDisplayText;
			dc.UIHint = UIHint;
			dc.InternalSetAttributes (attributes);
			
			cell.Controls.Add (dc);
		}
Exemplo n.º 7
0
		public void ValidationGroup ()
		{
			// TODO: more complicated tests involving actual page and validation
			var dc = new DynamicControl ();
			dc.ValidationGroup = "Group1";
			Assert.AreEqual ("Group1", dc.ValidationGroup, "#A1");
		}
Exemplo n.º 8
0
		public void Mode ()
		{
			var dc = new DynamicControl (DataBoundControlMode.Edit);
			Assert.AreEqual (DataBoundControlMode.Edit, dc.Mode, "#A1");

			dc.Mode = DataBoundControlMode.Insert;
			Assert.AreEqual (DataBoundControlMode.Insert, dc.Mode, "#A2");

			dc.Mode = DataBoundControlMode.ReadOnly;
			Assert.AreEqual (DataBoundControlMode.ReadOnly, dc.Mode, "#A3");
		}
Exemplo n.º 9
0
		public void IFieldTemplateHost_FormattingOptions ()
		{
			var dc = new DynamicControl ();

			Assert.IsNotNull (((IFieldTemplateHost)dc).FormattingOptions, "#A1");
			Assert.AreEqual (dc, ((IFieldTemplateHost)dc).FormattingOptions, "#A2");
		}
Exemplo n.º 10
0
		public void GetAttribute ()
		{
			var dc = new DynamicControl ();
			Assert.AreEqual (String.Empty, dc.GetAttribute ("NoSuchAttribute"), "#A1");

			dc.SetAttribute ("MyAttribute", "value");
			Assert.AreEqual ("value", dc.GetAttribute ("MyAttribute"), "#B1");

			// Nice...
			AssertExtensions.Throws<KeyNotFoundException> (() => {
				dc.GetAttribute ("NoSuchAttribute");
			}, "#C1");
		}
Exemplo n.º 11
0
		public void DataField_2 ()
		{
			var dc = new DynamicControl ();

			dc.DataField = null;
			Assert.AreEqual (String.Empty, dc.DataField, "#A1");

			var c = dc.Column;
			Assert.IsNull (c, "#A1-1");

			dc.DataField = "MyField";
			Assert.AreEqual ("MyField", dc.DataField, "#B1");

			c = dc.Column;
			Assert.IsNull (c, "#B1-1");
		}
Exemplo n.º 12
0
		public void DataField ()
		{
			var dc = new DynamicControl ();

			Assert.AreEqual (String.Empty, dc.DataField, "#A1");
			dc.DataField = "MyField";
			Assert.AreEqual ("MyField", dc.DataField, "#A2");

			dc.DataField = "AnotherField";
			Assert.AreEqual ("AnotherField", dc.DataField, "#A3");

			dc.DataField = String.Empty;
			Assert.AreEqual (String.Empty, dc.DataField, "#A4");

			dc.DataField = null;
			Assert.AreEqual (String.Empty, dc.DataField, "#A5");
		}
Exemplo n.º 13
0
		public void CssClass ()
		{
			var dc = new DynamicControl ();
			dc.CssClass = "MyCssClass";
			Assert.AreEqual ("MyCssClass", dc.CssClass, "#A1");

			var test = new WebTest ("ListView_DynamicControl_01.aspx");
			test.Invoker = PageInvoker.CreateOnLoad (CssClass_OnLoad);
			var p = test.Run ();
			Assert.IsNotNull (test.Response, "#X1");
			Assert.AreNotEqual (HttpStatusCode.NotFound, test.Response.StatusCode, "#X1-1{0}Returned HTML:{0}{1}", Environment.NewLine, p);
			Assert.AreNotEqual (HttpStatusCode.InternalServerError, test.Response.StatusCode, "#X1-2{0}Returned HTML:{0}{1}", Environment.NewLine, p);
			Assert.IsFalse (String.IsNullOrEmpty (p), "#X1-3");

			string html = @"<span class=""activeCssClass"">

<span class=""field"">Active</span>:";
			Assert.IsTrue (p.IndexOf (html) != -1, "#Y1");
		}
Exemplo n.º 14
0
		public void Defaults ()
		{
			var dc = new DynamicControl ();

			Assert.AreEqual (false, dc.ApplyFormatInEditMode, "#A1");
			Assert.AreEqual (null, dc.Column, "#A2");
			Assert.AreEqual (false, dc.ConvertEmptyStringToNull, "#A3");
			Assert.AreEqual (String.Empty, dc.CssClass, "#A4");
			Assert.AreEqual (String.Empty, dc.DataField, "#A5");
			Assert.AreEqual (String.Empty, dc.DataFormatString, "#A6");
			Assert.AreEqual (null, dc.FieldTemplate, "#A7");
			Assert.AreEqual (true, dc.HtmlEncode, "#A8");
			Assert.AreEqual (dc, ((IFieldTemplateHost)dc).FormattingOptions, "#A9");
			Assert.AreEqual (DataBoundControlMode.ReadOnly, dc.Mode, "#A10");
			Assert.AreEqual (String.Empty, dc.NullDisplayText, "#A11");
			// Throws NREX on .NET .... (why am I still surprised by this?)
			// Calls DynamicDataExtensions.FindMetaTable which is where the exception is thrown from
			// Assert.AreEqual (null, dc.Table, "#A12");
			Assert.AreEqual (String.Empty, dc.UIHint, "#A13");
			Assert.AreEqual (String.Empty, dc.ValidationGroup, "#A14");
		}
Exemplo n.º 15
0
 /// <summary>
 /// Provides a hook to further modify a DynamicControl that was created by the InitializeCell method
 /// </summary>
 /// <param name="control"></param>
 protected virtual void ConfigureDynamicControl(DynamicControl control) {
     Debug.Assert(control != null);
 }
 /// <summary>
 /// Provides a hook to further modify a DynamicControl that was created by the InitializeCell method
 /// </summary>
 /// <param name="control"></param>
 protected virtual void ConfigureDynamicControl(DynamicControl control)
 {
     Debug.Assert(control != null);
 }