示例#1
0
        public void CleanFooter()
        {
            System.Web.UI.WebControls.DataGridColumnCollection columns = gridHandler.DataGrid.Columns;

            for (int i = 0, j = columns.Count; i < j; i++)
            {
                columns[i].FooterText = String.Empty;
            }
        }
示例#2
0
		protected override void CreateControlHierarchy(bool useDataSource)
		{
			IEnumerator pageSourceEnumerator;
			int         itemCount;
			ArrayList   dataKeys;
			ArrayList   columns;
			IEnumerable resolvedDS;
			ICollection collResolvedDS;
			int         pageDSCount;
			int         colCount;
			DataGridColumn[] cols;
			Table       deployTable;
			TableRowCollection deployRows;
			ListItemType deployType;
			int         indexCounter;
			string      dkField;
			bool        dsUse;
			bool        pgEnabled;
			int         editIndex;
			int         selIndex;

			pagedDataSource = CreatePagedDataSource();
			pageSourceEnumerator  = null;
			itemCount       = -1;
			dataKeys        = DataKeysArray;
			columns         = null;
			if(itemsArrayList != null)
			{
				itemsArrayList.Clear();
			} else
			{
				itemsArrayList = new ArrayList();
			}
			if(!useDataSource)
			{
				itemCount    = (int) ViewState["_!ItemCount"];
				pageDSCount  = (int) ViewState["_!DataSource_ItemCount"];
				if(itemCount != -1)
				{
					if(pagedDataSource.IsCustomPagingEnabled)
					{
						pagedDataSource.DataSource = new DataSourceInternal(itemCount);
					} else
					{
						pagedDataSource.DataSource = new DataSourceInternal(pageDSCount);
					}
					pageSourceEnumerator = pagedDataSource.GetEnumerator();
					columns              = CreateColumnSet(null, false);
					itemsArrayList.Capacity = itemCount;
				}
			} else
			{
				dataKeys.Clear();
				resolvedDS = GetResolvedDataSource ();
				if(resolvedDS != null)
				{
					collResolvedDS = resolvedDS as ICollection;
					if(pagedDataSource.IsPagingEnabled && !pagedDataSource.IsCustomPagingEnabled
					   && collResolvedDS == null)
					{
						throw new HttpException(HttpRuntime.FormatResourceString("DataGrid_Missing_VirtualItemCount", ID));
					}
					pagedDataSource.DataSource = resolvedDS;
					if(pagedDataSource.IsPagingEnabled && (pagedDataSource.CurrentPageIndex < 0 ||
							pagedDataSource.PageCount < pagedDataSource.CurrentPageIndex))
					{
						throw new HttpException(HttpRuntime.FormatResourceString("DataGrid_Invalid_Current_PageIndex", ID));
					}
					columns = CreateColumnSet(pagedDataSource, useDataSource);

					if(storedDataValid)
					{
						pageSourceEnumerator = storedData;
					} else
					{
						pageSourceEnumerator = pagedDataSource.GetEnumerator();
					}
					if(collResolvedDS != null)
					{
						pageDSCount         = pagedDataSource.Count;
						dataKeys.Capacity   = pageDSCount;
						itemsArrayList.Capacity = pageDSCount;
					}
				}
			}

			colCount = 0;
			if(columns != null)
				colCount = columns.Count;
			int currentSourceIndex;
			if(colCount > 0)
			{
				cols = (DataGridColumn []) columns.ToArray (typeof (DataGridColumn));
				foreach(DataGridColumn current in cols)
				{
					current.Initialize();
				}
				deployTable = new DataGridTableInternal();
				Controls.Add(deployTable);
				deployRows = deployTable.Rows;

				indexCounter = 0;
				currentSourceIndex  = 0;
				dkField = DataKeyField;

				dsUse = (useDataSource) ? (dkField.Length > 0) : false;
				pgEnabled = pagedDataSource.IsPagingEnabled;
				editIndex = EditItemIndex;
				selIndex  = SelectedIndex;
				if(pgEnabled)
				{
					currentSourceIndex = pagedDataSource.FirstIndexInPage;
					CreateItem(-1, -1, ListItemType.Pager, false, null,
						   cols, deployRows, pagedDataSource);
				}
				itemCount = 0;
				CreateItem(-1, -1, ListItemType.Header, useDataSource, null,
					   cols, deployRows, null);
				
				if(storedDataValid && storedDataFirst != null)
				{
					if(dsUse)
					{
						dataKeys.Add(DataBinder.GetPropertyValue(storedDataFirst, dkField));
					}
					if (indexCounter == editIndex) {
						deployType = ListItemType.EditItem;
					} else if (indexCounter == selIndex) {
						deployType = ListItemType.SelectedItem;
					} else {
						deployType = ListItemType.Item;
					}

					itemsArrayList.Add(CreateItem(0, currentSourceIndex, deployType,
								      useDataSource, storedDataFirst,
								      cols, deployRows, null));
					itemCount++;
					indexCounter++;
					currentSourceIndex++;
					storedDataValid = false;
					storedDataFirst = null;
				}

				while(pageSourceEnumerator.MoveNext())
				{
					object current = pageSourceEnumerator.Current;
					if(dsUse)
					{
						dataKeys.Add(DataBinder.GetPropertyValue(current, dkField));
					}

					if (indexCounter == editIndex) {
						deployType = ListItemType.EditItem;
					} else if (indexCounter == selIndex) {
						deployType = ListItemType.SelectedItem;
					} else if ((indexCounter % 2) == 1) {
						deployType = ListItemType.AlternatingItem;
					} else {
						deployType = ListItemType.Item;
					}

					itemsArrayList.Add(CreateItem(indexCounter, currentSourceIndex,
								      deployType, useDataSource, current,
								      cols, deployRows, null));
					itemCount++;
					indexCounter++;
					currentSourceIndex++;
				}

				CreateItem(-1, -1, ListItemType.Footer, useDataSource, null,
					   cols, deployRows, null);

				if(pgEnabled)
				{
					CreateItem(-1, -1, ListItemType.Pager, false, null, cols, deployRows,
						   pagedDataSource);
				}
			}

			if(useDataSource)
			{
				if(pageSourceEnumerator != null)
				{
					ViewState["_!ItemCount"] = itemCount;
					if(pagedDataSource.IsPagingEnabled)
					{
						ViewState["PageCount"] = pagedDataSource.PageCount;
						ViewState["_!DataSource_ItemCount"] = pagedDataSource.DataSourceCount;
					} else
					{
						ViewState["PageCount"] = 1;
						ViewState["_!DataSource_ItemCount"] = itemCount;
					}
				} else
				{
					ViewState["_!ItemCount"] = -1;
					ViewState["_!DataSource_ItemCount"] = -1;
					ViewState["PageCount"] = 0;
				}
			}
			pagedDataSource = null;
		}