protected void GridView1_RowClicked(System.Web.UI.WebControls.DataKey dataKey, int rowIndex) { Page.Response.Redirect( string.Concat("ErrorType.aspx", "?Id=", HttpContext.Current.Server.UrlEncode(dataKey["Id"].ToString()), "&exceptionType=", HttpContext.Current.Server.UrlEncode(dataKey["ExceptionType"].ToString()), "&opcoCode=", HttpContext.Current.Server.UrlEncode(dataKey["OpCoCode"].ToString()), "&policyName=", HttpContext.Current.Server.UrlEncode(dataKey["Policy"].ToString()), "&UrlReferrer=", HttpContext.Current.Server.UrlEncode(GridView1.UrlReferrer))); }
protected void g_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { System.Web.UI.WebControls.DataKey key = this.g.DataKeys[this.g.DataKeys.Count - 1]; double num = _Convert.StrToDouble(key.Values[0].ToString(), 0.0); ((TextBox)e.Row.Cells[1].FindControl("tbMoney")).Text = (num == 0.0) ? "" : num.ToString(); num = _Convert.StrToDouble(key.Values[1].ToString(), 0.0); ((TextBox)e.Row.Cells[2].FindControl("tbMoneyNoWithTax")).Text = (num == 0.0) ? "" : num.ToString(); } }
/// <summary> /// Deletes a row in grid view /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void grdResultCodes_RowDeleting(object sender, GridViewDeleteEventArgs e) { System.Web.UI.WebControls.DataKey dk = ((System.Web.UI.WebControls.DataKey)grdResultCodes.DataKeys[e.RowIndex]); long ResultCodeID = Convert.ToInt64(dk.Value); ResultCode objResultCode = new ResultCode(); Campaign objCampaign = new Campaign(); if (Session["Campaign"] != null) { objCampaign = (Campaign)Session["Campaign"]; } try { objResultCode.ResultCodeID = ResultCodeID; LinkButton lbtn = (LinkButton)grdResultCodes.Rows[e.RowIndex].Cells[1].FindControl("lbtnStatus"); objResultCode.Description = lbtn.Text; objResultCode.RecycleInDays = Convert.ToInt32(grdResultCodes.Rows[e.RowIndex].Cells[2].Text); objResultCode.Presentation = Convert.ToBoolean(grdResultCodes.Rows[e.RowIndex].Cells[3].Text); objResultCode.Redialable = Convert.ToBoolean(grdResultCodes.Rows[e.RowIndex].Cells[4].Text); objResultCode.Lead = Convert.ToBoolean(grdResultCodes.Rows[e.RowIndex].Cells[5].Text); objResultCode.MasterDNC = Convert.ToBoolean(grdResultCodes.Rows[e.RowIndex].Cells[6].Text); objResultCode.NeverCall = Convert.ToBoolean(grdResultCodes.Rows[e.RowIndex].Cells[7].Text); objResultCode.VerifyOnly = Convert.ToBoolean(grdResultCodes.Rows[e.RowIndex].Cells[8].Text); objResultCode.DialThroughAll = false; objResultCode.ShowDeletedResultCodes = false; objResultCode.DateDeleted = DateTime.Now.Date; CampaignService objCampaignService = new CampaignService(); XmlDocument xDocResultCode = new XmlDocument(); XmlDocument xDocCampaign = new XmlDocument(); xDocResultCode.LoadXml(Serialize.SerializeObject(objResultCode, "ResultCode")); xDocCampaign.LoadXml(Serialize.SerializeObject(objCampaign, "Campaign")); objCampaignService.ResultCodeInsertUpdate(xDocCampaign, xDocResultCode); BindResultCodesLocal(); } catch (Exception ex) { PageMessage = ex.Message; } }
/// <devdoc> /// <para>Copies the contents of the entire collection into an <see cref='System.Array' qualify='true'/> appending at /// the specified index of the <see cref='System.Array' qualify='true'/>.</para> /// </devdoc> public void CopyTo(DataKey[] array, int index) { ((ICollection)this).CopyTo(array, index); }
protected internal override void LoadControlState(object savedState) { // Any properties that could have been set in the persistance need to be // restored to their defaults if they're not in ControlState, or they will // be restored to their persisted state instead of their empty state. _startRowIndex = 0; _maximumRows = -1; _editIndex = -1; _selectedIndex = -1; _groupItemCount = 1; _sortExpression = String.Empty; _sortDirection = SortDirection.Ascending; _dataKeyNames = new string[0]; object[] state = savedState as object[]; if (state != null) { base.LoadControlState(state[0]); if (state[1] != null) { _editIndex = (int)state[1]; } if (state[2] != null) { _selectedIndex = (int)state[2]; } if (state[3] != null) { _groupItemCount = (int)state[3]; } if (state[4] != null) { _sortExpression = (string)state[4]; } if (state[5] != null) { _sortDirection = (SortDirection)state[5]; } if (state[6] != null) { _dataKeyNames = (string[])state[6]; } if (state[7] != null) { LoadDataKeysState(state[7]); } if (state[8] != null) { _totalRowCount = (int)state[8]; } if (state[9] != null) { if ((_dataKeyNames != null) && (_dataKeyNames.Length > 0)) { _persistedDataKey = new DataKey(new OrderedDictionary(_dataKeyNames.Length), _dataKeyNames); ((IStateManager)_persistedDataKey).LoadViewState(state[9]); } } if (state[10] != null) { _clientIDRowSuffix = (string[])state[10]; } if (state[11] != null) { LoadClientIDRowSuffixDataKeysState(state[11]); } if (state[12] != null) { _startRowIndex = (int)state[12]; } if (state[13] != null) { _maximumRows = (int)state[13]; } } else { base.LoadControlState(null); } // DataPager handles the TotalRowCountAvailable event in order to create its pager fields. Normally this // is fired from CreateChildControls, but when ViewState is disabled this is not getting called until after // postback data has been handled. In this case the event will be fired using the control count from the // last request so that the pager fields can be initialized. if (!IsViewStateEnabled) { OnTotalRowCountAvailable(new PageEventArgs(_startRowIndex, _maximumRows, _totalRowCount)); } }
protected virtual IList<ListViewDataItem> CreateItemsInGroups(ListViewPagedDataSource dataSource, bool dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) { // If this is the first time we're creating the control items, we need // to locate the groupPlaceholder container. // If this is a scenario where we are recreating control items, we already // have the cached groupPlaceholder container. if (_groupsOriginalIndexOfGroupPlaceholderInContainer == -1) { _groupsGroupPlaceholderContainer = GetPreparedContainerInfo(this, false, out _groupsOriginalIndexOfGroupPlaceholderInContainer); } int groupInsertLocation = _groupsOriginalIndexOfGroupPlaceholderInContainer; _groupsItemCreatedCount = 0; int itemInsertLocation = 0; Control itemPlaceholderContainer = null; // Reset the selected index if we have a persisted datakey so we // can figure out what index to select based on the key ResetPersistedSelectedIndex(); List<ListViewDataItem> items = new List<ListViewDataItem>(); int itemIndex = 0; int dataItemIndex = 0; if (insertPosition == InsertItemPosition.FirstItem) { ListViewContainer groupContainer = new ListViewContainer(); AutoIDControl(groupContainer); InstantiateGroupTemplate(groupContainer); AddControlToContainer(groupContainer, _groupsGroupPlaceholderContainer, groupInsertLocation); groupInsertLocation++; itemPlaceholderContainer = GetPreparedContainerInfo(groupContainer, true, out itemInsertLocation); ListViewItem insertItem = CreateInsertItem(); AddControlToContainer(insertItem, itemPlaceholderContainer, itemInsertLocation); insertItem.DataBind(); itemInsertLocation++; itemIndex++; } foreach (object o in dataSource) { if (itemIndex % _groupItemCount == 0) { if (itemIndex != 0 && _groupSeparatorTemplate != null) { ListViewContainer groupSeparatorContainer = new ListViewContainer(); AutoIDControl(groupSeparatorContainer); InstantiateGroupSeparatorTemplate(groupSeparatorContainer); AddControlToContainer(groupSeparatorContainer, _groupsGroupPlaceholderContainer, groupInsertLocation); groupInsertLocation++; } ListViewContainer groupContainer = new ListViewContainer(); AutoIDControl(groupContainer); InstantiateGroupTemplate(groupContainer); AddControlToContainer(groupContainer, _groupsGroupPlaceholderContainer, groupInsertLocation); groupInsertLocation++; itemPlaceholderContainer = GetPreparedContainerInfo(groupContainer, true, out itemInsertLocation); } ListViewDataItem item = CreateDataItem(dataItemIndex + StartRowIndex, dataItemIndex); if (dataBinding) { item.DataItem = o; OrderedDictionary keyTable = new OrderedDictionary(DataKeyNamesInternal.Length); foreach (string keyName in DataKeyNamesInternal) { object keyValue = DataBinder.GetPropertyValue(o, keyName); keyTable.Add(keyName, keyValue); } if (keyArray.Count == dataItemIndex) { keyArray.Add(new DataKey(keyTable, DataKeyNamesInternal)); } else { keyArray[dataItemIndex] = new DataKey(keyTable, DataKeyNamesInternal); } } // If persisted selection is enabled and we have a data key then compare it to get the selected index if (EnablePersistedSelection) { if (dataItemIndex < keyArray.Count) { DataKey currentKey = (DataKey)keyArray[dataItemIndex]; SetPersistedDataKey(dataItemIndex, currentKey); } } InstantiateItemTemplate(item, dataItemIndex); OnItemCreated(new ListViewItemEventArgs(item)); if (itemIndex % _groupItemCount != 0 && _itemSeparatorTemplate != null) { ListViewContainer itemSeparatorContainer = new ListViewContainer(); InstantiateItemSeparatorTemplate(itemSeparatorContainer); AddControlToContainer(itemSeparatorContainer, itemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; } AddControlToContainer(item, itemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; items.Add(item); if (dataBinding) { item.DataBind(); OnItemDataBound(new ListViewItemEventArgs(item)); item.DataItem = null; } itemIndex++; dataItemIndex++; } if (insertPosition == InsertItemPosition.LastItem) { if (itemIndex % _groupItemCount == 0) { // start a new group if (itemIndex != 0 && _groupSeparatorTemplate != null) { ListViewContainer groupSeparatorContainer = new ListViewContainer(); AutoIDControl(groupSeparatorContainer); InstantiateGroupSeparatorTemplate(groupSeparatorContainer); AddControlToContainer(groupSeparatorContainer, _groupsGroupPlaceholderContainer, groupInsertLocation); groupInsertLocation++; } ListViewContainer groupContainer = new ListViewContainer(); AutoIDControl(groupContainer); InstantiateGroupTemplate(groupContainer); AddControlToContainer(groupContainer, _groupsGroupPlaceholderContainer, groupInsertLocation); groupInsertLocation++; itemPlaceholderContainer = GetPreparedContainerInfo(groupContainer, true, out itemInsertLocation); } // use the existing group if (itemIndex % _groupItemCount != 0 && _itemSeparatorTemplate != null) { ListViewContainer itemSeparatorContainer = new ListViewContainer(); InstantiateItemSeparatorTemplate(itemSeparatorContainer); AddControlToContainer(itemSeparatorContainer, itemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; } ListViewItem insertItem = CreateInsertItem(); AddControlToContainer(insertItem, itemPlaceholderContainer, itemInsertLocation); insertItem.DataBind(); itemInsertLocation++; itemIndex++; } // fill in the rest of the items if there's an emptyItemTemplate if (_emptyItemTemplate != null) { while (itemIndex % _groupItemCount != 0) { if (_itemSeparatorTemplate != null) { ListViewContainer itemSeparatorContainer = new ListViewContainer(); InstantiateItemSeparatorTemplate(itemSeparatorContainer); AddControlToContainer(itemSeparatorContainer, itemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; } ListViewItem emptyItem = CreateEmptyItem(); AddControlToContainer(emptyItem, itemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; itemIndex++; } } _groupsItemCreatedCount = groupInsertLocation - _groupsOriginalIndexOfGroupPlaceholderInContainer; return items; }
protected virtual IList<ListViewDataItem> CreateItemsWithoutGroups(ListViewPagedDataSource dataSource, bool dataBinding, InsertItemPosition insertPosition, ArrayList keyArray) { // If this is the first time we're creating the control items, we need // to locate the itemPlaceholder container. // If this is a scenario where we are recreating control items, we already // have the cached itemPlaceholder container. if (_noGroupsOriginalIndexOfItemPlaceholderInContainer == -1) { _noGroupsItemPlaceholderContainer = GetPreparedContainerInfo(this, true, out _noGroupsOriginalIndexOfItemPlaceholderInContainer); } // We need to keep track of where we're inserting items and how many items we have // inserted so that if we need to remove them we know what to do. int itemInsertLocation = _noGroupsOriginalIndexOfItemPlaceholderInContainer; List<ListViewDataItem> items = new List<ListViewDataItem>(); int itemIndex = 0; int dataItemIndex = 0; if (insertPosition == InsertItemPosition.FirstItem) { ListViewItem insertItem = CreateInsertItem(); AddControlToContainer(insertItem, _noGroupsItemPlaceholderContainer, itemInsertLocation); insertItem.DataBind(); itemInsertLocation++; itemIndex++; } // Reset the selected index if we have a persisted datakey so we // can figure out what index to select based on the key ResetPersistedSelectedIndex(); foreach (object o in dataSource) { if (itemIndex != 0 && _itemSeparatorTemplate != null) { ListViewContainer itemSeparatorContainer = new ListViewContainer(); AutoIDControl(itemSeparatorContainer); InstantiateItemSeparatorTemplate(itemSeparatorContainer); AddControlToContainer(itemSeparatorContainer, _noGroupsItemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; } ListViewDataItem item = CreateDataItem(dataItemIndex + dataSource.StartRowIndex, dataItemIndex); AutoIDControl(item); if (dataBinding) { item.DataItem = o; OrderedDictionary keyTable = new OrderedDictionary(DataKeyNamesInternal.Length); foreach (string keyName in DataKeyNamesInternal) { object keyValue = DataBinder.GetPropertyValue(o, keyName); keyTable.Add(keyName, keyValue); } if (keyArray.Count == dataItemIndex) { keyArray.Add(new DataKey(keyTable, DataKeyNamesInternal)); } else { keyArray[dataItemIndex] = new DataKey(keyTable, DataKeyNamesInternal); } } // If persisted selection is enabled and we have a data key then compare it to get the selected index if (EnablePersistedSelection) { if (dataItemIndex < keyArray.Count) { DataKey currentKey = (DataKey)keyArray[dataItemIndex]; SetPersistedDataKey(dataItemIndex, currentKey); } } InstantiateItemTemplate(item, dataItemIndex); OnItemCreated(new ListViewItemEventArgs(item)); AddControlToContainer(item, _noGroupsItemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; items.Add(item); if (dataBinding) { item.DataBind(); OnItemDataBound(new ListViewItemEventArgs(item)); item.DataItem = null; } dataItemIndex++; itemIndex++; } if (insertPosition == InsertItemPosition.LastItem) { if (_itemSeparatorTemplate != null) { ListViewContainer itemSeparatorContainer = new ListViewContainer(); AutoIDControl(itemSeparatorContainer); InstantiateItemSeparatorTemplate(itemSeparatorContainer); AddControlToContainer(itemSeparatorContainer, _noGroupsItemPlaceholderContainer, itemInsertLocation); itemInsertLocation++; } ListViewItem insertItem = CreateInsertItem(); AddControlToContainer(insertItem, _noGroupsItemPlaceholderContainer, itemInsertLocation); insertItem.DataBind(); itemInsertLocation++; itemIndex++; } _noGroupsItemCreatedCount = itemInsertLocation - _noGroupsOriginalIndexOfItemPlaceholderInContainer; return items; }
/// <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; }
public sealed override void DataBind () { cachedKeyProperties = null; base.DataBind (); if (dataItem != null) { if (CurrentMode == DetailsViewMode.Edit) oldEditValues = new DataKey (GetRowValues (false, true)); FillRowDataKey (dataItem); key = new DataKey (KeyTable); } }
public void ControlParameter_EvaluateComplex () { ControlParameterPoker ctrlParam = new ControlParameterPoker ("Test", "TestControl1", "Values['one']"); Page page = new Page (); OrderedDictionary dict = new OrderedDictionary (); dict.Add ("one", "1"); DataKey values = new DataKey (dict); TestControl test = new TestControl (values); test.ID = "TestControl1"; page.Controls.Add (test); string value = ctrlParam.DoEvaluate (HttpContext.Current, test) as string; Assert.AreEqual ("1", value, "#1"); }
public TestControl (DataKey values) { this._values = values; }
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; }
private void SetPersistedDataKey(int dataItemIndex, DataKey currentKey) { if (this._persistedDataKey == null) { if (this._selectedIndex == dataItemIndex) { this._persistedDataKey = currentKey; } } else if (this._persistedDataKey.Equals(currentKey)) { this._selectedIndex = dataItemIndex; } }
protected internal override void LoadControlState(object savedState) { this._editIndex = -1; this._pageIndex = 0; this._selectedIndex = -1; this._sortExpression = string.Empty; this._sortDirection = System.Web.UI.WebControls.SortDirection.Ascending; this._dataKeyNames = new string[0]; this._pageCount = -1; object[] objArray = savedState as object[]; if (objArray != null) { base.LoadControlState(objArray[0]); if (objArray[1] != null) { this._editIndex = (int) objArray[1]; } if (objArray[2] != null) { this._pageIndex = (int) objArray[2]; } if (objArray[3] != null) { this._selectedIndex = (int) objArray[3]; } if (objArray[4] != null) { this._sortExpression = (string) objArray[4]; } if (objArray[5] != null) { this._sortDirection = (System.Web.UI.WebControls.SortDirection) objArray[5]; } if (objArray[6] != null) { this._dataKeyNames = (string[]) objArray[6]; } if (objArray[7] != null) { this.LoadDataKeysState(objArray[7]); } if (objArray[8] != null) { this._pageCount = (int) objArray[8]; } if (((objArray[9] != null) && (this._dataKeyNames != null)) && (this._dataKeyNames.Length > 0)) { this._persistedDataKey = new DataKey(new OrderedDictionary(this._dataKeyNames.Length), this._dataKeyNames); ((IStateManager) this._persistedDataKey).LoadViewState(objArray[9]); } if (objArray[10] != null) { this._clientIDRowSuffix = (string[]) objArray[10]; } if (objArray[11] != null) { this.LoadClientIDRowSuffixDataKeysState(objArray[11]); } } else { base.LoadControlState(null); } }
private bool unbindObjectFromPage() { targetObject.Title = tbTitle.Text; targetObject.Prefix = tbPrefix.Text; targetObject.FirstName = tbFirstName.Text; targetObject.MiddleName = tbMiddleName.Text; targetObject.LastName = tbLastName.Text; targetObject.Nickname = tbNickName.Text; targetObject.Suffix = tbSuffix.Text; //unbind the image if applicable if (imageUpload.HasFile) { targetObject["Image_Contents"] = getImageFile(); //Set the session variable forcing any cached images to be refreshed from the MemberSuite Image content server SessionManager.Set("ImageUrlUpper", !SessionManager.Get <bool>("ImageUrlUpper")); } // now, the email targetObject.EmailAddress = tbEmail.Text; targetObject.EmailAddress2 = tbEmail2.Text; targetObject.EmailAddress3 = tbEmail3.Text; // now, the phone numbers foreach (GridViewRow grvPhoneNumberType in gvPhoneNumbers.Rows) { DataKey dataKey = gvPhoneNumbers.DataKeys[grvPhoneNumberType.RowIndex]; if (dataKey == null) { continue; } var code = dataKey.Value; TextBox tb = grvPhoneNumberType.FindControl("tbPhoneNumber") as TextBox; if (tb == null) { continue; } targetObject[code + "_PhoneNumber"] = tb.Text; } //if (!atLeastOnePhoneNumber) //{ // cvPhoneNumber.IsValid = false; // return false; //} // the preferred string preferredPhoneNumberID = Request.Form["PhoneNumberPreferredType"]; if (preferredPhoneNumberID != null) { targetObject.PreferredPhoneNumberType = preferredPhoneNumberID; } // now, let's unbind the addresses foreach (RepeaterItem riAddress in rptAddresses.Items) { AddressControl ac = (AddressControl)riAddress.FindControl("acAddress"); HiddenField hfAddressCode = (HiddenField)riAddress.FindControl("hfAddressCode"); if (ac == null || hfAddressCode == null) { continue; // defensive programmer } string code = hfAddressCode.Value; // remember we stuck the code in there during databinding targetObject[code + "_Address"] = ac.Address; } //if (!atLeastOneAddress) //{ // cvAddress.IsValid = false; // return false; //} // let's get the preferred address targetObject.PreferredAddressType = ddlPreferredAddress.SelectedValue; // and, the seasonal settings if (rbSeasonalNo.Checked) { targetObject.SeasonalAddressStart = null; targetObject.SeasonalAddressEnd = null; } else { targetObject.SeasonalAddressStart = mdpSeasonalStart.Date; targetObject.SeasonalAddressEnd = mdpSeasonalEnd.Date; } //Communication Preferences targetObject.DoNotEmail = chkDoNotEmail.Checked; targetObject.DoNotFax = chkDoNotFax.Checked; targetObject.DoNotMail = chkDoNotMail.Checked; targetObject.CommunicationsLastVerified = DateTime.UtcNow; targetObject.CommunicationsLastVerifiedFrom = Utils.GetIP(); //Unbind selected opt out message categories targetObject.OptOuts = (from category in dlbMessageCategories.Destination.Items select category.Value).ToList(); // finally, the custom fields CustomFieldSet1.Harvest(); return(true); }
void EndRowEdit () { EditIndex = -1; oldEditValues = new DataKey (new OrderedDictionary ()); currentEditRowKeys = null; currentEditOldValues = null; currentEditNewValues = null; }
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; }
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); }
/// <devdoc> /// <para>Loads the control state for those properties that should persist across postbacks /// even when EnableViewState=false.</para> /// </devdoc> protected internal override void LoadControlState(object savedState) { // Any properties that could have been set in the persistance need to be // restored to their defaults if they're not in ControlState, or they will // be restored to their persisted state instead of their empty state. _editIndex = -1; _pageIndex = 0; _selectedIndex = -1; _sortExpression = String.Empty; _sortDirection = SortDirection.Ascending; _dataKeyNames = new string[0]; _pageCount = -1; object[] state = savedState as object[]; if (state != null) { base.LoadControlState(state[0]); if (state[1] != null) { _editIndex = (int)state[1]; } if (state[2] != null) { _pageIndex = (int)state[2]; } if (state[3] != null) { _selectedIndex = (int)state[3]; } if (state[4] != null) { _sortExpression = (string)state[4]; } if (state[5] != null) { _sortDirection = (SortDirection)state[5]; } if (state[6] != null) { _dataKeyNames = (string[])state[6]; } if (state[7] != null) { LoadDataKeysState(state[7]); } if (state[8] != null) { _pageCount = (int)state[8]; } if (state[9] != null) { if ((_dataKeyNames != null) && (_dataKeyNames.Length > 0)) { _persistedDataKey = new DataKey(new OrderedDictionary(_dataKeyNames.Length), _dataKeyNames); ((IStateManager)_persistedDataKey).LoadViewState(state[9]); } } if (state[10] != null) { _clientIDRowSuffix = (string[])state[10]; } if (state[11] != null) { LoadClientIDRowSuffixDataKeysState(state[11]); } } else { base.LoadControlState(null); } }
/// <summary> /// encodes the url parts of the primary key thet shall be (after redirect) assigned to a newly created Panel; /// the PK parts are saved into the query string as PK0=...,PK1=..., . . ., this is a convention shared with the the decoder /// (Show.SetRoutedPKForPanel). /// </summary> /// <param name="key"></param> /// <returns></returns> private string DataKey2Url(DataKey key) { // the PK pats could not be appended route to form a /-separated string - ASP.NET doesn`t allow special characters before the '?' mark in the URL. var parts = from object p in key.Values.Values select p.ToString(); List<string> lParts = new List<string>(); StringBuilder sb = new StringBuilder("?"); bool first = true; int i = 0; foreach (string s in parts){ if(!first) sb.Append("&"); first = false; sb.Append("IKP" + i.ToString() + "=" + HttpUtility.UrlEncode(s)); i++; } return sb.ToString(); }
private void SetPersistedDataKey(int dataItemIndex, DataKey currentKey) { if (_persistedDataKey == null) { // If there is no persisted DataKey then set it to the DataKey at the // the selected index if (_selectedIndex == dataItemIndex) { _persistedDataKey = currentKey; } } else if (_persistedDataKey.Equals(currentKey)) { // Persist the selection by picking the selected index where DataKeys match _selectedIndex = dataItemIndex; } }
// -- // -- private string GetKey(DataKey key) { string res = ""; for (int i = 0; i < key.Values.Count; i++) { if (i > 0) { res += "|"; } res += key.Values[i].ToString(); } return res; }
protected virtual void CreateSuffixArrayList(ListViewPagedDataSource dataSource, ArrayList suffixArray) { int dataItemIndex = 0; foreach (object o in dataSource) { OrderedDictionary suffixTable = new OrderedDictionary(ClientIDRowSuffixInternal.Length); foreach (string suffixName in ClientIDRowSuffixInternal) { object suffixValue = DataBinder.GetPropertyValue(o, suffixName); suffixTable.Add(suffixName, suffixValue); } if (suffixArray.Count == dataItemIndex) { suffixArray.Add(new DataKey(suffixTable, ClientIDRowSuffixInternal)); } else { suffixArray[dataItemIndex] = new DataKey(suffixTable, ClientIDRowSuffixInternal); } dataItemIndex++; } }
public sealed override void DataBind () { cachedKeyProperties = null; base.DataBind (); if (pageCount > 0) { if (CurrentMode == FormViewMode.Edit) oldEditValues = new DataKey (GetRowValues (true)); FillRowDataKey (dataItem); key = new DataKey (KeyTable); } }
/// <devdoc> /// <para>Creates the control hierarchy that is used to render the DetailsView. /// 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; int itemIndex = PageIndex; bool allowPaging = AllowPaging; int itemCount = 0; DetailsViewMode mode = Mode; // if we're in design mode, PageIndex doesn't return -1 if (DesignMode && mode == DetailsViewMode.Insert) { itemIndex = -1; } if (dataBinding) { DataSourceView view = GetData(); DataSourceSelectArguments arguments = SelectArguments; if (view == null) { throw new HttpException(SR.GetString(SR.DataBoundControl_NullView, ID)); } if (mode != DetailsViewMode.Insert) { if (allowPaging && !view.CanPage) { if (dataSource != null && !(dataSource is ICollection)) { arguments.StartRowIndex = itemIndex; arguments.MaximumRows = 1; // 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)); } pagedDataSource = CreateServerPagedDataSource(checked(PageIndex + dataSourceCollection.Count)); } } else { pagedDataSource = CreatePagedDataSource(); } } } else { pagedDataSource = CreatePagedDataSource(); } if (mode != DetailsViewMode.Insert) { pagedDataSource.DataSource = dataSource; } IEnumerator dataSourceEnumerator = null; OrderedDictionary keyTable = KeyTable; _rowsArray = new ArrayList(); _rowsCollection = null; if (dataBinding == false) { dataSourceEnumerator = dataSource.GetEnumerator(); ICollection collection = dataSource as ICollection; if (collection == null) { throw new HttpException(SR.GetString(SR.DataControls_DataSourceMustBeCollectionWhenNotDataBinding)); } itemCount = collection.Count; } else { keyTable.Clear(); if (dataSource != null) { if (mode != DetailsViewMode.Insert) { ICollection collection = dataSource as ICollection; if ((collection == null) && (pagedDataSource.IsPagingEnabled && !pagedDataSource.IsServerPagingEnabled)) { throw new HttpException(SR.GetString(SR.DetailsView_DataSourceMustBeCollection, ID)); } if (pagedDataSource.IsPagingEnabled) { itemCount = pagedDataSource.DataSourceCount; } else if (collection != null) { itemCount = collection.Count; } } dataSourceEnumerator = dataSource.GetEnumerator(); } } Table table = CreateTable(); TableRowCollection rows = table.Rows; bool moveNextSucceeded = false; object lastItem = null; Controls.Add(table); if (dataSourceEnumerator != null) { moveNextSucceeded = dataSourceEnumerator.MoveNext(); // goto the first item } // if there are no items, only add the tablerow if there's a null template or null text if (!moveNextSucceeded && mode != DetailsViewMode.Insert) { // if we're in insert mode and we're not autogenerating rows, render the rows in insert mode if (itemIndex >= 0 || AutoGenerateRows) { if (EmptyDataText.Length > 0 || _emptyDataTemplate != null) { _rowsArray.Add(CreateRow(0, DataControlRowType.EmptyDataRow, DataControlRowState.Normal, null, rows, null)); } itemCount = 0; } } else { int currentItemIndex = 0; if (!_useServerPaging) { // skip over the first records that are before the page we're showing for (; currentItemIndex < itemIndex; currentItemIndex++) { lastItem = dataSourceEnumerator.Current; moveNextSucceeded = dataSourceEnumerator.MoveNext(); if (!moveNextSucceeded) { _pageIndex = currentItemIndex; pagedDataSource.CurrentPageIndex = currentItemIndex; itemIndex = currentItemIndex; break; // never throw if the PageIndex is out of range: just fix up the current page and goto the last item. } } } if (moveNextSucceeded) { _dataItem = dataSourceEnumerator.Current; } else { _dataItem = lastItem; // if we broke out of the above loop, the current item will be invalid } // If we're not using server paging and this isn't a collection, or server paging doesn't return a page count, our _pageCount isn't accurate. // Loop through the rest of the enumeration to figure out how many items are in it. if ((!_useServerPaging && !(dataSource is ICollection)) || (_useServerPaging && itemCount < 0)) { itemCount = currentItemIndex; while (moveNextSucceeded) { itemCount++; moveNextSucceeded = dataSourceEnumerator.MoveNext(); } } _dataItemIndex = currentItemIndex; bool singlePage = itemCount <= 1 && !_useServerPaging; // hide pagers if there's only one item if (allowPaging && PagerSettings.Visible && _pagerSettings.IsPagerOnTop && !singlePage && mode != DetailsViewMode.Insert) { // top pager _topPagerRow = CreateRow(-1, DataControlRowType.Pager, DataControlRowState.Normal, null, rows, pagedDataSource); } _headerRow = CreateRow(-1, DataControlRowType.Header, DataControlRowState.Normal, null, rows, null); if (_headerTemplate == null && HeaderText.Length == 0) { _headerRow.Visible = false; } _rowsArray.AddRange(CreateDataRows(dataBinding, rows, _dataItem)); if (itemIndex >= 0) { string[] keyFields = DataKeyNamesInternal; if (dataBinding && (keyFields.Length != 0)) { foreach (string keyName in keyFields) { object keyValue = DataBinder.GetPropertyValue(_dataItem, keyName); keyTable.Add(keyName, keyValue); } _dataKey = new DataKey(keyTable); } } _footerRow = CreateRow(-1, DataControlRowType.Footer, DataControlRowState.Normal, null, rows, null); if (_footerTemplate == null && FooterText.Length == 0) { _footerRow.Visible = false; } if (allowPaging && PagerSettings.Visible && _pagerSettings.IsPagerOnBottom && !singlePage && mode != DetailsViewMode.Insert) { // bottom pager _bottomPagerRow = CreateRow(-1, DataControlRowType.Pager, DataControlRowState.Normal, null, rows, pagedDataSource); } } _pageCount = itemCount; OnItemCreated(EventArgs.Empty); if (dataBinding) { DataBind(false); } return itemCount; }
void EndRowEdit (bool switchToDefaultMode, bool cancelingEdit) { if (switchToDefaultMode) ProcessChangeMode (DefaultMode, cancelingEdit); oldEditValues = new DataKey (new OrderedDictionary ()); currentEditRowKeys = null; currentEditOldValues = null; currentEditNewValues = null; RequireBinding (); }
public void CopyTo(DataKey[] array, int index) { }
public sealed override void DataBind () { DataSourceView view = GetData (); if (AllowPaging && view.CanPage) { SelectArguments.StartRowIndex = PageIndex; SelectArguments.MaximumRows = 1; if (view.CanRetrieveTotalRowCount) SelectArguments.RetrieveTotalRowCount = true; } cachedKeyProperties = null; base.DataBind (); if (dataItem != null) { if (CurrentMode == DetailsViewMode.Edit) oldEditValues = new DataKey (GetRowValues (false, true)); key = new DataKey (CreateRowDataKey (dataItem), DataKeyNames); } }
public void CopyTo (DataKey[] array, int index) { foreach (DataKey current in this) array [index++] = current; }
void EndRowEdit () { ChangeMode (DefaultMode); oldEditValues = new DataKey (new OrderedDictionary ()); currentEditRowKeys = null; currentEditOldValues = null; currentEditNewValues = null; RequireBinding (); }
protected override int CreateChildControls (IEnumerable data, bool dataBinding) { // clear GridView Controls.Clear (); table = null; rows = null; if (data == null) { return 0; } PagedDataSource dataSource; if (dataBinding) { DataSourceView view = GetData (); dataSource = new PagedDataSource (); dataSource.DataSource = data; if (AllowPaging) { dataSource.AllowPaging = true; dataSource.PageSize = PageSize; if (view.CanPage) { dataSource.AllowServerPaging = true; if (SelectArguments.RetrieveTotalRowCount) dataSource.VirtualCount = SelectArguments.TotalRowCount; } if (PageIndex >= dataSource.PageCount) pageIndex = dataSource.PageCount - 1; dataSource.CurrentPageIndex = PageIndex; } PageCount = dataSource.PageCount; } else { dataSource = new PagedDataSource (); dataSource.DataSource = data; if (AllowPaging) { dataSource.AllowPaging = true; dataSource.PageSize = PageSize; dataSource.CurrentPageIndex = PageIndex; } } bool createPager = AllowPaging && (PageCount >= 1) && PagerSettings.Visible; ArrayList list = new ArrayList (); // Creates the set of fields to show _dataEnumerator = null; ICollection fieldCollection = CreateColumns (dataSource, dataBinding); int fieldCount = fieldCollection.Count; DataControlField dcf; DataControlField[] fields = new DataControlField [fieldCount]; fieldCollection.CopyTo (fields, 0); for (int i = 0; i < fieldCount; i++) { dcf = fields [i]; dcf.Initialize (AllowSorting, this); if (EnableSortingAndPagingCallbacks) dcf.ValidateSupportsCallback (); } bool skip_first = false; IEnumerator enumerator; if (_dataEnumerator != null) { // replaced when creating bound columns enumerator = _dataEnumerator; skip_first = true; } else { enumerator = dataSource.GetEnumerator (); } // Main table creation while (skip_first || enumerator.MoveNext ()) { skip_first = false; object obj = enumerator.Current; if (list.Count == 0) { if (createPager && (PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom)) { topPagerRow = CreatePagerRow (fieldCount, dataSource); OnRowCreated (new GridViewRowEventArgs (topPagerRow)); ContainedTable.Rows.Add (topPagerRow); if (dataBinding) { topPagerRow.DataBind (); OnRowDataBound (new GridViewRowEventArgs (topPagerRow)); } if (PageCount == 1) topPagerRow.Visible = false; } GridViewRow headerRow = CreateRow (-1, -1, DataControlRowType.Header, DataControlRowState.Normal); InitializeRow (headerRow, fields); OnRowCreated (new GridViewRowEventArgs (headerRow)); ContainedTable.Rows.Add (headerRow); if (dataBinding) { headerRow.DataBind (); OnRowDataBound (new GridViewRowEventArgs (headerRow)); } } DataControlRowState rstate = GetRowState (list.Count); GridViewRow row = CreateRow (list.Count, list.Count, DataControlRowType.DataRow, rstate); row.DataItem = obj; list.Add (row); InitializeRow (row, fields); OnRowCreated (new GridViewRowEventArgs (row)); ContainedTable.Rows.Add (row); if (dataBinding) { row.DataBind (); if (EditIndex == row.RowIndex) oldEditValues = new DataKey (GetRowValues (row, true, true)); DataKeyArrayList.Add (new DataKey (CreateRowDataKey (row), DataKeyNames)); OnRowDataBound (new GridViewRowEventArgs (row)); } } if (list.Count == 0) { GridViewRow emptyRow = CreateEmptyrRow (fieldCount); if (emptyRow != null) { OnRowCreated (new GridViewRowEventArgs (emptyRow)); ContainedTable.Rows.Add (emptyRow); if (dataBinding) { emptyRow.DataBind (); OnRowDataBound (new GridViewRowEventArgs (emptyRow)); } } return 0; } else { GridViewRow footerRow = CreateRow (-1, -1, DataControlRowType.Footer, DataControlRowState.Normal); InitializeRow (footerRow, fields); OnRowCreated (new GridViewRowEventArgs (footerRow)); ContainedTable.Rows.Add (footerRow); if (dataBinding) { footerRow.DataBind (); OnRowDataBound (new GridViewRowEventArgs (footerRow)); } if (createPager && (PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom)) { bottomPagerRow = CreatePagerRow (fieldCount, dataSource); OnRowCreated (new GridViewRowEventArgs (bottomPagerRow)); ContainedTable.Rows.Add (bottomPagerRow); if (dataBinding) { bottomPagerRow.DataBind (); OnRowDataBound (new GridViewRowEventArgs (bottomPagerRow)); } if (PageCount == 1) bottomPagerRow.Visible = false; } } rows = new GridViewRowCollection (list); if (!dataBinding) return -1; if (AllowPaging) return dataSource.DataSourceCount; else return list.Count; }
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 = 1; 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 = 1; dataSource.CurrentPageIndex = PageIndex; } } bool showPager = AllowPaging && (PageCount > 1); Controls.Clear (); table = CreateTable (); Controls.Add (table); ArrayList list = new ArrayList (); if (!Page.IsPostBack) currentMode = DefaultMode; // Gets the current data item IEnumerator e = dataSource.GetEnumerator (); if (e.MoveNext ()) dataItem = e.Current; else dataItem = null; // Creates the set of fields to show ICollection fieldCollection = CreateFieldSet (dataItem, dataBinding); DataControlField[] fields = new DataControlField [fieldCollection.Count]; fieldCollection.CopyTo (fields, 0); foreach (DataControlField field in fields) { field.Initialize (false, this); if (EnablePagingCallbacks) field.ValidateSupportsCallback (); } // Main table creation if (HeaderText.Length != 0 || headerTemplate != null) { headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal); DataControlFieldCell cell = new DataControlFieldCell (null); cell.ColumnSpan = 2; if (headerTemplate != null) headerTemplate.InstantiateIn (cell); else cell.Text = HeaderText; headerRow.Cells.Add (cell); table.Rows.Add (headerRow); } if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) { topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (topPagerRow, dataSource); table.Rows.Add (topPagerRow); } if (dataSource.Count > 0) { foreach (DataControlField field in fields) { DataControlRowState rstate = GetRowState (list.Count); DetailsViewRow row = CreateRow (list.Count, DataControlRowType.DataRow, rstate); InitializeRow (row, field); table.Rows.Add (row); list.Add (row); if (commandField == field) commandRow = row; } if (!dataBinding) { if (CurrentMode == DetailsViewMode.Edit) oldEditValues = new DataKey (new OrderedDictionary ()); key = new DataKey (new OrderedDictionary (), DataKeyNames); } } else { table.Rows.Add (CreateEmptyrRow ()); } rows = new DetailsViewRowCollection (list); if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) { bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (bottomPagerRow, dataSource); table.Rows.Add (bottomPagerRow); } if (FooterText.Length != 0 || footerTemplate != null) { footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal); DataControlFieldCell cell = new DataControlFieldCell (null); cell.ColumnSpan = 2; if (footerTemplate != null) footerTemplate.InstantiateIn (cell); else cell.Text = FooterText; footerRow.Cells.Add (cell); table.Rows.Add (footerRow); } if (dataBinding) DataBind (false); return dataSource.DataSourceCount; }
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); }
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 = 1; 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 = 1; dataSource.CurrentPageIndex = PageIndex; } } bool showPager = AllowPaging && (PageCount > 1); dataSourceCount = dataSource.Count; Controls.Clear (); table = CreateTable (); Controls.Add (table); if (!Page.IsPostBack) currentMode = DefaultMode; // Gets the current data item IEnumerator e = dataSource.GetEnumerator (); if (e.MoveNext ()) dataItem = e.Current; else dataItem = null; // Main table creation if (HeaderText.Length != 0 || headerTemplate != null) { headerRow = CreateRow (-1, DataControlRowType.Header, DataControlRowState.Normal); InitializeRow (headerRow); table.Rows.Add (headerRow); } if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) { topPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (topPagerRow, dataSource); table.Rows.Add (topPagerRow); } if (dataSourceCount > 0) { DataControlRowState rstate = GetRowState (); itemRow = CreateRow (0, DataControlRowType.DataRow, rstate); InitializeRow (itemRow); table.Rows.Add (itemRow); if (!dataBinding) { if (CurrentMode == FormViewMode.Edit) oldEditValues = new DataKey (new OrderedDictionary ()); key = new DataKey (new OrderedDictionary (), DataKeyNames); } } else { itemRow = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal); table.Rows.Add (itemRow); InitializeRow (itemRow); } if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) { bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal); InitializePager (bottomPagerRow, dataSource); table.Rows.Add (bottomPagerRow); } if (FooterText.Length != 0 || footerTemplate != null) { footerRow = CreateRow (-1, DataControlRowType.Footer, DataControlRowState.Normal); InitializeRow (footerRow); table.Rows.Add (footerRow); } if (dataBinding) DataBind (false); return dataSource.DataSourceCount; }