Пример #1
0
        /// <summary>
        /// 将指定的 TableCell 对象初始化为指定的行状态。
        /// </summary>
        /// <param name="cell">要初始化的 TableCell。</param>
        /// <param name="cellType">DataControlCellType<see cref="DataControlCellType"/> 值之一。</param>
        /// <param name="rowState">DataControlRowState<see cref="DataControlRowState"/> 值之一。</param>
        /// <param name="rowIndex">从零开始的行索引。</param>
        public override void InitializeCell(DataControlFieldCellEx cell,
            DataControlCellType cellType,
            DataGridViewRowState rowState,
            int rowIndex)
        {
            base.InitializeCell(cell, cellType, rowState, rowIndex);
            DataGridView owner = this.Control as DataGridView;
            if (owner == null)
                return;
            else if (cellType == DataControlCellType.Header)
            {
                ClientScriptManager scriptManager = owner.Page.ClientScript;
                string scriptKey = string.Format("{0}_SelectAll", owner.ClientID);
                if (!scriptManager.IsClientScriptBlockRegistered(this.GetType(), scriptKey))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<script type=\"text/javascript\">\r\n");
                    sb.AppendFormat("function {0}_SelectAll()\r\n", owner.ClientID);
                    sb.Append("{\r\n");
                    sb.AppendFormat("\tvar c=document.all.{0}_cbSelectAll.checked;\r\n", owner.ClientID);
                    sb.AppendFormat("\tvar cb=document.all.{0}.getElementsByTagName(\"input\");\r\n", owner.ClientID);
                    sb.Append("\tif(cb && cb!=null)\r\n");
                    sb.Append("\t{\r\n");
                    sb.Append("\t\tfor(var i=0;i<cb.length;i++)\r\n");
                    sb.Append("\t\t{\r\n");
                    sb.AppendFormat("\t\t\tif(cb[i].type==\"checkbox\" && cb[i].id.indexOf(\"{0}\")>-1)\r\n", owner.ClientID);
                    sb.Append("\t\t\t{\r\n");
                    sb.Append("\t\t\tcb[i].checked=c;\r\n");
                    sb.Append("\t\t\t}\r\n");
                    sb.Append("\t\t}\r\n");
                    sb.Append("\t}\r\n");
                    sb.Append("}\r\n");
                    sb.Append("</script>\r\n");

                    scriptManager.RegisterClientScriptBlock(this.GetType(), scriptKey, sb.ToString());
                }
                HtmlInputCheckBox cb = new HtmlInputCheckBox();
                cb.Attributes["ID"] = string.Format("{0}_cbSelectAll", owner.ClientID);
                cb.Attributes["onclick"] = string.Format("javascript:{0}_SelectAll()", owner.ClientID);
                cell.Controls.Add(cb);
            }
        }
Пример #2
0
 /// <summary>
 /// 将文本或控件添加到单元格的控件集合中。
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="cellType"></param>
 /// <param name="rowState"></param>
 /// <param name="rowIndex"></param>
 public override void InitializeCell(DataControlFieldCellEx cell, DataControlCellType cellType, DataGridViewRowState rowState, int rowIndex)
 {
     base.InitializeCell(cell, cellType, rowState, rowIndex);
     ITemplate template = null;
     switch (cellType)
     {
         case DataControlCellType.Header:
             template = this.headerTemplate;
             break;
         case DataControlCellType.Footer:
             template = this.footerTemplate;
             break;
         case DataControlCellType.DataCell:
             template = this.itemTemplate;
             if (((rowState & DataGridViewRowState.AlterNate) != DataGridViewRowState.Normal) && (this.alternatingItemTemplate != null))
                 template = this.alternatingItemTemplate;
             break;
     }
     if (template != null)
     {
         cell.Text = string.Empty;
         template.InstantiateIn(cell);
     }
     else if (cellType == DataControlCellType.DataCell)
         cell.Text = "&nbsp;";
 }
Пример #3
0
 /// <summary>
 /// 从当前表单元格提取由一个或多个双向绑定语句 (DataBind) 指定的数据控件字段的值,并将这些值添加到指定的 IOrderedDictionary 集合。
 /// </summary>
 /// <param name="dictionary"></param>
 /// <param name="cell"></param>
 /// <param name="rowState"></param>
 /// <param name="includeReadOnly"></param>
 public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCellEx cell, DataGridViewRowState rowState, bool includeReadOnly)
 {
     DataBoundControlExHelper.ExtractValuesFromBindableControls(dictionary, cell);
     IBindableTemplate itemTemplate = this.ItemTemplate as IBindableTemplate;
     if (((rowState & DataGridViewRowState.AlterNate) != DataGridViewRowState.Normal) && (this.AlternatingItemTemplate != null))
         itemTemplate = this.AlternatingItemTemplate as IBindableTemplate;
     if (itemTemplate != null)
     {
         bool convertEmptyStringToNull = this.ConvertEmptyStringToNull;
         foreach (DictionaryEntry entry in itemTemplate.ExtractValues(cell.BindingContainer))
         {
             object obj = entry.Value;
             if (convertEmptyStringToNull && (obj is string) && (((string)obj).Length == 0))
                 dictionary[entry.Key] = null;
             else
                 dictionary[entry.Key] = obj;
         }
     }
 }
Пример #4
0
        /// <summary>
        /// 将指定的 TableCell 对象初始化为指定的行状态。
        /// </summary>
        /// <param name="cell">要初始化的 TableCell。</param>
        /// <param name="rowState">DataControlRowState<see cref="DataControlRowState"/> 值之一。</param>
        protected override void InitializeDataCell(DataControlFieldCellEx cell, DataGridViewRowState rowState)
        {
            HtmlInputCheckBox cb = new HtmlInputCheckBox();
            cb.ID = string.Format("{0}_cbSelect", ((DataGridView)this.Control).ClientID);

            Control dataBindingContainer = (Control)cb;
            dataBindingContainer.DataBinding += this.OnDataBindField;
            cell.Controls.Add(cb);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="cellType"></param>
 /// <param name="rowState"></param>
 /// <param name="rowIndex"></param>
 public override void InitializeCell(DataControlFieldCellEx cell, 
     DataControlCellType cellType,
     DataGridViewRowState rowState,
     int rowIndex)
 {
     base.InitializeCell(cell, cellType, rowState, rowIndex);
     DataGridView owner = this.Control as DataGridView;
     if (owner == null)
         return;
     else if (cellType == DataControlCellType.Header && this.PopupWin)
     {
         if (this.WinType == EnumWindowType.Modal)
             this.BuildModalWin(owner);
         else
             this.BuildNormalWin(owner);
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="rowState"></param>
 protected override void InitializeDataCell(DataControlFieldCellEx cell,
     DataGridViewRowState rowState)
 {
     HtmlAnchor anchor = new HtmlAnchor();
     Control dataBindingContainer = anchor as Control;
     if (dataBindingContainer != null)
         dataBindingContainer.DataBinding += this.OnDataBindField;
     cell.Controls.Add(anchor);
 }
Пример #7
0
        /// <summary>
        /// 初始化行。
        /// </summary>
        /// <param name="row"></param>
        /// <param name="fields"></param>
        protected virtual void InitializeRow(DataGridViewRow row, DataControlFieldEx[] fields)
        {
            DataGridViewRowType rowType = row.RowType;
            DataGridViewRowState rowState = row.RowState;
            int rowIndex = row.RowIndex;

            TableCellCollection cells = row.Cells;
            string rowHeaderColumn = this.RowHeaderColumn;
            bool useAccessibleHeader = false;
            if (rowType == DataGridViewRowType.Header)
                useAccessibleHeader = this.UseAccessibleHeader;

            for (int i = 0; i < fields.Length; i++)
            {
                DataControlFieldCellEx cell = null;
                DataControlCellType header = DataControlCellType.DataCell;
                if ((rowType == DataGridViewRowType.Header) && useAccessibleHeader)
                {
                    cell = new DataControlFieldHeaderCellEx(fields[i]);
                    ((DataControlFieldHeaderCellEx)cell).Scope = TableHeaderScope.Column;
                    ((DataControlFieldHeaderCellEx)cell).AbbreviatedText = fields[i].AccessibleHeaderText;
                }
                else
                {
                    BoundFieldEx field = fields[i] as BoundFieldEx;
                    if (!string.IsNullOrEmpty(rowHeaderColumn) && (field != null) && (field.DataField == rowHeaderColumn))
                    {
                        cell = new DataControlFieldHeaderCellEx(fields[i]);
                        ((DataControlFieldHeaderCellEx)cell).Scope = TableHeaderScope.Row;
                    }
                    else
                        cell = new DataControlFieldCellEx(fields[i]);
                }

                switch (rowType)
                {
                    case DataGridViewRowType.Header:
                        header = DataControlCellType.Header;
                        break;
                    case DataGridViewRowType.Footer:
                        header = DataControlCellType.Footer;
                        break;
                    default:
                        header = DataControlCellType.DataCell;
                        break;
                }

                fields[i].InitializeCell(cell,header, rowState, rowIndex);
                cells.Add(cell);
            }
        }
Пример #8
0
 /// <summary>
 /// 初始化为指定的行状态。
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="rowState"></param>
 protected virtual void InitializeDataCell(DataControlFieldCellEx cell, DataGridViewRowState rowState)
 {
     Control control = null;
     if (!string.IsNullOrEmpty(this.DataField))
         control = cell;
     if ((control != null) && base.Visible)
         control.DataBinding += new EventHandler(this.OnDataBindField);
 }
Пример #9
0
        /// <summary>
        /// 初始化为指定的行状态。
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="cellType"></param>
        /// <param name="rowState"></param>
        /// <param name="rowIndex"></param>
        public override void InitializeCell(DataControlFieldCellEx cell, DataControlCellType cellType, DataGridViewRowState rowState, int rowIndex)
        {
            string headerText = string.Empty;
            bool flag = false, flag2 = false;
            if ((cellType == DataControlCellType.Header) && this.SupportsHtmlEncode && this.HtmlEncode)
            {
                headerText = this.HeaderText;
                flag2 = true;
            }

            if (flag2 && !string.IsNullOrEmpty(headerText))
            {
                this.supressHeaderTextFieldChange = true;
                this.HeaderText = HttpUtility.HtmlEncode(headerText);
                flag = true;
            }
            base.InitializeCell(cell, cellType, rowState, rowIndex);
            if (flag)
            {
                this.HeaderText = headerText;
                this.supressHeaderTextFieldChange = false;
            }

            if (cellType == DataControlCellType.DataCell)
            {
                if (this.ShowRowSelectingEvent)
                {
                    IButtonControl control;
                    IPostBackContainer container = base.Control as IPostBackContainer;
                    if (container != null)
                    {
                        control = new DataControlLinkButton(container);
                    }
                    else
                        control = new LinkButton();
                    control.CommandName = "RowSelectingEvent";
                    control.CommandArgument = rowIndex.ToString(CultureInfo.InvariantCulture);
                    ((WebControl)control).DataBinding += new EventHandler(this.OnDataBindField);
                    cell.Controls.Add((WebControl)control);
                }
                else
                    this.InitializeDataCell(cell, rowState);
            }
        }
        /// <summary>
        /// 将文本或控件添加到单元格的控件集合中。
        /// </summary>
        /// <param name="cell"></param>
        /// <param name="cellType"></param>
        /// <param name="rowState"></param>
        /// <param name="rowIndex"></param>
        public virtual void InitializeCell(DataControlFieldCellEx cell, DataControlCellType cellType, DataGridViewRowState rowState, int rowIndex)
        {
            WebControl control = null;
            string sortExpression = string.Empty, headerText = string.Empty;
            ImageButton button = null;

            switch (cellType)
            {
                case DataControlCellType.Header:
                    {
                        control = null;
                        sortExpression = this.SortExpression;
                        bool bSort = this.sortingEnabled && !string.IsNullOrEmpty(sortExpression);
                        string headerImageUrl = this.HeaderImageUrl;
                        headerText = this.HeaderText;
                        if (string.IsNullOrEmpty(headerImageUrl))
                        {
                            if (bSort)
                            {
                                LinkButton link = null;
                                IPostBackContainer container = this.control as IPostBackContainer;
                                if (container != null)
                                {
                                    link = new DataControlLinkButton(container);
                                    ((DataControlLinkButton)link).EnableCallback(null);
                                }
                                else
                                    link = new LinkButton();
                                link.Text = headerText;
                                link.CommandName = "Sort";
                                link.CommandArgument = sortExpression;

                                if (!(link is DataControlLinkButton))
                                    link.CausesValidation = false;
                                control = link;
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(headerText))
                                    headerText = "&nbsp;";
                                cell.Text = headerText;
                            }
                            goto Label_015C;
                        }
                        if (!bSort && !string.IsNullOrEmpty(headerImageUrl))
                        {
                            Image image = new Image();
                            image.ImageUrl = headerImageUrl;
                            control = image;
                            image.AlternateText = headerText;
                            goto Label_015C;
                        }

                        IPostBackContainer contrainer = this.control as IPostBackContainer;
                        if (contrainer == null)
                        {
                            button = new ImageButton();
                            break;
                        }
                        button = new DataControlImageButton(contrainer);
                        ((DataControlImageButton)button).EnableCallback(null);
                    }
                    break;
                case DataControlCellType.Footer:
                    {
                        string footerText = this.FooterText;
                        if (string.IsNullOrEmpty(footerText))
                            footerText = "&nbsp;";
                        cell.Text = footerText;
                    }
                    return;
                default:
                    return;
            }
            button.ImageUrl = this.HeaderImageUrl;
            button.CommandName = "Sort";
            button.CommandArgument = sortExpression;
            if (!(button is DataControlImageButton))
                button.CausesValidation = false;
            button.AlternateText = headerText;
            control = button;

            Label_015C:
            if (control != null)
                cell.Controls.Add(control);
        }
 /// <summary>
 /// 从当前表格单元格中提取数据控件字段的值,并将该值添加到指定的 <see cref="IDictionary"/> 集合中。
 /// </summary>
 /// <param name="dictionary"></param>
 /// <param name="cell"></param>
 /// <param name="rowState"></param>
 /// <param name="includeReadOnly">如果要指示只读字段的值包括在 dictionary 集合中,则为 true;否则为 false。</param>
 public virtual void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCellEx cell, DataGridViewRowState rowState, bool includeReadOnly)
 {
 }