TableItemStyle pagerStyle;
TableItemStyle rowStyle;
TableItemStyle selectedRowStyle;
+ ArrayList _dataKeyArrayList;
DataKeyArray keys;
DataKey oldEditValues;
AutoGeneratedFieldProperties[] autoFieldProperties;
// Control state
int pageIndex;
- int pageCount;
int selectedIndex = -1;
int editIndex = -1;
SortDirection sortDirection = SortDirection.Ascending;
RequireBinding ();
}
}
+
+ ArrayList DataKeyArrayList {
+ get {
+ if (_dataKeyArrayList == null) {
+ _dataKeyArrayList = new ArrayList ();
+ }
+ return _dataKeyArrayList;
+ }
+ }
[BrowsableAttribute (false)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
public virtual DataKeyArray DataKeys {
get {
- EnsureDataBound ();
+ if (keys == null) {
+ keys = new DataKeyArray (DataKeyArrayList);
+ if (IsTrackingViewState)
+ ((IStateManager) keys).TrackViewState ();
+ }
return keys;
}
}
+ DataKey OldEditValues {
+ get {
+ if (oldEditValues == null) {
+ oldEditValues = new DataKey (new OrderedDictionary ());
+ }
+ return oldEditValues;
+ }
+ }
+
[WebCategoryAttribute ("Misc")]
[DefaultValueAttribute (-1)]
public virtual int EditIndex {
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
public virtual int PageCount {
get {
- if (pageCount != 0) return pageCount;
- EnsureDataBound ();
- return pageCount;
+ return ViewState.GetInt ("PageCount", 0);
+ }
+ private set {
+ ViewState ["PageCount"] = value;
}
}
[BrowsableAttribute (false)]
public virtual GridViewRowCollection Rows {
get {
- EnsureDataBound ();
+ EnsureChildControls ();
+ if (rows == null)
+ rows = new GridViewRowCollection (new ArrayList ());
return rows;
}
}
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
public virtual DataKey SelectedDataKey {
get {
- if (DataKeys == null)
+ if (keys == null)
throw new InvalidOperationException ("DataKeys");
if (selectedIndex >= 0 && selectedIndex < DataKeys.Count) {
protected virtual GridViewRow CreateRow (int rowIndex, int dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState)
{
GridViewRow row = new GridViewRow (rowIndex, dataSourceIndex, rowType, rowState);
- OnRowCreated (new GridViewRowEventArgs (row));
return row;
}
{
if (Initialized) {
RequiresDataBinding = true;
- pageCount = -1;
}
}
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) {
dataSource.CurrentPageIndex = PageIndex;
if (view.CanPage) {
dataSource.AllowServerPaging = true;
- if (view.CanRetrieveTotalRowCount)
+ if (SelectArguments.RetrieveTotalRowCount)
dataSource.VirtualCount = SelectArguments.TotalRowCount;
}
}
- pageCount = dataSource.PageCount;
+ PageCount = dataSource.PageCount;
}
else
{
}
}
+ if (dataSource.DataSourceCount == 0)
+ return 0;
+
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
if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
topPagerRow = CreatePagerRow (fields.Length, dataSource);
table.Rows.Add (topPagerRow);
+ OnRowCreated (new GridViewRowEventArgs (topPagerRow));
}
GridViewRow headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
table.Rows.Add (headerRow);
InitializeRow (headerRow, fields);
+ OnRowCreated (new GridViewRowEventArgs (headerRow));
+ if (dataBinding) {
+ headerRow.DataBind ();
+ OnRowDataBound (new GridViewRowEventArgs (headerRow));
+ }
foreach (object obj in dataSource) {
DataControlRowState rstate = GetRowState (list.Count);
list.Add (row);
table.Rows.Add (row);
InitializeRow (row, fields);
+ OnRowCreated (new GridViewRowEventArgs (row));
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));
- }
+ DataKeyArrayList.Add (new DataKey (CreateRowDataKey (row), DataKeyNames));
+ }
if (list.Count >= PageSize)
break;
}
-
- if (list.Count == 0)
- table.Rows.Add (CreateEmptyrRow (fields.Length));
+
+ if (list.Count == 0) {
+ GridViewRow emptyRow = CreateEmptyrRow (fields.Length);
+ table.Rows.Add (emptyRow);
+ OnRowCreated (new GridViewRowEventArgs (emptyRow));
+ if (dataBinding) {
+ emptyRow.DataBind ();
+ OnRowDataBound (new GridViewRowEventArgs (emptyRow));
+ }
+ }
GridViewRow footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
table.Rows.Add (footerRow);
InitializeRow (footerRow, fields);
+ OnRowCreated (new GridViewRowEventArgs (footerRow));
+ if (dataBinding) {
+ footerRow.DataBind ();
+ OnRowDataBound (new GridViewRowEventArgs (footerRow));
+ }
if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
table.Rows.Add (bottomPagerRow);
+ OnRowCreated (new GridViewRowEventArgs (bottomPagerRow));
}
rows = new GridViewRowCollection (list);
- keys = new DataKeyArray (keyList);
return dataSource.DataSourceCount;
}
public sealed override void DataBind ()
{
+ DataKeyArrayList.Clear ();
cachedKeyProperties = null;
base.DataBind ();
+
+ keys = new DataKeyArray (DataKeyArrayList);
}
protected internal override void PerformDataBinding (IEnumerable data)
param = row.RowIndex.ToString();
}
ProcessEvent (args.CommandName, param);
+ return true;
}
return base.OnBubbleEvent (source, e);
}
newIndex = PageCount - 1;
break;
case DataControlCommands.NextPageCommandArgument:
- if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
+ newIndex = PageIndex + 1;
break;
case DataControlCommands.PreviousPageCommandArgument:
- if (PageIndex > 0) newIndex = PageIndex - 1;
+ newIndex = PageIndex - 1;
break;
default:
- newIndex = int.Parse (param) - 1;
+ int paramIndex = 0;
+ int.TryParse (param, out paramIndex);
+ newIndex = paramIndex - 1;
break;
}
ShowPage (newIndex);
[MonoTODO ("Support two-way binding expressions")]
public virtual void UpdateRow (int rowIndex, bool causesValidation)
{
- if (causesValidation)
+ if (causesValidation && Page != null)
Page.Validate ();
if (rowIndex != EditIndex) throw new NotSupportedException ();
-
- currentEditOldValues = oldEditValues.Values;
+
+ currentEditOldValues = OldEditValues.Values;
GridViewRow row = Rows [rowIndex];
currentEditRowKeys = DataKeys [rowIndex].Values;
OnRowUpdating (args);
if (!args.Cancel) {
DataSourceView view = GetData ();
- if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
- view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
+ if (view == null)
+ throw new HttpException ("The DataSourceView associated to data bound control was null");
+ if(view.CanUpdate)
+ view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
} else
EndRowEdit ();
}
if (!args.Cancel) {
RequireBinding ();
DataSourceView view = GetData ();
- if (view != null)
+ if (view != null && view.CanDelete)
view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
else {
GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
object[] state = (object[]) ob;
base.LoadControlState (state[0]);
pageIndex = (int) state[1];
- pageCount = (int) state[2];
- selectedIndex = (int) state[3];
- editIndex = (int) state[4];
- sortExpression = (string) state[5];
- sortDirection = (SortDirection) state[6];
- DataKeyNames = (string []) state [7];
+ selectedIndex = (int) state[2];
+ editIndex = (int) state[3];
+ sortExpression = (string) state[4];
+ sortDirection = (SortDirection) state[5];
+ DataKeyNames = (string []) state [6];
+ if (state [7] != null)
+ LoadDataKeyArrayState ((object []) state [7]);
+ if (state [8] != null)
+ ((IStateManager) OldEditValues).LoadViewState (state [8]);
}
protected internal override object SaveControlState ()
}
object bstate = base.SaveControlState ();
- return new object[] {
- bstate, pageIndex, pageCount, selectedIndex, editIndex, sortExpression, sortDirection, DataKeyNames
+ return new object [] {
+ bstate,
+ pageIndex,
+ selectedIndex,
+ editIndex,
+ sortExpression,
+ sortDirection,
+ DataKeyNames,
+ SaveDataKeyArrayState (),
+ (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState ())
};
}
-
+
+ object [] SaveDataKeyArrayState ()
+ {
+ 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;
+ }
+
+ 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 void TrackViewState()
{
base.TrackViewState();
protected override object SaveViewState()
{
- object[] states = new object [14];
+ object[] states = new object [12];
states[0] = base.SaveViewState();
states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
states[8] = (selectedRowStyle == null ? null : ((IStateManager)selectedRowStyle).SaveViewState());
states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
- states[11] = (keys == null ? null : ((IStateManager)keys).SaveViewState());
- states[12] = (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState());
if (autoFieldProperties != null) {
object[] data = new object [autoFieldProperties.Length];
data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
if (data [n] != null) allNull = false;
}
- if (!allNull) states [13] = data;
+ if (!allNull) states [11] = data;
}
for (int i = states.Length - 1; i >= 0; i--) {
object [] states = (object []) savedState;
- if (states[13] != null) {
- object[] data = (object[]) states [13];
+ if (states[11] != null) {
+ object[] data = (object[]) states [11];
autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
for (int n=0; n<data.Length; n++) {
IStateManager p = new AutoGeneratedFieldProperties ();
}
base.LoadViewState (states[0]);
- EnsureChildControls ();
if (states[1] != null) ((IStateManager)Columns).LoadViewState (states[1]);
if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
if (states[8] != null) ((IStateManager)SelectedRowStyle).LoadViewState (states[8]);
if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
- if (states[11] != null) ((IStateManager)DataKeys).LoadViewState (states[11]);
- if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
}
void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)