• Kentico UniGrid中的GridView的DataBound


    kentico12\UIControls\Controls\UniGrid\UniGrid.cs

    protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
    
                AdvancedExportControl.UniGrid = this;
    
                PageSizeDropdown.SelectedIndexChanged += PageSizeDropdown_SelectedIndexChanged;
                GridView.Sorting += GridView_Sorting;
                GridView.DataBinding += GridView_DataBinding;
                GridView.DataBound += GridView_DataBound;
                GridView.RowCreated += GridView_RowCreated;
            }

    还有下面两个成员

      /// <summary>
            /// Selection external source name. Used for external DataBound of selection column.
            /// </summary>
            public const string SELECTION_EXTERNAL_DATABOUND = "UG_Selection_DataBound";
    
    
            /// <summary>
            /// Select all external source name. Used for header external DataBound of SelectAll check box.
            /// </summary>
            public const string SELECTALL_EXTERNAL_DATABOUND = "UG_SelectAll_DataBound";

    kentico12\UIControls\Controls\UniGrid\Fields\GridViewTemplate.cs   在这个GridViewTemplate中,BindCheckData

      /// <summary> 
            /// Handle DataBinding event called in the InstantiateIn method.
            /// </summary>        
            private void BindCheckData(object sender, EventArgs e)
            {
                CMSCheckBox checkBox = (CMSCheckBox)sender;
                GridViewRow container = (GridViewRow)checkBox.NamingContainer;
    
                var uniGrid = UniGridControl;
    
                if (container.RowType == DataControlRowType.DataRow)
                {
                    if (container.DataItem != null)
                    {
                        var dataItem = (DataRowView)container.DataItem;
    
                        var selColumn = checkBox.Attributes["selectioncolumn"];
    
                        string argument = String.IsNullOrEmpty(selColumn) ? dataItem[0].ToString() : dataItem[selColumn].ToString();
    
                        if (uniGrid != null)
                        {
                            // Add to the allowed selection
                            uniGrid.SelectionsID.Add(argument);
    
                            checkBox.Page.PreRenderComplete += ((senderObj, eventArgs) => { if (uniGrid.SelectedItems != null) { checkBox.Checked = uniGrid.SelectedItems.Contains(argument, StringComparer.InvariantCultureIgnoreCase); } });
    
                            string onclick = uniGrid.GetJSModule() + ".select(this);";
    
                            checkBox.InputAttributes["data-arg"] = argument;
                            checkBox.InputAttributes["data-argHash"] = ValidationHelper.GetHashString(argument, HashSettings);
    
                            if (!String.IsNullOrEmpty(uniGrid.SelectionJavascript))
                            {
                                onclick += $"{uniGrid.SelectionJavascript}('{ScriptHelper.GetString(argument, false)}', this.checked);";
                            }
    
                            checkBox.InputAttributes["onclick"] = onclick;
                            checkBox.InputAttributes["onchange"] = uniGrid.GetJSModule() + ".updateHeaderCheckbox();";
    
                            uniGrid.RaiseExternalDataBound(checkBox, UniGrid.SELECTION_EXTERNAL_DATABOUND, container.DataItem);
                        }
    
                        checkBox.Attributes.Remove("selectioncolumn");
                    }
                }
                else if (container.RowType == DataControlRowType.Header)
                {
                    if (uniGrid != null)
                    {
                        checkBox.Attributes["onclick"] = uniGrid.GetJSModule() + ".selectAll(this);";
                        checkBox.Checked = false;
    
                        uniGrid.RaiseExternalDataBound(checkBox, UniGrid.SELECTALL_EXTERNAL_DATABOUND, container.DataItem);
                    }
                }
            }

    kentico12\UIControls\Controls\UniGrid\UniGrid.cs

    /// <summary>
            /// Raises the external data bound event.
            /// </summary>
            /// <param name="sender">Sender object</param>
            /// <param name="sourceName">External source name</param>
            /// <param name="parameter">Source parameter</param>
            public object RaiseExternalDataBound(object sender, string sourceName, object parameter)
            {
                // Special handling for built-in grid transformations
                if ((sourceName != null) && (sourceName[0] == '#'))
                {
                    // Object transformation
                    if (sourceName.StartsWith(UniGridTransformations.TRANSFORM_PREFIX, StringComparison.OrdinalIgnoreCase))
                    {
                        int prefixLength = UniGridTransformations.TRANSFORM_PREFIX.Length;
    
                        int trIndex = sourceName.IndexOf(':', prefixLength);
                        if (trIndex <= 0)
                        {
                            // Search for the last part (column name)
                            trIndex = sourceName.LastIndexOf(".", StringComparison.Ordinal);
                        }
    
                        if (trIndex > 0)
                        {
                            int objectId;
    
                            string objectType = sourceName.Substring(prefixLength, trIndex - prefixLength).Trim();
                            string columnName = sourceName.Substring(trIndex + 1).Trim();
    
                            if (parameter is DataRowView)
                            {
                                // ##ALL##
                                int lIndex = objectType.IndexOf("=>", StringComparison.Ordinal);
                                if (lIndex <= 0)
                                {
                                    return null;
                                }
    
                                string idValue = objectType.Substring(lIndex + 2).Trim();
                                objectType = objectType.Substring(0, lIndex).Trim();
    
                                // Resolve macros in object type and ID value
                                CurrentResolver.SetAnonymousSourceData(parameter);
    
                                idValue = CurrentResolver.ResolveMacros(idValue);
                                objectType = CurrentResolver.ResolveMacros(objectType);
    
                                objectId = ValidationHelper.GetInteger(idValue, 0);
                            }
                            else
                            {
                                // Specific column (ID of the object)
                                objectId = ValidationHelper.GetInteger(parameter, 0);
                            }
    
                            if (objectId <= 0)
                            {
                                return null;
                            }
    
                            // Add the field transformation control that handles the translation
                            var tr = new ObjectTransformation(objectType, objectId);
                            tr.Transformation = columnName;
    
                            return tr;
                        }
                    }
    
                    // Try to find the transformation
                    if (UniGridTransformations.Global.ExecuteTransformation(sender, sourceName, ref parameter))
                    {
                        return parameter;
                    }
                }
    
                // If column was added using AddAdditionalColumn method and its external data bound callback was specified, fire it
                OnExternalDataBoundEventHandler additionalExternalDataBound;
                if (TryGetAdditionalExternalDataBoundCallback(sourceName, out additionalExternalDataBound))
                {
                    return additionalExternalDataBound(sender, sourceName, parameter);
                }
    
                return OnExternalDataBound?.Invoke(sender, sourceName, parameter);
            }

    应该是执行了后半部分

    // If column was added using AddAdditionalColumn method and its external data bound callback was specified, fire it
                OnExternalDataBoundEventHandler additionalExternalDataBound;
                if (TryGetAdditionalExternalDataBoundCallback(sourceName, out additionalExternalDataBound))
                {
                    return additionalExternalDataBound(sender, sourceName, parameter);
                }

                return OnExternalDataBound?.Invoke(sender, sourceName, parameter);

  • 相关阅读:
    如何在当前文件夹打开cmd(基于win10)
    Python命名空间和作用域
    Python定位模块_PYTHONPATH变量
    Python模块_import语句_from...import 函数名_from ... import *
    Python全局变量和局部变量
    Python变量作用域
    Python匿名函数_return语句
    Python函数参数
    Python按值传递参数和按引用传递参数
    Python函数调用
  • 原文地址:https://www.cnblogs.com/chucklu/p/16560873.html
Copyright © 2020-2023  润新知