Exemple #1
0
        public void InsertRow(int rowIndex)
        {
            IDataSource       ds     = GetDataSource();
            DataSourceView    view   = ds.GetView(this.DataMember);
            GridViewRow       row    = this.Rows[rowIndex];
            OrderedDictionary values = new OrderedDictionary();

            for (int i = 0; i < this.Columns.Count; ++i)
            {
                this.Columns[i].ExtractValuesFromCell(values, (DataControlFieldCell)row.Cells[i], DataControlRowState.Insert, false);
            }
            GridViewInsertingEventArgs insertingArgs = new GridViewInsertingEventArgs(values, rowIndex);

            OnRowInserting(insertingArgs);
            if (insertingArgs.Cancel)
            {
                return;
            }
            view.Insert(values, delegate(int affectedRecords, Exception ex)
            {
                GridViewInsertedEventArgs insertedArgs = new GridViewInsertedEventArgs(affectedRecords, ex, values);
                OnRowInserted(insertedArgs);
                if (!insertedArgs.KeepInInsertMode)
                {
                    this.InsertRowsCount = 0;
                }
                return(insertedArgs.ExceptionHandled);
            });
        }
Exemple #2
0
        /// <summary>
        /// Prepares the <see cref="RowInserting"/> event and calls insert on the DataSource.
        /// </summary>
        /// <param name="rowIndex"></param>
        /// <param name="causesValidation"></param>
        private void InsertRow(int rowIndex, bool causesValidation)
        {
            GridViewRow row = null;

            if ((!causesValidation || (this.Page == null)) || this.Page.IsValid)
            {
                DataSourceView dsv           = null;
                bool           useDataSource = base.IsBoundUsingDataSourceID;
                if (useDataSource)
                {
                    dsv = this.GetData();
                    if (dsv == null)
                    {
                        throw new HttpException("DataSource Returned Null View");
                    }
                }
                GridViewInsertEventArgs args = new GridViewInsertEventArgs(rowIndex);
                if (useDataSource)
                {
                    if ((row == null) && (this.InnerTable.Rows.Count > rowIndex))
                    {
                        row = this.InnerTable.Rows[rowIndex] as GridViewRow;
                    }
                    if (row != null)
                    {
                        this.ExtractRowValues(args.NewValues, row, true, true);
                    }
                }

                this.OnRowInserting(args);

                if (!args.Cancel && useDataSource)
                {
                    dsv.Insert(args.NewValues, new DataSourceViewOperationCallback(DataSourceViewInsertCallback));
                }
            }
        }