Rock.Web.UI.Controls.MergeFieldPicker.SetValue C# (CSharp) Method

SetValue() public method

Sets the value.
public SetValue ( string nodePath ) : void
nodePath string The node path.
return void
        public void SetValue( string nodePath )
        {
            if ( ! string.IsNullOrWhiteSpace(nodePath))
            {
                // Get any prefixes that were defined with the mergefield
                var prefixedMergeFieldIds = GetPrefixedMergeFieldIds();

                var nodes = new List<string>();
                string workingPath = nodePath;

                // Check to see if the nodepath starts with one of the prefixedMergeFields.  If so
                // the node path should not split its items on the first pipe character
                foreach ( string fieldId in prefixedMergeFieldIds )
                {
                    if ( nodePath.StartsWith( fieldId ) )
                    {
                        nodes.Add( fieldId );
                        workingPath = nodePath.Substring( fieldId.Length );
                        break;
                    }
                }

                workingPath.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries ).ToList()
                    .ForEach( n => nodes.Add( n ) );

                if ( nodes.Count > 0 )
                {
                    ItemId = nodePath;
                    ItemName = nodes[nodes.Count -1];

                    if ( nodes.Count > 1 )
                    {
                        InitialItemParentIds = nodes.Take( nodes.Count - 1 ).ToList().AsDelimited( "," );
                    }
                }
            }
            else
            {
                ItemId = "0";
                ItemName = "Add Merge Field";
            }
        }

Usage Example

Esempio n. 1
0
 void MergeFields_SelectItem(object sender, EventArgs e)
 {
     EnsureChildControls();
     this.Text += _mfpMergeFields.SelectedMergeField;
     _mfpMergeFields.SetValue(string.Empty);
 }