/// <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);
            }
        }
 /// <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;";
 }
 /// <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;
         }
     }
 }
        /// <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="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);
 }
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="rowIndex"></param>
 /// <param name="dataItemIndex"></param>
 /// <param name="rowType"></param>
 /// <param name="rowState"></param>
 public DataGridViewRow(int rowIndex, int dataItemIndex, DataGridViewRowType rowType, DataGridViewRowState rowState)
 {
     this.rowIndex = rowIndex;
     this.dataItemIndex = dataItemIndex;
     this.rowType = rowType;
     this.rowState = rowState;
 }
示例#7
0
 /// <summary>
 /// 创建行。
 /// </summary>
 /// <param name="rowIndex">要创建的行的索引。</param>
 /// <param name="dataSourceIndex">要绑定到行的数据源项的索引。</param>
 /// <param name="rowType">行类型。</param>
 /// <param name="rowState">行状态。</param>
 /// <returns></returns>
 protected virtual DataGridViewRow CreateRow(int rowIndex, int dataSourceIndex, DataGridViewRowType rowType, DataGridViewRowState rowState)
 {
     DataGridViewRow row = new DataGridViewRow(rowIndex, dataSourceIndex, rowType, rowState);
     if (rowType == DataGridViewRowType.DataRow)
     {
         row.Attributes.Add("onmouseout", string.Format("this.className='{0}';",
                    rowState == DataGridViewRowState.AlterNate ? this.AlternatingRowStyle.CssClass : this.RowStyle.CssClass));
         row.Attributes.Add("onmouseover", string.Format("this.className='{0}';", this.MouseoverCssClass));
     }
     return row;
 }
 /// <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);
     }
 }
示例#9
0
 DataGridViewRow CreateRow(int rowIndex, int dataSourceIndex, DataGridViewRowType rowType, DataGridViewRowState rowState, bool dataBind,
     object dataItem, DataControlFieldEx[] fields, TableRowCollection rows, PagedDataSourceEx pagedDataSource)
 {
     DataGridViewRow row = this.CreateRow(rowIndex, dataSourceIndex, rowType, rowState);
     DataGridViewRowEventArgs e = new DataGridViewRowEventArgs(row);
     if (rowType != DataGridViewRowType.Footer)
         this.InitializeRow(row, fields);
     else
         this.InitializePager(row, fields.Length, pagedDataSource);
     if (dataBind)
         row.DataItem = dataItem;
     this.OnRowCreated(e);
     rows.Add(row);
     if (dataBind)
     {
         row.DataBind();
         this.OnRowDataBound(e);
         row.DataItem = null;
     }
     return row;
 }
示例#10
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);
 }
示例#11
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)
 {
 }