コード例 #1
0
ファイル: DataKeyArrayTest.cs プロジェクト: nobled/mono
		public void DataKeyArray_DefaultProperty()
		{
			DataKeyArray keyarray = new DataKeyArray (new ArrayList ());
			Assert.AreEqual (0, keyarray.Count, "Count");
			Assert.AreEqual (false, keyarray.IsReadOnly, "IsReadOnly");
			Assert.AreEqual (false, keyarray.IsSynchronized, "IsSynchronized");
			//Assert.AreEqual (keyarray, keyarray.SyncRoot, "SyncRoot");
		}
コード例 #2
0
ファイル: DataKeyArrayTest.cs プロジェクト: nobled/mono
		public void DataKeyArray_Item ()
		{
			OrderedDictionary dictionary = new OrderedDictionary();
			dictionary.Add("key","value");
			ArrayList list = new ArrayList ();
			DataKey key = new DataKey (dictionary);
			list.Add (key);
			DataKeyArray keyarray = new DataKeyArray (list);
			Assert.AreEqual(1,keyarray.Count,"CreateItems");
			Assert.AreEqual (key, keyarray[0], "CreateKeyData");
			Assert.AreEqual ("value",((DataKey)keyarray[0]).Value,"KeyArrayValue");
			dictionary.Add ("key1", "value1");
			key = new DataKey (dictionary);
			list.Add (key);
			keyarray = new DataKeyArray (list);
			Assert.AreEqual (2, keyarray.Count, "CreateItemsMulty");
		}
コード例 #3
0
		void LoadDataKeyArrayState (object [] state)
		{
			for (int i = 0; i < state.Length; i++) {
				DataKey dataKey = new DataKey (new OrderedDictionary (DataKeyNames.Length), DataKeyNames);
				((IStateManager) dataKey).LoadViewState (state [i]);
				DataKeyArrayList.Add (dataKey);
			}
			keys = new DataKeyArray (DataKeyArrayList);
		}
コード例 #4
0
		public sealed override void DataBind ()
		{
			DataKeyArrayList.Clear ();
			cachedKeyProperties = null;
			base.DataBind ();

			keys = new DataKeyArray (DataKeyArrayList);
		}
コード例 #5
0
ファイル: DataKeyArrayTest.cs プロジェクト: nobled/mono
		public void DataKeyArray_CopyTo ()
		{
			OrderedDictionary dictionary = new OrderedDictionary ();
			dictionary.Add ("key", "value");
			ArrayList list = new ArrayList ();
			DataKey key = new DataKey (dictionary);
			list.Add (key);
			DataKeyArray keyarray = new DataKeyArray (list);
			DataKey[] keys = new DataKey[list.Count];
			keyarray.CopyTo(keys,0);
			Assert.AreEqual ("value", keys[0].Value, "CopyToValue");
		}
コード例 #6
0
ファイル: DataKeyArrayTest.cs プロジェクト: nobled/mono
		public void DataKeyArray_DefaultPropertyNotWorking()
		{
			DataKeyArray keyarray = new DataKeyArray (new ArrayList ());
			Assert.AreEqual (keyarray, keyarray.SyncRoot, "SyncRoot");
		}
コード例 #7
0
ファイル: DataKeyArrayTest.cs プロジェクト: nobled/mono
		public void DataKeyArray_GetEnumerator ()
		{
			OrderedDictionary dictionary = new OrderedDictionary ();
			dictionary.Add ("key", "value");
			ArrayList list = new ArrayList ();
			DataKey key = new DataKey (dictionary);
			list.Add (key);
			DataKeyArray keyarray = new DataKeyArray (list);
			IEnumerator inumerator = keyarray.GetEnumerator ();
			Assert.IsNotNull (inumerator, "GetEnumerator");
		}
コード例 #8
0
ファイル: GridSupport.cs プロジェクト: Confirmit/Portal
 public GridDeleteEventArgs(DataKeyArray keys)
 {
     m_DataKeys = keys;
 }
コード例 #9
0
        /// <summary>
        /// Performs the work of creating the control hierarchy based on a data source.
        /// When dataBinding is true, the specified data source contains real
        /// data, and the data is supposed to be pushed into the UI.
        /// When dataBinding is false, the specified data source is a dummy data
        /// source, that allows enumerating the right number of items, but the items
        /// themselves are null and do not contain data. In this case, the recreated
        /// control hierarchy reinitializes its state from view state.
        /// It enables a DataBoundControl to encapsulate the logic of creating its
        /// control hierarchy in both modes into a single code path.
        /// </summary>
        /// <param name="dataSource">
        /// The data source to be used to enumerate items.
        /// </param>
        /// <param name="dataBinding">
        /// Whether the method has been called from DataBind or not.
        /// </param>
        /// <returns>
        /// The number of items created based on the data source. Put another way, its
        /// the number of items enumerated from the data source.
        /// </returns>
        protected virtual int CreateChildControls(IEnumerable dataSource, bool dataBinding) {
            ListViewPagedDataSource pagedDataSource = null;

            // Create the LayoutTemplate so the pager control in it can set page properties.
            // We'll only create the layout template once.

            EnsureLayoutTemplate();
            RemoveItems();

            // if we should render the insert item, make a dummy empty datasource and go through
            // the regular code path.
            if (dataSource == null && InsertItemPosition != InsertItemPosition.None) {
                dataSource = new object[0];
            }

            bool usePaging = (_startRowIndex > 0 || _maximumRows > 0);

            if (dataBinding) {
                DataSourceView view = GetData();
                DataSourceSelectArguments arguments = SelectArguments;
                if (view == null) {
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.ListView_NullView, ID));
                }

                bool useServerPaging = view.CanPage && usePaging;

                if (!view.CanPage && useServerPaging) {
                    if (dataSource != null && !(dataSource is ICollection)) {
                        arguments.StartRowIndex = _startRowIndex;
                        arguments.MaximumRows = _maximumRows;
                        // This should throw an exception saying the data source can't page.
                        // We do this because the data source can provide a better error message than we can.
                        view.Select(arguments, SelectCallback);
                    }
                }

                if (useServerPaging) {
                    int totalRowCount;
                    if (view.CanRetrieveTotalRowCount) {
                        totalRowCount = arguments.TotalRowCount;
                    }
                    else {
                        ICollection dataSourceCollection = dataSource as ICollection;
                        if (dataSourceCollection == null) {
                            throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.ListView_NeedICollectionOrTotalRowCount, GetType().Name));
                        }
                        totalRowCount = checked(_startRowIndex + dataSourceCollection.Count);
                    }
                    pagedDataSource = CreateServerPagedDataSource(totalRowCount);

                }
                else {
                    pagedDataSource = CreatePagedDataSource();
                }
            }
            else {
                pagedDataSource = CreatePagedDataSource();
            }

            ArrayList keyArray = DataKeysArrayList;
            ArrayList suffixArray = ClientIDRowSuffixArrayList;
            _dataKeyArray = null;
            _clientIDRowSuffixArray = null;

            ICollection collection = dataSource as ICollection;

            if (dataBinding) {
                keyArray.Clear();
                suffixArray.Clear();
                if ((dataSource != null) && (collection == null) && !pagedDataSource.IsServerPagingEnabled && usePaging) {
                    // If we got to here, it's because the data source view said it could page, but then returned
                    // something that wasn't an ICollection.  Probably a data source control author error.
                    throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.ListView_Missing_VirtualItemCount, ID));
                }
            }
            else {
                if (collection == null) {
                    throw new InvalidOperationException(AtlasWeb.ListView_DataSourceMustBeCollectionWhenNotDataBinding);
                }
            }

            if (dataSource != null) {
                pagedDataSource.DataSource = dataSource;
                if (dataBinding && usePaging) {
                    keyArray.Capacity = pagedDataSource.DataSourceCount;
                    suffixArray.Capacity = pagedDataSource.DataSourceCount;
                }

                if (_groupTemplate != null) {
                    _itemList = CreateItemsInGroups(pagedDataSource, dataBinding, InsertItemPosition, keyArray);
                    if (dataBinding && ClientIDRowSuffixInternal != null && ClientIDRowSuffixInternal.Length != 0) {
                        CreateSuffixArrayList(pagedDataSource, suffixArray);
                    }
                }
                else {
                    if (GroupItemCount != 1) {
                        throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, AtlasWeb.ListView_GroupItemCountNoGroupTemplate, ID, GroupPlaceholderID));
                    }

                    _itemList = CreateItemsWithoutGroups(pagedDataSource, dataBinding, InsertItemPosition, keyArray);
                    if(dataBinding && ClientIDRowSuffixInternal != null && ClientIDRowSuffixInternal.Length != 0) {
                        CreateSuffixArrayList(pagedDataSource, suffixArray);
                    }
                }

                _totalRowCount = usePaging ? pagedDataSource.DataSourceCount : _itemList.Count;
                OnTotalRowCountAvailable(new PageEventArgs(_startRowIndex, _maximumRows, _totalRowCount));

                if (_itemList.Count == 0) {
                    if (InsertItemPosition == InsertItemPosition.None) {
                        // remove the layout template
                        Controls.Clear();
                        CreateEmptyDataItem();
                    }
                }
            }
            else {
                // remove the layout template
                Controls.Clear();
                CreateEmptyDataItem();
            }

            return _totalRowCount;
        }
コード例 #10
0
        /// <summary>
        /// Creates the labels.
        /// </summary>
        /// <param name="dataKeyArray">The data key array.</param>
        /// <returns></returns>
        private void ProcessLabels( DataKeyArray checkinArray )
        {
            // Make sure we can save the attendance and get an attendance code
            if ( RunSaveAttendance )
            {
                var attendanceErrors = new List<string>();
                if ( ProcessActivity( "Save Attendance", out attendanceErrors ) )
                {
                    SaveState();
                }
                else
                {
                    string errorMsg = "<ul><li>" + attendanceErrors.AsDelimited( "</li><li>" ) + "</li></ul>";
                    maAlert.Show( errorMsg, Rock.Web.UI.Controls.ModalAlertType.Warning );
                    return;
                }

                RunSaveAttendance = false;
            }

            var printQueue = new Dictionary<string, StringBuilder>();
            bool printIndividually = GetAttributeValue( "PrintIndividualLabels" ).AsBoolean();
            var designatedLabelGuid = GetAttributeValue( "DesignatedSingleLabel" ).AsGuidOrNull();

            foreach ( var selectedFamily in CurrentCheckInState.CheckIn.Families.Where( p => p.Selected ) )
            {
                List<CheckInLabel> labels = new List<CheckInLabel>();
                List<CheckInPerson> selectedPeople = selectedFamily.People.Where( p => p.Selected ).ToList();
                List<CheckInGroupType> selectedGroupTypes = selectedPeople.SelectMany( gt => gt.GroupTypes )
                    .Where( gt => gt.Selected ).ToList();
                List<CheckInGroup> availableGroups = null;
                List<CheckInLocation> availableLocations = null;
                List<CheckInSchedule> availableSchedules = null;
                List<CheckInSchedule> personSchedules = null;

                foreach ( DataKey dataKey in checkinArray )
                {
                    var personId = Convert.ToInt32( dataKey["PersonId"] );
                    var groupId = Convert.ToInt32( dataKey["GroupId"] );
                    var locationId = Convert.ToInt32( dataKey["LocationId"] );
                    var scheduleId = Convert.ToInt32( dataKey["ScheduleId"] );

                    int groupTypeId = selectedGroupTypes.Where( gt => gt.Groups.Any( g => g.Group.Id == groupId ) )
                        .Select( gt => gt.GroupType.Id ).FirstOrDefault();
                    availableGroups = selectedGroupTypes.SelectMany( gt => gt.Groups ).ToList();
                    availableLocations = availableGroups.SelectMany( l => l.Locations ).ToList();
                    availableSchedules = availableLocations.SelectMany( s => s.Schedules ).ToList();
                    personSchedules = selectedPeople.SelectMany( p => p.PossibleSchedules ).ToList();

                    // Make sure only the current item is selected in the merge object
                    if ( printIndividually || checkinArray.Count == 1 )
                    {
                        // Note: This depends on PreSelected being set properly to undo changes later
                        selectedPeople.ForEach( p => p.Selected = ( p.Person.Id == personId ) );
                        selectedGroupTypes.ForEach( gt => gt.Selected = ( gt.GroupType.Id == groupTypeId ) );
                        availableGroups.ForEach( g => g.Selected = ( g.Group.Id == groupId ) );
                        availableLocations.ForEach( l => l.Selected = ( l.Location.Id == locationId ) );
                        availableSchedules.ForEach( s => s.Selected = ( s.Schedule.Id == scheduleId ) );
                        personSchedules.ForEach( s => s.Selected = ( s.Schedule.Id == scheduleId ) );
                    }

                    // Create labels for however many items are currently selected
                    // #TODO: Rewrite CreateLabels so it would accept a list of ID's
                    var labelErrors = new List<string>();
                    if ( ProcessActivity( "Create Labels", out labelErrors ) )
                    {
                        SaveState();
                    }

                    // mark the person as being checked in
                    var selectedSchedules = availableLocations.Where( l => l.Selected )
                        .SelectMany( s => s.Schedules ).Where( s => s.Selected ).ToList();
                    foreach ( var selectedSchedule in selectedSchedules )
                    {
                        var serviceStart = (DateTime)selectedSchedule.StartTime;
                        selectedSchedule.LastCheckIn = serviceStart.AddMinutes( (double)selectedSchedule.Schedule.CheckInEndOffsetMinutes );
                    }

                    // Add valid grouptype labels, excluding the one-time label (if set)
                    if ( printIndividually )
                    {
                        var selectedPerson = selectedPeople.FirstOrDefault( p => p.Person.Id == personId );
                        if ( selectedPerson != null )
                        {
                            labels.AddRange( selectedPerson.GroupTypes.Where( gt => gt.Labels != null )
                                .SelectMany( gt => gt.Labels )
                                .Where( l => ( !RemoveFromQueue || l.FileGuid != designatedLabelGuid ) )
                            );
                        }

                        RemoveFromQueue = RemoveFromQueue || labels.Any( l => l.FileGuid == designatedLabelGuid );
                    }
                    else
                    {
                        labels.AddRange( selectedGroupTypes.Where( gt => gt.Labels != null )
                            .SelectMany( gt => gt.Labels )
                            .Where( l => ( !RemoveFromQueue || l.FileGuid != designatedLabelGuid ) )
                        );

                        // don't continue processing if printing all info on one label
                        break;
                    }
                }

                // Print client labels
                if ( labels.Any( l => l.PrintFrom == PrintFrom.Client ) )
                {
                    var clientLabels = labels.Where( l => l.PrintFrom == PrintFrom.Client ).ToList();
                    var urlRoot = string.Format( "{0}://{1}", Request.Url.Scheme, Request.Url.Authority );
                    clientLabels.ForEach( l => l.LabelFile = urlRoot + l.LabelFile );
                    AddLabelScript( clientLabels.ToJson() );
                    pnlContent.Update();
                }

                // Print server labels
                if ( labels.Any( l => l.PrintFrom == PrintFrom.Server ) )
                {
                    string delayCut = @"^XB";
                    string endingTag = @"^XZ";
                    var printerIp = string.Empty;
                    var labelContent = new StringBuilder();

                    // make sure labels have a valid ip
                    var lastLabel = labels.Last();
                    foreach ( var label in labels.Where( l => l.PrintFrom == PrintFrom.Server && !string.IsNullOrEmpty( l.PrinterAddress ) ) )
                    {
                        var labelCache = KioskLabel.Read( label.FileGuid );
                        if ( labelCache != null )
                        {
                            if ( printerIp != label.PrinterAddress )
                            {
                                printQueue.AddOrReplace( label.PrinterAddress, labelContent );
                                printerIp = label.PrinterAddress;
                                labelContent = new StringBuilder();
                            }

                            var printContent = labelCache.FileContent;
                            foreach ( var mergeField in label.MergeFields )
                            {
                                if ( !string.IsNullOrWhiteSpace( mergeField.Value ) )
                                {
                                    printContent = Regex.Replace( printContent, string.Format( @"(?<=\^FD){0}(?=\^FS)", mergeField.Key ), ZebraFormatString( mergeField.Value ) );
                                }
                                else
                                {
                                    printContent = Regex.Replace( printContent, string.Format( @"\^FO.*\^FS\s*(?=\^FT.*\^FD{0}\^FS)", mergeField.Key ), string.Empty );
                                    printContent = Regex.Replace( printContent, string.Format( @"\^FD{0}\^FS", mergeField.Key ), "^FD^FS" );
                                }
                            }

                            // send a Delay Cut command at the end to prevent cutting intermediary labels
                            if ( label != lastLabel )
                            {
                                printContent = Regex.Replace( printContent.Trim(), @"\" + endingTag + @"$", delayCut + endingTag );
                            }

                            labelContent.Append( printContent );
                        }
                    }

                    printQueue.AddOrReplace( printerIp, labelContent );

                    if ( printQueue.Any() )
                    {
                        PrintLabels( printQueue );
                        printQueue.Clear();
                    }
                    else
                    {   // give the user feedback when no server labels are configured
                        phPrinterStatus.Controls.Add( new LiteralControl( "No labels were created.  Please verify that the grouptype is configured with labels and cache is reset." ) );
                    }
                }

                if ( printIndividually || checkinArray.Count == 1 )
                {
                    // reset selections to what they were before queue
                    selectedPeople.ForEach( p => p.Selected = p.PreSelected );
                    personSchedules.ForEach( s => s.Selected = s.PreSelected );
                    selectedGroupTypes.ForEach( gt => gt.Selected = gt.PreSelected );
                    availableGroups.ForEach( g => g.Selected = g.PreSelected );
                    availableLocations.ForEach( l => l.Selected = l.PreSelected );
                    availableSchedules.ForEach( s => s.Selected = s.PreSelected );
                }
            }

            // refresh the currently checked in flag
            BindGrid();
        }
コード例 #11
0
        /// <internalonly/>
        /// <devdoc>
        ///    <para>Creates the control hierarchy that is used to render the Smart.
        ///       This is called whenever a control hierarchy is needed and the
        ///       ChildControlsCreated property is false.
        ///       The implementation assumes that all the children in the controls
        ///       collection have already been cleared.</para>
        /// </devdoc>
        protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding) {
            PagedDataSource pagedDataSource = null;

            if (dataBinding) {
                bool allowPaging = AllowPaging;
                DataSourceView view = GetData();
                DataSourceSelectArguments arguments = SelectArguments;
                if (view == null) {
                    throw new HttpException(SR.GetString(SR.DataBoundControl_NullView, ID));
                }

                bool useServerPaging = allowPaging && view.CanPage;

                if (allowPaging && !view.CanPage) {
                    if (dataSource != null && !(dataSource is ICollection)) {
                        arguments.StartRowIndex = checked(PageSize * PageIndex);
                        arguments.MaximumRows = PageSize;
                        // This should throw an exception saying the data source can't page.
                        // We do this because the data source can provide a better error message than we can.
                        view.Select(arguments, SelectCallback);
                    }
                }

                if (useServerPaging) {
                    if (view.CanRetrieveTotalRowCount) {
                        pagedDataSource = CreateServerPagedDataSource(arguments.TotalRowCount);
                    }
                    else {
                        ICollection dataSourceCollection = dataSource as ICollection;
                        if (dataSourceCollection == null) {
                            throw new HttpException(SR.GetString(SR.DataBoundControl_NeedICollectionOrTotalRowCount, GetType().Name));
                        }
                        int priorPagesRecordCount = checked(PageIndex * PageSize);
                        pagedDataSource = CreateServerPagedDataSource(checked(priorPagesRecordCount + dataSourceCollection.Count));
                    }
                }
                else {
                    pagedDataSource = CreatePagedDataSource();
                }
            }
            else {
                pagedDataSource = CreatePagedDataSource();
            }

            IEnumerator pagedDataSourceEnumerator = null;
            int count = 0;
            ArrayList keyArray = DataKeysArrayList;
            ArrayList suffixArray = ClientIDRowSuffixArrayList;
            ICollection fields = null;
            int itemCount = -1; // number of items in the collection.  We need to know to decide if we need a null row.
            int rowsArrayCapacity = 0;
            ICollection collection = dataSource as ICollection;

            if (dataBinding) {
                keyArray.Clear();
                suffixArray.Clear();
                if (dataSource != null) {
                    // If we got to here, it's because the data source view said it could page, but then returned
                    // something that wasn't an ICollection.  Probably a data source control author error.
                    if ((collection == null) && (pagedDataSource.IsPagingEnabled && !pagedDataSource.IsServerPagingEnabled)) {
                        throw new HttpException(SR.GetString(SR.GridView_Missing_VirtualItemCount, ID));
                    }
                }
            }
            else {
                if (collection == null) {
                    throw new HttpException(SR.GetString(SR.DataControls_DataSourceMustBeCollectionWhenNotDataBinding));
                }
            }

            _pageCount = 0;
            if (dataSource != null) {
                pagedDataSource.DataSource = dataSource;
                if (pagedDataSource.IsPagingEnabled && dataBinding) {
                    // Fix up the page index if we have gone past the page count
                    int pagedDataSourcePageCount = pagedDataSource.PageCount;
                    Debug.Assert(pagedDataSource.CurrentPageIndex >= 0);
                    if (pagedDataSource.CurrentPageIndex >= pagedDataSourcePageCount) {
                        int lastPageIndex = pagedDataSourcePageCount - 1;
                        pagedDataSource.CurrentPageIndex = _pageIndex = lastPageIndex;
                    }
                }
                fields = CreateColumns(dataBinding ? pagedDataSource : null, dataBinding);

                if (collection != null) {
                    itemCount = collection.Count;
                    int pageSize = pagedDataSource.IsPagingEnabled ? pagedDataSource.PageSize : collection.Count;
                    rowsArrayCapacity = pageSize;
                    if (dataBinding) {
                        keyArray.Capacity = pageSize;
                        suffixArray.Capacity = pageSize;
                    }
                    // PagedDataSource has strange nehavior here.  If DataSourceCount is 0 but paging is enabled,
                    // it returns a PageCount of 1, which is inconsistent with DetailsView and FormView.
                    // We don't want to change PagedDataSource for back compat reasons.
                    if (pagedDataSource.DataSourceCount == 0) {
                        _pageCount = 0;
                    }
                    else {
                        _pageCount = pagedDataSource.PageCount;
                    }
                }
            }
            _rowsArray = new ArrayList(rowsArrayCapacity);
            _rowsCollection = null;
            _dataKeyArray = null;
            _clientIDRowSuffixArray = null;

            Table table = CreateChildTable();
            Controls.Add(table);

            TableRowCollection rows = table.Rows;

            // 
            if (dataSource == null) {
                if (EmptyDataTemplate != null || EmptyDataText.Length > 0) {
                    CreateRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, dataBinding, null, new DataControlField[0], rows, null);
                }
                else {
                    Controls.Clear();
                }
                return 0;
            }

            int fieldCount = 0;
            if (fields != null)
                fieldCount = fields.Count;

            DataControlField[] displayFields = new DataControlField[fieldCount];
            if (fieldCount > 0) {
                fields.CopyTo(displayFields, 0);

                bool requiresDataBinding = false;

                for (int c = 0; c < displayFields.Length; c++) {
                    if (displayFields[c].Initialize(AllowSorting, this)) {
                        requiresDataBinding = true;
                    }

                    if (DetermineRenderClientScript()) {
                        displayFields[c].ValidateSupportsCallback();
                    }
                }

                if (requiresDataBinding) {
                    RequiresDataBinding = true;
                }
            }

            GridViewRow row;
            DataControlRowType rowType;
            DataControlRowState rowState;
            int index = 0;
            int dataSourceIndex = 0;

            string[] dataKeyNames = DataKeyNamesInternal;
            bool storeKeys = (dataBinding && (dataKeyNames.Length != 0));
            bool storeSuffix = (dataBinding && ClientIDRowSuffixInternal.Length != 0);
            bool createPager = pagedDataSource.IsPagingEnabled;
            int editIndex = EditIndex;

            if (itemCount == -1) {
                if (_storedDataValid) {
                    if (_firstDataRow != null) {
                        itemCount = 1;
                    }
                    else {
                        itemCount = 0;
                    }
                }
                else {
                    // make sure there's at least one item in the source.
                    IEnumerator e = dataSource.GetEnumerator();

                    if (e.MoveNext()) {
                        object sampleItem = e.Current;
                        StoreEnumerator(e, sampleItem);
                        itemCount = 1;
                    }
                    else {
                        itemCount = 0;
                    }
                }
            }
            if (itemCount == 0) {
                bool controlsCreated = false;

                if (ShowHeader && ShowHeaderWhenEmpty && displayFields.Length > 0) {
                    _headerRow = CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal, dataBinding, null, displayFields, rows, null);
                    controlsCreated = true;
                }
                if (EmptyDataTemplate != null || EmptyDataText.Length > 0) {
                    CreateRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, dataBinding, null, displayFields, rows, null);
                    controlsCreated = true;
                }

                if (!controlsCreated) {
                    Controls.Clear();
                }
                _storedDataValid = false;
                _firstDataRow = null;
                return 0;
            }

            if (fieldCount > 0) {
                if (pagedDataSource.IsPagingEnabled)
                    dataSourceIndex = pagedDataSource.FirstIndexInPage;

                if (createPager && PagerSettings.Visible && _pagerSettings.IsPagerOnTop) {
                    _topPagerRow = CreateRow(-1, -1, DataControlRowType.Pager, DataControlRowState.Normal, dataBinding, null, displayFields, rows, pagedDataSource);
                }

                _headerRow = CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal, dataBinding, null, displayFields, rows, null);
                if (!ShowHeader) {
                    _headerRow.Visible = false;
                }

                if (storeKeys) {
                    // Reset the selected index if we have a persisted datakey so we
                    // can figure out what index to select based on the key
                    ResetPersistedSelectedIndex();
                }

                if (_storedDataValid) {
                    pagedDataSourceEnumerator = _storedData;
                    if (_firstDataRow != null) {
                        if (storeKeys) {
                            OrderedDictionary keyTable = new OrderedDictionary(dataKeyNames.Length);
                            foreach (string keyName in dataKeyNames) {
                                object keyValue = DataBinder.GetPropertyValue(_firstDataRow, keyName);
                                keyTable.Add(keyName, keyValue);
                            }
                            if (keyArray.Count == index) {
                                keyArray.Add(new DataKey(keyTable, dataKeyNames));
                            }
                            else {
                                keyArray[index] = new DataKey(keyTable, dataKeyNames);
                            }
                        }

                        if (storeSuffix) {
                            OrderedDictionary suffixTable = new OrderedDictionary(ClientIDRowSuffixInternal.Length);
                            foreach (string suffixName in ClientIDRowSuffixInternal) {
                                object suffixValue = DataBinder.GetPropertyValue(_firstDataRow, suffixName);
                                suffixTable.Add(suffixName, suffixValue);
                            }
                            if (suffixArray.Count == index) {
                                suffixArray.Add(new DataKey(suffixTable, ClientIDRowSuffixInternal));
                            }
                            else {
                                suffixArray[index] = new DataKey(suffixTable, ClientIDRowSuffixInternal);
                            }
                        }

                        if (storeKeys && EnablePersistedSelection) {
                            if (index < keyArray.Count) {
                                SetPersistedDataKey(index, (DataKey)keyArray[index]);
                            }
                        }

                        rowType = DataControlRowType.DataRow;
                        rowState = DataControlRowState.Normal;
                        if (index == editIndex)
                            rowState |= DataControlRowState.Edit;
                        if (index == _selectedIndex)
                            rowState |= DataControlRowState.Selected;

                        row = CreateRow(0, dataSourceIndex, rowType, rowState, dataBinding, _firstDataRow, displayFields, rows, null);
                        _rowsArray.Add(row);

                        count++;
                        index++;
                        dataSourceIndex++;

                        _storedDataValid = false;
                        _firstDataRow = null;
                    }
                }
                else {
                    pagedDataSourceEnumerator = pagedDataSource.GetEnumerator();
                }

                rowType = DataControlRowType.DataRow;
                while (pagedDataSourceEnumerator.MoveNext()) {
                    object dataRow = pagedDataSourceEnumerator.Current;

                    if (storeKeys) {
                        OrderedDictionary keyTable = new OrderedDictionary(dataKeyNames.Length);
                        foreach (string keyName in dataKeyNames) {
                            object keyValue = DataBinder.GetPropertyValue(dataRow, keyName);
                            keyTable.Add(keyName, keyValue);
                        }
                        if (keyArray.Count == index) {
                            keyArray.Add(new DataKey(keyTable, dataKeyNames));
                        }
                        else {
                            keyArray[index] = new DataKey(keyTable, dataKeyNames);
                        }
                    }

                    if (storeSuffix) {
                        OrderedDictionary suffixTable = new OrderedDictionary(ClientIDRowSuffixInternal.Length);
                        foreach (string suffixName in ClientIDRowSuffixInternal) {
                            object suffixValue = DataBinder.GetPropertyValue(dataRow, suffixName);
                            suffixTable.Add(suffixName, suffixValue);
                        }
                        if (suffixArray.Count == index) {
                            suffixArray.Add(new DataKey(suffixTable, ClientIDRowSuffixInternal));
                        }
                        else {
                            suffixArray[index] = new DataKey(suffixTable, ClientIDRowSuffixInternal);
                        }
                    }

                    if (storeKeys && EnablePersistedSelection) {
                        if (index < keyArray.Count) {
                            SetPersistedDataKey(index, (DataKey)keyArray[index]);
                        }
                    }

                    rowState = DataControlRowState.Normal;
                    if (index == editIndex)
                        rowState |= DataControlRowState.Edit;
                    if (index == _selectedIndex)
                        rowState |= DataControlRowState.Selected;
                    if (index % 2 != 0) {
                        rowState |= DataControlRowState.Alternate;
                    }

                    row = CreateRow(index, dataSourceIndex, rowType, rowState, dataBinding, dataRow, displayFields, rows, null);
                    _rowsArray.Add(row);

                    count++;
                    dataSourceIndex++;
                    index++;
                }

                if (index == 0) {
                    CreateRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, dataBinding, null, displayFields, rows, null);
                }

                _footerRow = CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal, dataBinding, null, displayFields, rows, null);
                if (!ShowFooter) {
                    _footerRow.Visible = false;
                }

                if (createPager && PagerSettings.Visible && _pagerSettings.IsPagerOnBottom) {
                    _bottomPagerRow = CreateRow(-1, -1, DataControlRowType.Pager, DataControlRowState.Normal, dataBinding, null, displayFields, rows, pagedDataSource);
                }
            }

            int createdRowsCount = -1;
            if (dataBinding) {
                if (pagedDataSourceEnumerator != null) {
                    if (pagedDataSource.IsPagingEnabled) {
                        _pageCount = pagedDataSource.PageCount;
                        createdRowsCount = pagedDataSource.DataSourceCount;
                    }
                    else {
                        _pageCount = 1;
                        createdRowsCount = count;
                    }
                }
                else {
                    _pageCount = 0;
                }
            }

            if (PageCount == 1) {   // don't show the pager if there's just one row.
                if (_topPagerRow != null) {
                    _topPagerRow.Visible = false;
                }
                if (_bottomPagerRow != null) {
                    _bottomPagerRow.Visible = false;
                }
            }
            return createdRowsCount;

        }
コード例 #12
0
ファイル: GridView.cs プロジェクト: Bewolf2/GenesisMono
		public sealed override void DataBind ()
		{
			DataKeyArrayList.Clear ();
			cachedKeyProperties = null;
			base.DataBind ();

			keys = new DataKeyArray (DataKeyArrayList);
			
			GridViewRow row = HeaderRow;
			if (row != null)
				row.Visible = ShowHeader;

			row = FooterRow;
			if (row != null)
				row.Visible = ShowFooter;
		}
コード例 #13
0
ファイル: GridView.cs プロジェクト: nobled/mono
		void LoadDataKeyArrayState (object [] state, out DataKeyArray keys)
		{
			List <DataKey> dataKeyList = DataKeyList;
			string[] dataKeyNames = DataKeyNames;
			int dataKeyNamesLen = dataKeyNames.Length;
			
			for (int i = 0; i < state.Length; i++) {
				DataKey dataKey = new DataKey (new OrderedDictionary (dataKeyNamesLen), dataKeyNames);
				((IStateManager) dataKey).LoadViewState (state [i]);
				dataKeyList.Add (dataKey);
			}
			keys = new DataKeyArray (dataKeyList);
		}
コード例 #14
0
ファイル: GridView.cs プロジェクト: nobled/mono
		object [] SaveDataKeyArrayState (DataKeyArray keys)
		{
			if (keys == null)
				return null;

			object [] state = new object [keys.Count];
			for (int i = 0; i < keys.Count; i++)
				state [i] = ((IStateManager) keys [i]).SaveViewState ();
			return state;
		}
コード例 #15
0
        protected override int CreateChildControls(IEnumerable dataSource, bool dataBinding)
        {
            PagedDataSource pagedDataSource = null;
            if (dataBinding)
            {
                bool allowPaging = this.AllowPaging;
                DataSourceView data = this.GetData();
                DataSourceSelectArguments selectArguments = base.SelectArguments;
                if (data == null)
                {
                    throw new HttpException(System.Web.SR.GetString("DataBoundControl_NullView", new object[] { this.ID }));
                }
                bool flag2 = allowPaging && data.CanPage;
                if ((allowPaging && !data.CanPage) && ((dataSource != null) && !(dataSource is ICollection)))
                {
                    selectArguments.StartRowIndex = this.PageSize * this.PageIndex;
                    selectArguments.MaximumRows = this.PageSize;
                    data.Select(selectArguments, new DataSourceViewSelectCallback(this.SelectCallback));
                }
                if (flag2)
                {
                    if (data.CanRetrieveTotalRowCount)
                    {
                        pagedDataSource = this.CreateServerPagedDataSource(selectArguments.TotalRowCount);
                    }
                    else
                    {
                        ICollection is2 = dataSource as ICollection;
                        if (is2 == null)
                        {
                            throw new HttpException(System.Web.SR.GetString("DataBoundControl_NeedICollectionOrTotalRowCount", new object[] { base.GetType().Name }));
                        }
                        int num = this.PageIndex * this.PageSize;
                        pagedDataSource = this.CreateServerPagedDataSource(num + is2.Count);
                    }
                }
                else
                {
                    pagedDataSource = this.CreatePagedDataSource();
                }
            }
            else
            {
                pagedDataSource = this.CreatePagedDataSource();
            }
            IEnumerator enumerator = null;
            int num2 = 0;
            ArrayList dataKeysArrayList = this.DataKeysArrayList;
            ArrayList clientIDRowSuffixArrayList = this.ClientIDRowSuffixArrayList;
            ICollection is3 = null;
            int count = -1;
            int capacity = 0;
            ICollection is4 = dataSource as ICollection;
            if (dataBinding)
            {
                dataKeysArrayList.Clear();
                clientIDRowSuffixArrayList.Clear();
                if (((dataSource != null) && (is4 == null)) && (pagedDataSource.IsPagingEnabled && !pagedDataSource.IsServerPagingEnabled))
                {
                    throw new HttpException(System.Web.SR.GetString("GridView_Missing_VirtualItemCount", new object[] { this.ID }));
                }
            }
            else if (is4 == null)
            {
                throw new HttpException(System.Web.SR.GetString("DataControls_DataSourceMustBeCollectionWhenNotDataBinding"));
            }
            this._pageCount = 0;
            if (dataSource != null)
            {
                pagedDataSource.DataSource = dataSource;
                if (pagedDataSource.IsPagingEnabled && dataBinding)
                {
                    int pageCount = pagedDataSource.PageCount;
                    if (pagedDataSource.CurrentPageIndex >= pageCount)
                    {
                        int num6 = pageCount - 1;
                        pagedDataSource.CurrentPageIndex = this._pageIndex = num6;
                    }
                }
                is3 = this.CreateColumns(dataBinding ? pagedDataSource : null, dataBinding);
                if (is4 != null)
                {
                    count = is4.Count;
                    int num7 = pagedDataSource.IsPagingEnabled ? pagedDataSource.PageSize : is4.Count;
                    capacity = num7;
                    if (dataBinding)
                    {
                        dataKeysArrayList.Capacity = num7;
                        clientIDRowSuffixArrayList.Capacity = num7;
                    }
                    if (pagedDataSource.DataSourceCount == 0)
                    {
                        this._pageCount = 0;
                    }
                    else
                    {
                        this._pageCount = pagedDataSource.PageCount;
                    }
                }
            }
            this._rowsArray = new ArrayList(capacity);
            this._rowsCollection = null;
            this._dataKeyArray = null;
            this._clientIDRowSuffixArray = null;
            Table child = this.CreateChildTable();
            this.Controls.Add(child);
            TableRowCollection rows = child.Rows;
            if (dataSource == null)
            {
                if ((this.EmptyDataTemplate != null) || (this.EmptyDataText.Length > 0))
                {
                    this.CreateRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, dataBinding, null, new DataControlField[0], rows, null);
                }
                else
                {
                    this.Controls.Clear();
                }
                return 0;
            }
            int num8 = 0;
            if (is3 != null)
            {
                num8 = is3.Count;
            }
            DataControlField[] array = new DataControlField[num8];
            if (num8 > 0)
            {
                is3.CopyTo(array, 0);
                bool flag3 = false;
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i].Initialize(this.AllowSorting, this))
                    {
                        flag3 = true;
                    }
                    if (this.DetermineRenderClientScript())
                    {
                        array[i].ValidateSupportsCallback();
                    }
                }
                if (flag3)
                {
                    base.RequiresDataBinding = true;
                }
            }
            int dataItemIndex = 0;
            int dataSourceIndex = 0;
            string[] dataKeyNamesInternal = this.DataKeyNamesInternal;
            bool flag4 = dataBinding && (dataKeyNamesInternal.Length != 0);
            bool flag5 = dataBinding && (this.ClientIDRowSuffixInternal.Length != 0);
            bool isPagingEnabled = pagedDataSource.IsPagingEnabled;
            int editIndex = this.EditIndex;
            switch (count)
            {
                case -1:
                    if (this._storedDataValid)
                    {
                        if (this._firstDataRow != null)
                        {
                            count = 1;
                        }
                        else
                        {
                            count = 0;
                        }
                    }
                    else
                    {
                        IEnumerator enumerator2 = dataSource.GetEnumerator();
                        if (enumerator2.MoveNext())
                        {
                            object current = enumerator2.Current;
                            this.StoreEnumerator(enumerator2, current);
                            count = 1;
                        }
                        else
                        {
                            count = 0;
                        }
                    }
                    break;

                case 0:
                {
                    bool flag7 = false;
                    if ((this.ShowHeader && this.ShowHeaderWhenEmpty) && (array.Length > 0))
                    {
                        this._headerRow = this.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal, dataBinding, null, array, rows, null);
                        flag7 = true;
                    }
                    if ((this.EmptyDataTemplate != null) || (this.EmptyDataText.Length > 0))
                    {
                        this.CreateRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, dataBinding, null, array, rows, null);
                        flag7 = true;
                    }
                    if (!flag7)
                    {
                        this.Controls.Clear();
                    }
                    this._storedDataValid = false;
                    this._firstDataRow = null;
                    return 0;
                }
            }
            if (num8 > 0)
            {
                GridViewRow row;
                DataControlRowType dataRow;
                DataControlRowState normal;
                if (pagedDataSource.IsPagingEnabled)
                {
                    dataSourceIndex = pagedDataSource.FirstIndexInPage;
                }
                if ((isPagingEnabled && this.PagerSettings.Visible) && this._pagerSettings.IsPagerOnTop)
                {
                    this._topPagerRow = this.CreateRow(-1, -1, DataControlRowType.Pager, DataControlRowState.Normal, dataBinding, null, array, rows, pagedDataSource);
                }
                this._headerRow = this.CreateRow(-1, -1, DataControlRowType.Header, DataControlRowState.Normal, dataBinding, null, array, rows, null);
                if (!this.ShowHeader)
                {
                    this._headerRow.Visible = false;
                }
                if (flag4)
                {
                    this.ResetPersistedSelectedIndex();
                }
                if (this._storedDataValid)
                {
                    enumerator = this._storedData;
                    if (this._firstDataRow != null)
                    {
                        if (flag4)
                        {
                            OrderedDictionary keyTable = new OrderedDictionary(dataKeyNamesInternal.Length);
                            foreach (string str in dataKeyNamesInternal)
                            {
                                object propertyValue = DataBinder.GetPropertyValue(this._firstDataRow, str);
                                keyTable.Add(str, propertyValue);
                            }
                            if (dataKeysArrayList.Count == dataItemIndex)
                            {
                                dataKeysArrayList.Add(new DataKey(keyTable, dataKeyNamesInternal));
                            }
                            else
                            {
                                dataKeysArrayList[dataItemIndex] = new DataKey(keyTable, dataKeyNamesInternal);
                            }
                        }
                        if (flag5)
                        {
                            OrderedDictionary dictionary2 = new OrderedDictionary(this.ClientIDRowSuffixInternal.Length);
                            foreach (string str2 in this.ClientIDRowSuffixInternal)
                            {
                                object obj4 = DataBinder.GetPropertyValue(this._firstDataRow, str2);
                                dictionary2.Add(str2, obj4);
                            }
                            if (clientIDRowSuffixArrayList.Count == dataItemIndex)
                            {
                                clientIDRowSuffixArrayList.Add(new DataKey(dictionary2, this.ClientIDRowSuffixInternal));
                            }
                            else
                            {
                                clientIDRowSuffixArrayList[dataItemIndex] = new DataKey(dictionary2, this.ClientIDRowSuffixInternal);
                            }
                        }
                        if ((flag4 && this.EnablePersistedSelection) && (dataItemIndex < dataKeysArrayList.Count))
                        {
                            this.SetPersistedDataKey(dataItemIndex, (DataKey) dataKeysArrayList[dataItemIndex]);
                        }
                        dataRow = DataControlRowType.DataRow;
                        normal = DataControlRowState.Normal;
                        if (dataItemIndex == editIndex)
                        {
                            normal |= DataControlRowState.Edit;
                        }
                        if (dataItemIndex == this._selectedIndex)
                        {
                            normal |= DataControlRowState.Selected;
                        }
                        row = this.CreateRow(0, dataSourceIndex, dataRow, normal, dataBinding, this._firstDataRow, array, rows, null);
                        this._rowsArray.Add(row);
                        num2++;
                        dataItemIndex++;
                        dataSourceIndex++;
                        this._storedDataValid = false;
                        this._firstDataRow = null;
                    }
                }
                else
                {
                    enumerator = pagedDataSource.GetEnumerator();
                }
                dataRow = DataControlRowType.DataRow;
                while (enumerator.MoveNext())
                {
                    object container = enumerator.Current;
                    if (flag4)
                    {
                        OrderedDictionary dictionary3 = new OrderedDictionary(dataKeyNamesInternal.Length);
                        foreach (string str3 in dataKeyNamesInternal)
                        {
                            object obj6 = DataBinder.GetPropertyValue(container, str3);
                            dictionary3.Add(str3, obj6);
                        }
                        if (dataKeysArrayList.Count == dataItemIndex)
                        {
                            dataKeysArrayList.Add(new DataKey(dictionary3, dataKeyNamesInternal));
                        }
                        else
                        {
                            dataKeysArrayList[dataItemIndex] = new DataKey(dictionary3, dataKeyNamesInternal);
                        }
                    }
                    if (flag5)
                    {
                        OrderedDictionary dictionary4 = new OrderedDictionary(this.ClientIDRowSuffixInternal.Length);
                        foreach (string str4 in this.ClientIDRowSuffixInternal)
                        {
                            object obj7 = DataBinder.GetPropertyValue(container, str4);
                            dictionary4.Add(str4, obj7);
                        }
                        if (clientIDRowSuffixArrayList.Count == dataItemIndex)
                        {
                            clientIDRowSuffixArrayList.Add(new DataKey(dictionary4, this.ClientIDRowSuffixInternal));
                        }
                        else
                        {
                            clientIDRowSuffixArrayList[dataItemIndex] = new DataKey(dictionary4, this.ClientIDRowSuffixInternal);
                        }
                    }
                    if ((flag4 && this.EnablePersistedSelection) && (dataItemIndex < dataKeysArrayList.Count))
                    {
                        this.SetPersistedDataKey(dataItemIndex, (DataKey) dataKeysArrayList[dataItemIndex]);
                    }
                    normal = DataControlRowState.Normal;
                    if (dataItemIndex == editIndex)
                    {
                        normal |= DataControlRowState.Edit;
                    }
                    if (dataItemIndex == this._selectedIndex)
                    {
                        normal |= DataControlRowState.Selected;
                    }
                    if ((dataItemIndex % 2) != 0)
                    {
                        normal |= DataControlRowState.Alternate;
                    }
                    row = this.CreateRow(dataItemIndex, dataSourceIndex, dataRow, normal, dataBinding, container, array, rows, null);
                    this._rowsArray.Add(row);
                    num2++;
                    dataSourceIndex++;
                    dataItemIndex++;
                }
                if (dataItemIndex == 0)
                {
                    this.CreateRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, dataBinding, null, array, rows, null);
                }
                this._footerRow = this.CreateRow(-1, -1, DataControlRowType.Footer, DataControlRowState.Normal, dataBinding, null, array, rows, null);
                if (!this.ShowFooter)
                {
                    this._footerRow.Visible = false;
                }
                if ((isPagingEnabled && this.PagerSettings.Visible) && this._pagerSettings.IsPagerOnBottom)
                {
                    this._bottomPagerRow = this.CreateRow(-1, -1, DataControlRowType.Pager, DataControlRowState.Normal, dataBinding, null, array, rows, pagedDataSource);
                }
            }
            int dataSourceCount = -1;
            if (dataBinding)
            {
                if (enumerator != null)
                {
                    if (pagedDataSource.IsPagingEnabled)
                    {
                        this._pageCount = pagedDataSource.PageCount;
                        dataSourceCount = pagedDataSource.DataSourceCount;
                    }
                    else
                    {
                        this._pageCount = 1;
                        dataSourceCount = num2;
                    }
                }
                else
                {
                    this._pageCount = 0;
                }
            }
            if (this.PageCount == 1)
            {
                if (this._topPagerRow != null)
                {
                    this._topPagerRow.Visible = false;
                }
                if (this._bottomPagerRow != null)
                {
                    this._bottomPagerRow.Visible = false;
                }
            }
            return dataSourceCount;
        }
コード例 #16
0
		protected override int CreateChildControls (IEnumerable data, bool dataBinding)
		{
			PagedDataSource dataSource;

			if (dataBinding) {
				DataSourceView view = GetData ();
				dataSource = new PagedDataSource ();
				dataSource.DataSource = data;
				
				if (AllowPaging) {
					dataSource.AllowPaging = true;
					dataSource.PageSize = PageSize;
					dataSource.CurrentPageIndex = PageIndex;
					if (view.CanPage) {
						dataSource.AllowServerPaging = true;
						if (view.CanRetrieveTotalRowCount)
							dataSource.VirtualCount = SelectArguments.TotalRowCount;
						else {
							dataSource.DataSourceView = view;
							dataSource.DataSourceSelectArguments = SelectArguments;
							dataSource.SetItemCountFromPageIndex (PageIndex + PagerSettings.PageButtonCount);
						}
					}
				}
				
				pageCount = dataSource.PageCount;
			}
			else
			{
				dataSource = new PagedDataSource ();
				dataSource.DataSource = data;
				if (AllowPaging) {
					dataSource.AllowPaging = true;
					dataSource.PageSize = PageSize;
					dataSource.CurrentPageIndex = PageIndex;
				}
			}

			bool showPager = AllowPaging && (PageCount > 1);
			
			Controls.Clear ();
			table = CreateChildTable ();
			Controls.Add (table);
				
			ArrayList list = new ArrayList ();
			ArrayList keyList = new ArrayList ();
			
			// Creates the set of fields to show
			
			ICollection fieldCollection = CreateColumns (dataSource, dataBinding);
			DataControlField[] fields = new DataControlField [fieldCollection.Count];
			fieldCollection.CopyTo (fields, 0);

			foreach (DataControlField field in fields) {
				field.Initialize (AllowSorting, this);
				if (EnableSortingAndPagingCallbacks)
					field.ValidateSupportsCallback ();
			}

			// Main table creation
			
			if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
				topPagerRow = CreatePagerRow (fields.Length, dataSource);
				table.Rows.Add (topPagerRow);
			}

			if (ShowHeader) {
				headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
				table.Rows.Add (headerRow);
				InitializeRow (headerRow, fields);
			}
			
			foreach (object obj in dataSource) {
				DataControlRowState rstate = GetRowState (list.Count);
				GridViewRow row = CreateRow (list.Count, list.Count, DataControlRowType.DataRow, rstate);
				row.DataItem = obj;
				list.Add (row);
				table.Rows.Add (row);
				InitializeRow (row, fields);
				if (dataBinding) {
//					row.DataBind ();
					OnRowDataBound (new GridViewRowEventArgs (row));
					if (EditIndex == row.RowIndex)
						oldEditValues = new DataKey (GetRowValues (row, false, true));
					keyList.Add (new DataKey (CreateRowDataKey (row), DataKeyNames));
				} else {
					if (EditIndex == row.RowIndex)
						oldEditValues = new DataKey (new OrderedDictionary ());
					keyList.Add (new DataKey (new OrderedDictionary (), DataKeyNames));
				}

				if (list.Count >= PageSize)
					break;
			}
			
			if (list.Count == 0)
				table.Rows.Add (CreateEmptyrRow (fields.Length));

			if (ShowFooter) {
				footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
				table.Rows.Add (footerRow);
				InitializeRow (footerRow, fields);
			}

			if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
				bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
				table.Rows.Add (bottomPagerRow);
			}

			rows = new GridViewRowCollection (list);
			keys = new DataKeyArray (keyList);
			
			if (dataBinding)
				DataBind (false);

			return dataSource.DataSourceCount;
		}