Exemple #1
0
        private void InitializeRow(GridViewRow row, DataControlField[] fields, TableRowCollection newRows)
        {
            GridViewRowEventArgs e = new GridViewRowEventArgs(row);

            InitializeRow(row, fields);
            OnRowCreated(e);

            newRows.Add(row);

            row.DataBind();
            OnRowDataBound(e);
            row.DataItem = null;
        }
Exemple #2
0
        protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
        {
            int rows = base.CreateChildControls(dataSource, dataBinding);

            // no data rows created, create empty table if enabled
            if (rows == 0 && (ShowFooterWhenEmpty || ShowHeaderWhenEmpty))
            {
                // create the table
                Table table = CreateChildTable();

                Controls.Clear();
                Controls.Add(table);

                DataControlField[] fields;
                if (AutoGenerateColumns)
                {
                    var source = new PagedDataSource {
                        DataSource = dataSource
                    };

                    ICollection autoGeneratedColumns = CreateColumns(source, true);
                    fields = new DataControlField[autoGeneratedColumns.Count];
                    autoGeneratedColumns.CopyTo(fields, 0);
                }
                else
                {
                    fields = new DataControlField[Columns.Count];
                    Columns.CopyTo(fields, 0);
                }

                TableRowCollection newRows = table.Rows;
                if (ShowHeaderWhenEmpty)
                {
                    // create a new header row
                    _headerRow = CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal);
                    InitializeRow(_headerRow, fields, newRows);
                }

                // create the empty row
                GridViewRow             emptyRow = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
                TableCell               cell     = new TableCell();
                List <DataControlField> f        = fields.Where(dataControlField => dataControlField.Visible).ToList();
                cell.ColumnSpan = f.Count;
                //cell.Width = Unit.Percentage(100);

                // respect the precedence order if both EmptyDataTemplate
                // and EmptyDataText are both supplied ...
                if (EmptyDataTemplate != null)
                {
                    EmptyDataTemplate.InstantiateIn(cell);
                }
                else if (!string.IsNullOrEmpty(EmptyDataText))
                {
                    cell.Controls.Add(new LiteralControl(EmptyDataText));
                }

                emptyRow.Cells.Add(cell);
                GridViewRowEventArgs e = new GridViewRowEventArgs(emptyRow);
                OnRowCreated(e);

                newRows.Add(emptyRow);

                emptyRow.DataBind();
                OnRowDataBound(e);
                emptyRow.DataItem = null;

                if (ShowFooterWhenEmpty && ShowFooter)
                {
                    // create footer row
                    _footerRow = CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal);
                    InitializeRow(_footerRow, fields, newRows);
                    newRows.Remove(emptyRow);
                }
            }

            return(rows);
        }
Exemple #3
0
        /// <summary>
        /// Handles the RowDataBound event of the MainGrid control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewRowEventArgs"/> instance containing the event data.</param>
        void MainGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            McMetaViewPreference mvPref = GetMetaViewPreference();

            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                int index = i - this.CustomColumns.Count;
                if (this.ShowCheckboxes)
                {
                    index--;
                }
                if (this.ShowCheckboxes && i == 0)
                {
                    continue;
                }
                if (e.Row.RowType == DataControlRowType.DataRow)                 //if (e.Row.Cells[i].Controls[0] is Mediachase.Ibn.Web.UI.Modules.FieldControls.BaseType)
                {
                    //e.Row.Cells[i].Attributes.Add("unselectable", "on");
                    if (index <= this.VisibleMetaFields.Length)
                    {
                        ((BaseType)e.Row.Cells[i].Controls[0]).DataItem = (MetaObject)e.Row.DataItem;
                    }
                    if (index < this.VisibleMetaFields.Length && index >= 0)
                    {
                        ((BaseType)e.Row.Cells[i].Controls[0]).FieldName = this.VisibleMetaFields[index].Name;
                    }
                    if (e.Row.Cells[i].Controls[0] is CustomColumnBaseType)
                    {
                        ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ViewName = this.ViewName;
                        ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).Place    = this.PlaceName;
                        if (this.ShowCheckboxes)
                        {
                            index++;
                        }
                        //if (index + this.CustomColumns.Count < this.CustomColumns.Count)
                        if (this.ShowCheckboxes)
                        {
                            ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ColumnId = this.CustomColumns[i - 1].Id;
                        }
                        else
                        {
                            ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ColumnId = this.CustomColumns[i].Id;
                        }
                        //else if (index < this.CustomColumns.Count)
                        //    ((CustomColumnBaseType)e.Row.Cells[i].Controls[0]).ColumnId = this.CustomColumns[index].Id;
                    }
                    if (i + 1 != e.Row.Cells.Count)
                    {
                        e.Row.Cells[i].CssClass = this.GridInnerCssClass;
                    }
                }
            }

            GridViewRow row = e.Row;

            if (row.RowType == DataControlRowType.Header || row.RowType == DataControlRowType.DataRow)
            {
                internalBindRowWidth(ref row);
            }
            row.DataBind();
            if (row.RowType == DataControlRowType.DataRow)
            {
                //if (e.Row.DataItem != null && ((MetaObject)e.Row.DataItem).PrimaryKeyId.HasValue)
                //{
                //    if (this.ShowCheckboxes)
                //    {
                //        CheckBox cb = (CheckBox)row.Cells[0].Controls[0];
                //        cb.Attributes.Add(IbnGridView.primaryKeyIdAttr, ((MetaObject)e.Row.DataItem).PrimaryKeyId.Value.ToString());
                //    }

                //}
                if (e.Row.DataItem != null)
                {
                    e.Row.Attributes.Add(IbnGridView.primaryKeyIdAttr, String.Format("{0}", MetaViewGroupUtil.CreateUniqueKey(CurrentView, (MetaObject)e.Row.DataItem, this.PrimaryGroupType, this.SecondaryGroupType)));
                    if (this.ShowCheckboxes)
                    {
                        CheckBox cb = (CheckBox)row.Cells[0].Controls[0];
                        cb.Attributes.Add(IbnGridView.primaryKeyIdAttr, String.Format("{0}", MetaViewGroupUtil.CreateUniqueKey(CurrentView, (MetaObject)e.Row.DataItem, this.PrimaryGroupType, this.SecondaryGroupType)));
                    }
                }
            }
        }