int pageCount = 0;
public FormView ()
- {\r
- key = new DataKey (new OrderedDictionary ());\r
+ {
+ key = new DataKey (new OrderedDictionary ());
}
public event EventHandler PageIndexChanged {
if (o != null) return (int) o;
return -1;
}
- set {\r
- if (value < -1)\r
- throw new ArgumentOutOfRangeException ("< -1");\r
+ set {
+ if (value < -1)
+ throw new ArgumentOutOfRangeException ("< -1");
ViewState ["CellPadding"] = value;
RequireBinding ();
}
if (o != null) return (int) o;
return 0;
}
- set {\r
- if (value < -1)\r
- throw new ArgumentOutOfRangeException ("< -1");\r
+ set {
+ if (value < -1)
+ throw new ArgumentOutOfRangeException ("< -1");
ViewState["CellSpacing"] = value;
RequireBinding ();
}
return currentMode;
}
}
-
+
+ FormViewMode defaultMode;
+
[DefaultValueAttribute (FormViewMode.ReadOnly)]
[WebCategoryAttribute ("Behavior")]
public virtual FormViewMode DefaultMode {
get {
- object o = ViewState ["DefaultMode"];
- if (o != null) return (FormViewMode) o;
- return FormViewMode.ReadOnly;
+ return defaultMode;
}
set {
- ViewState ["DefaultMode"] = value;
+ defaultMode = value;
RequireBinding ();
}
}
-
+
+ string[] dataKeyNames;
[DefaultValueAttribute (null)]
[WebCategoryAttribute ("Data")]
[TypeConverter (typeof(StringArrayConverter))]
public virtual string[] DataKeyNames
{
get {
- object o = ViewState ["DataKeyNames"];
- if (o != null) return (string[]) o;
- return emptyKeys;
+ if (dataKeyNames == null)
+ return emptyKeys;
+ return dataKeyNames;
}
set {
- ViewState ["DataKeyNames"] = value;
+ dataKeyNames = value;
RequireBinding ();
}
}
[DefaultValueAttribute (GridLines.None)]
public virtual GridLines GridLines {
get {
- object ob = ViewState ["GridLines"];
- if (ob != null) return (GridLines) ob;
- return GridLines.None;
+ return ((TableStyle) ControlStyle).GridLines;
}
set {
- ViewState ["GridLines"] = value;
+ ((TableStyle) ControlStyle).GridLines = value;
}
}
[BrowsableAttribute (false)]
public virtual int DataItemIndex {
get { return PageIndex; }
- }
+ }
+
+ int IDataItemContainer.DataItemIndex {
+ get { return DataItemIndex; }
+ }
int IDataItemContainer.DisplayIndex {
get { return PageIndex; }
}
public virtual bool IsBindableType (Type type)
- {\r
- return type.IsPrimitive || type == typeof (string) || type == typeof (DateTime) || type == typeof (Guid) || type == typeof (Decimal);\r
+ {
+ return type.IsPrimitive || type == typeof (string) || type == typeof (DateTime) || type == typeof (Guid) || type == typeof (Decimal);
}
protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
base.EnsureDataBound ();
}
- [MonoTODO]
protected override Style CreateControlStyle ()
{
- return base.CreateControlStyle ();
+ TableStyle style = new TableStyle (ViewState);
+ style.CellSpacing = 0;
+ return style;
}
protected override int CreateChildControls (IEnumerable data, bool dataBinding)
if (dataBinding) {
DataSourceView view = GetData ();
- if (view.CanPage) {
+ if (view != null && view.CanPage) {
dataSource.AllowServerPaging = true;
if (view.CanRetrieveTotalRowCount)
dataSource.VirtualCount = SelectArguments.TotalRowCount;
}
pageCount = dataSource.DataSourceCount;
- bool showPager = AllowPaging && (dataSource.Count > 1);
+ bool showPager = AllowPaging && (pageCount > 1);
Controls.Clear ();
table = CreateTable ();
} else {
switch (CurrentMode) {
case FormViewMode.Edit:
- itemRow = CreateRow (-1, DataControlRowType.DataRow, DataControlRowState.Edit);
+ itemRow = CreateRow (-1, DataControlRowType.EmptyDataRow, DataControlRowState.Edit);
break;
case FormViewMode.Insert:
itemRow = CreateRow (-1, DataControlRowType.DataRow, DataControlRowState.Insert);
}
if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
- bottomPagerRow = CreateRow (-1, DataControlRowType.Pager, DataControlRowState.Normal);
+ bottomPagerRow = CreateRow (0, DataControlRowType.Pager, DataControlRowState.Normal);
InitializePager (bottomPagerRow, dataSource);
table.Rows.Add (bottomPagerRow);
}
protected virtual void InitializePager (FormViewRow row, PagedDataSource dataSource)
{
TableCell cell = new TableCell ();
-
+ cell.ColumnSpan = 2;
+
if (pagerTemplate != null)
pagerTemplate.InstantiateIn (cell);
else
- cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount));
+ cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount, pagerStyle));
row.Cells.Add (cell);
}
else
cell.Text = HeaderText;
}
+ cell.ColumnSpan = 2;
row.Cells.Add (cell);
}
}
protected virtual void ExtractRowValues (IOrderedDictionary fieldValues, bool includeKeys)
- {\r
- if (Row == null)\r
+ {
+ if (Row == null)
return;
DataControlRowState rowState = Row.RowState;
public sealed override void DataBind ()
{
+ if (CurrentMode == FormViewMode.Insert) {
+ RequiresDataBinding = false;
+ PerformDataBinding (new object [] { null });
+ return;
+ }
+
DataSourceView view = GetData ();
if (AllowPaging && view.CanPage) {
SelectArguments.StartRowIndex = PageIndex;
if (pageCount > 0) {
if (CurrentMode == FormViewMode.Edit)
oldEditValues = new DataKey (GetRowValues (true));
+ else
+ oldEditValues = new DataKey (new OrderedDictionary ());
key = new DataKey (CreateRowDataKey (dataItem), DataKeyNames);
}
}
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);
newIndex = args.NewPageIndex;
if (newIndex < 0 || newIndex >= PageCount)
return;
- EndRowEdit ();
+ EndRowEdit (false);
PageIndex = newIndex;
OnPageIndexChanged (EventArgs.Empty);
}
OnItemUpdating (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));
- } else
+ 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 ();
}
OnItemInserting (args);
if (!args.Cancel) {
DataSourceView view = GetData ();
- if (view == null) throw new HttpException ("The DataSourceView associated to data bound control was null");
- view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
- } else
+ if (view == null)
+ throw new HttpException ("The DataSourceView associated to data bound control was null");
+ if (view.CanInsert)
+ view.Insert (currentEditNewValues, new DataSourceViewOperationCallback (InsertCallback));
+ }
+ else
EndRowEdit ();
}
RequireBinding ();
DataSourceView view = GetData ();
- if (view != null)
+ if (view != null && view.CanDelete)
view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
else {
FormViewDeletedEventArgs dargs = new FormViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
void EndRowEdit ()
{
- ChangeMode (DefaultMode);
+ EndRowEdit (true);
+ }
+
+ void EndRowEdit (bool switchToDefaultMode)
+ {
+ if (switchToDefaultMode)
+ ChangeMode (DefaultMode);
oldEditValues = new DataKey (new OrderedDictionary ());
currentEditRowKeys = null;
currentEditOldValues = null;
pageIndex = (int) state[1];
pageCount = (int) state[2];
currentMode = (FormViewMode) state[3];
+ defaultMode = (FormViewMode) state[4];
+ dataKeyNames = (string[]) state[5];
}
protected internal override object SaveControlState ()
{
object bstate = base.SaveControlState ();
return new object[] {
- bstate, pageIndex, pageCount, currentMode
- };
+ bstate, pageIndex, pageCount, currentMode, defaultMode, dataKeyNames
+ };
}
protected override void TrackViewState()
}
writer.AddAttribute (HtmlTextWriterAttribute.Cellspacing, "0");
- writer.AddStyleAttribute (HtmlTextWriterStyle.BorderCollapse, "collapse");
if (!string.IsNullOrEmpty (ControlStyle.CssClass))
writer.AddAttribute (HtmlTextWriterAttribute.Class, ControlStyle.CssClass);
+
+ table.ControlStyle.MergeWith (ControlStyle);
table.RenderBeginTag (writer);
foreach (FormViewRow row in table.Rows)