namespace System.Web.UI.WebControls
{
+ [SupportsEventValidation]
[DesignerAttribute ("System.Web.UI.Design.WebControls.GridViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
[ControlValuePropertyAttribute ("SelectedValue")]
[DefaultEventAttribute ("SelectedIndexChanged")]
[AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- public class GridView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer
+ public class GridView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer, IPostBackEventHandler, IPostBackContainer
{
Table table;
GridViewRowCollection rows;
- GridViewRow headerRow;
- GridViewRow footerRow;
GridViewRow bottomPagerRow;
GridViewRow topPagerRow;
[WebCategoryAttribute ("Paging")]
[DefaultValueAttribute (false)]
- public bool AllowPaging {
+ public virtual bool AllowPaging {
get {
object ob = ViewState ["AllowPaging"];
if (ob != null) return (bool) ob;
[WebCategoryAttribute ("Behavior")]
[DefaultValueAttribute (false)]
- public bool AllowSorting {
+ public virtual bool AllowSorting {
get {
object ob = ViewState ["AllowSorting"];
if (ob != null) return (bool) ob;
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle AlternatingRowStyle {
+ public TableItemStyle AlternatingRowStyle {
get {
if (alternatingRowStyle == null) {
alternatingRowStyle = new TableItemStyle ();
[WebCategoryAttribute ("Accessibility")]
[DefaultValueAttribute ("")]
[LocalizableAttribute (true)]
- public string Caption {
+ public virtual string Caption {
get {
object ob = ViewState ["Caption"];
if (ob != null) return (string) ob;
[WebCategoryAttribute ("Misc")]
[DefaultValueAttribute (-1)]
- public int EditIndex {
+ public virtual int EditIndex {
get {
return editIndex;
}
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle EditRowStyle {
+ public TableItemStyle EditRowStyle {
get {
if (editRowStyle == null) {
editRowStyle = new TableItemStyle ();
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle EmptyDataRowStyle {
+ public TableItemStyle EmptyDataRowStyle {
get {
if (emptyDataRowStyle == null) {
emptyDataRowStyle = new TableItemStyle ();
}
[DefaultValue (null)]
- [TemplateContainer (typeof(GridView), BindingDirection.OneWay)]
+ [TemplateContainer (typeof(GridViewRow), BindingDirection.OneWay)]
[PersistenceMode (PersistenceMode.InnerProperty)]
- [Browsable (false)]
- public ITemplate EmptyDataTemplate {
+ [Browsable (false)]
+ public virtual ITemplate EmptyDataTemplate {
get { return emptyDataTemplate; }
set { emptyDataTemplate = value; RequireBinding (); }
}
[BrowsableAttribute (false)]
public virtual GridViewRow FooterRow {
get {
- if (footerRow == null)
- footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
- return footerRow;
+ if (table != null) {
+ for (int index = table.Rows.Count - 1; index >= 0; index--) {
+ GridViewRow row = (GridViewRow) table.Rows [index];
+ switch (row.RowType) {
+ case DataControlRowType.Separator:
+ case DataControlRowType.Pager:
+ continue;
+ case DataControlRowType.Footer:
+ return row;
+ default:
+ break;
+ }
+ }
+ }
+ return null;
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DefaultValue (null)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle FooterStyle {
+ public TableItemStyle FooterStyle {
get {
if (footerStyle == null) {
footerStyle = new TableItemStyle ();
[BrowsableAttribute (false)]
public virtual GridViewRow HeaderRow {
get {
- if (headerRow == null)
- headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
- return headerRow;
+ if (table != null) {
+ for (int index = 0, total = table.Rows.Count; index < total; index++) {
+ GridViewRow row = (GridViewRow) table.Rows [index];
+ switch (row.RowType) {
+ case DataControlRowType.Separator:
+ case DataControlRowType.Pager:
+ continue;
+ case DataControlRowType.Header:
+ return row;
+ default:
+ break;
+ }
+ }
+ }
+ return null;
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DefaultValue (null)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle HeaderStyle {
+ public TableItemStyle HeaderStyle {
get {
if (headerStyle == null) {
headerStyle = new TableItemStyle ();
[BrowsableAttribute (false)]
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public int PageCount {
+ public virtual int PageCount {
get {
if (pageCount != -1) return pageCount;
EnsureDataBound ();
[WebCategoryAttribute ("Paging")]
[BrowsableAttribute (true)]
[DefaultValueAttribute (0)]
- public int PageIndex {
+ public virtual int PageIndex {
get {
return pageIndex;
}
[DefaultValueAttribute (10)]
[WebCategoryAttribute ("Paging")]
- public int PageSize {
+ public virtual int PageSize {
get {
object ob = ViewState ["PageSize"];
if (ob != null) return (int) ob;
[DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
[NotifyParentPropertyAttribute (true)]
[PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- public PagerSettings PagerSettings {
+ public virtual PagerSettings PagerSettings {
get {
if (pagerSettings == null) {
pagerSettings = new PagerSettings (this);
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle PagerStyle {
+ public TableItemStyle PagerStyle {
get {
if (pagerStyle == null) {
pagerStyle = new TableItemStyle ();
/* DataControlPagerCell isnt specified in the docs */
//[TemplateContainer (typeof(DataControlPagerCell), BindingDirection.OneWay)]
[PersistenceMode (PersistenceMode.InnerProperty)]
- [Browsable (false)]
- public ITemplate PagerTemplate {
+ [Browsable (false)]
+ public virtual ITemplate PagerTemplate {
get { return pagerTemplate; }
set { pagerTemplate = value; RequireBinding (); }
}
[DefaultValueAttribute ("")]
[WebCategoryAttribute ("Accessibility")]
-// [TypeConverterAttribute (typeof(System.Web.UI.Design.DataColumnSelectionConverter)]
+ // [TypeConverterAttribute (typeof(System.Web.UI.Design.DataColumnSelectionConverter)]
public virtual string RowHeaderColumn {
get {
object ob = ViewState ["RowHeaderColumn"];
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle RowStyle {
+ public TableItemStyle RowStyle {
get {
if (rowStyle == null) {
rowStyle = new TableItemStyle ();
[BindableAttribute (true)]
[DefaultValueAttribute (-1)]
- public int SelectedIndex {
+ public virtual int SelectedIndex {
get {
return selectedIndex;
}
set {
- if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
+ if (Rows != null && selectedIndex >= 0 && selectedIndex < Rows.Count) {
int oldIndex = selectedIndex;
selectedIndex = -1;
Rows [oldIndex].RowState = GetRowState (oldIndex);
}
selectedIndex = value;
- if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
+ if (Rows != null && selectedIndex >= 0 && selectedIndex < Rows.Count) {
Rows [selectedIndex].RowState = GetRowState (selectedIndex);
}
}
}
}
- [WebCategoryAttribute ("Styles")]
+ [WebCategoryAttribute ("Styles")]
[PersistenceMode (PersistenceMode.InnerProperty)]
[NotifyParentProperty (true)]
[DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public virtual TableItemStyle SelectedRowStyle {
+ public TableItemStyle SelectedRowStyle {
get {
if (selectedRowStyle == null) {
selectedRowStyle = new TableItemStyle ();
}
[BrowsableAttribute (false)]
- public virtual object SelectedValue {
+ public object SelectedValue {
get {
if (SelectedDataKey != null)
return SelectedDataKey.Value;
object fitem = null;
prop_type = null;
PropertyInfo prop_item = source.DataSource.GetType().GetProperty("Item",
- BindingFlags.Instance | BindingFlags.Static |
- BindingFlags.Public, null, null,
- new Type[] { typeof(int) }, null);
+ BindingFlags.Instance | BindingFlags.Static |
+ BindingFlags.Public, null, null,
+ new Type[] { typeof(int) }, null);
if (prop_item != null) {
prop_type = prop_item.PropertyType;
table.Rows.Add (topPagerRow);
}
- if (ShowHeader) {
- headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
- table.Rows.Add (headerRow);
- InitializeRow (headerRow, fields);
- }
+ GridViewRow 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);
table.Rows.Add (row);
InitializeRow (row, fields);
if (dataBinding) {
-// row.DataBind ();
+ row.DataBind ();
OnRowDataBound (new GridViewRowEventArgs (row));
if (EditIndex == row.RowIndex)
oldEditValues = new DataKey (GetRowValues (row, false, true));
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);
- }
+ GridViewRow 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);
rows = new GridViewRowCollection (list);
keys = new DataKeyArray (keyList);
-
- if (dataBinding)
- DataBind (false);
return dataSource.DataSourceCount;
}
bool accessibleHeader = false;
switch (row.RowType) {
- case DataControlRowType.Header:
- ctype = DataControlCellType.Header;
- accessibleHeader = UseAccessibleHeader;
- break;
- case DataControlRowType.Footer:
- ctype = DataControlCellType.Footer;
- break;
- default:
- ctype = DataControlCellType.DataCell;
- break;
+ case DataControlRowType.Header:
+ ctype = DataControlCellType.Header;
+ accessibleHeader = UseAccessibleHeader;
+ break;
+ case DataControlRowType.Footer:
+ ctype = DataControlCellType.Footer;
+ break;
+ default:
+ ctype = DataControlCellType.DataCell;
+ break;
}
for (int n=0; n<fields.Length; n++) {
GridViewCommandEventArgs args = e as GridViewCommandEventArgs;
if (args != null) {
OnRowCommand (args);
- ProcessEvent (args.CommandName, args.CommandArgument as string);
+ string param = args.CommandArgument as string;
+ if (param == null || param.Length == 0) {
+ GridViewRow row = args.Row;
+ if (row != null)
+ param = row.RowIndex.ToString();
+ }
+ ProcessEvent (args.CommandName, param);
}
return base.OnBubbleEvent (source, e);
}
+ void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
+ {
+ RaisePostBackEvent (eventArgument);
+ }
+
// This is prolly obsolete
protected virtual void RaisePostBackEvent (string eventArgument)
{
{
switch (eventName)
{
- case DataControlCommands.PageCommandName:
- int newIndex = -1;
- switch (param) {
- case DataControlCommands.FirstPageCommandArgument:
- newIndex = 0;
- break;
- case DataControlCommands.LastPageCommandArgument:
- newIndex = PageCount - 1;
- break;
- case DataControlCommands.NextPageCommandArgument:
- if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
- break;
- case DataControlCommands.PreviousPageCommandArgument:
- if (PageIndex > 0) newIndex = PageIndex - 1;
- break;
- default:
- newIndex = int.Parse (param) - 1;
- break;
- }
- ShowPage (newIndex);
- break;
-
+ case DataControlCommands.PageCommandName:
+ int newIndex = -1;
+ switch (param) {
case DataControlCommands.FirstPageCommandArgument:
- ShowPage (0);
+ newIndex = 0;
break;
-
case DataControlCommands.LastPageCommandArgument:
- ShowPage (PageCount - 1);
+ newIndex = PageCount - 1;
break;
-
case DataControlCommands.NextPageCommandArgument:
- if (PageIndex < PageCount - 1)
- ShowPage (PageIndex + 1);
+ if (PageIndex < PageCount - 1) newIndex = PageIndex + 1;
break;
-
case DataControlCommands.PreviousPageCommandArgument:
- if (PageIndex > 0)
- ShowPage (PageIndex - 1);
+ if (PageIndex > 0) newIndex = PageIndex - 1;
break;
-
- case DataControlCommands.SelectCommandName:
- SelectRow (int.Parse (param));
+ default:
+ newIndex = int.Parse (param) - 1;
break;
+ }
+ ShowPage (newIndex);
+ break;
- case DataControlCommands.EditCommandName:
- EditRow (int.Parse (param));
- break;
+ case DataControlCommands.FirstPageCommandArgument:
+ ShowPage (0);
+ break;
+
+ case DataControlCommands.LastPageCommandArgument:
+ ShowPage (PageCount - 1);
+ break;
- case DataControlCommands.UpdateCommandName:
- UpdateRow (EditIndex, true);
- break;
+ case DataControlCommands.NextPageCommandArgument:
+ if (PageIndex < PageCount - 1)
+ ShowPage (PageIndex + 1);
+ break;
+
+ case DataControlCommands.PreviousPageCommandArgument:
+ if (PageIndex > 0)
+ ShowPage (PageIndex - 1);
+ break;
- case DataControlCommands.CancelCommandName:
- CancelEdit ();
- break;
+ case DataControlCommands.SelectCommandName:
+ SelectRow (int.Parse (param));
+ break;
- case DataControlCommands.DeleteCommandName:
- DeleteRow (int.Parse (param));
- break;
+ case DataControlCommands.EditCommandName:
+ EditRow (int.Parse (param));
+ break;
- case DataControlCommands.SortCommandName:
- Sort (param);
- break;
+ case DataControlCommands.UpdateCommandName:
+ UpdateRow (EditIndex, true);
+ break;
+
+ case DataControlCommands.CancelCommandName:
+ CancelEdit ();
+ break;
+
+ case DataControlCommands.DeleteCommandName:
+ DeleteRow (int.Parse (param));
+ break;
+
+ case DataControlCommands.SortCommandName:
+ Sort (param);
+ break;
}
}
Sort (newSortExpression, newDirection);
}
- public void Sort (string newSortExpression, SortDirection newSortDirection)
+ public virtual void Sort (string newSortExpression, SortDirection newSortDirection)
{
GridViewSortEventArgs args = new GridViewSortEventArgs (newSortExpression, newSortDirection);
OnSorting (args);
EndRowEdit ();
}
- bool UpdateCallback (int recordsAffected, Exception exception)
+ bool UpdateCallback (int recordsAffected, Exception exception)
{
GridViewUpdatedEventArgs dargs = new GridViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
OnRowUpdated (dargs);
return dargs.ExceptionHandled;
}
- public void DeleteRow (int rowIndex)
+ public virtual void DeleteRow (int rowIndex)
{
GridViewRow row = Rows [rowIndex];
currentEditRowKeys = DataKeys [rowIndex].Values;
}
}
- bool DeleteCallback (int recordsAffected, Exception exception)
+ bool DeleteCallback (int recordsAffected, Exception exception)
{
GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
OnRowDeleted (dargs);
object bstate = base.SaveControlState ();
return new object[] {
bstate, pageIndex, pageCount, selectedIndex, editIndex, sortExpression, sortDirection
- };
+ };
}
protected override void TrackViewState()
if (states[12] != null && oldEditValues != null) ((IStateManager)oldEditValues).LoadViewState (states[12]);
}
- string ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
+ void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
{
- return RaiseCallbackEvent (eventArgs);
+ RaiseCallbackEvent (eventArgs);
}
- protected virtual string RaiseCallbackEvent (string eventArgs)
+ string callbackResult;
+ protected virtual void RaiseCallbackEvent (string eventArgs)
{
string[] clientData = eventArgs.Split ('|');
pageIndex = int.Parse (clientData[0]);
HtmlTextWriter writer = new HtmlTextWriter (sw);
RenderGrid (writer);
- return sw.ToString ();
+ callbackResult = sw.ToString ();
}
+ string ICallbackEventHandler.GetCallbackResult ()
+ {
+ return GetCallbackResult ();
+ }
+
+ protected virtual string GetCallbackResult ()
+ {
+ return callbackResult;
+ }
+
string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
{
return GetCallbackScript (control, argument);
Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
// Make sure the basic script infrastructure is rendered
- Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
+ Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
Page.ClientScript.GetPostBackClientHyperlink (this, "");
}
}
void RenderGrid (HtmlTextWriter writer)
{
switch (GridLines) {
- case GridLines.Horizontal:
- writer.AddAttribute (HtmlTextWriterAttribute.Rules, "rows");
- writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
- break;
- case GridLines.Vertical:
- writer.AddAttribute (HtmlTextWriterAttribute.Rules, "cols");
- writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
- break;
- case GridLines.Both:
- writer.AddAttribute (HtmlTextWriterAttribute.Rules, "all");
- writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
- break;
- default:
- writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
- break;
+ case GridLines.Horizontal:
+ writer.AddAttribute (HtmlTextWriterAttribute.Rules, "rows");
+ writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
+ break;
+ case GridLines.Vertical:
+ writer.AddAttribute (HtmlTextWriterAttribute.Rules, "cols");
+ writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
+ break;
+ case GridLines.Both:
+ writer.AddAttribute (HtmlTextWriterAttribute.Rules, "all");
+ writer.AddAttribute (HtmlTextWriterAttribute.Border, "1");
+ break;
+ default:
+ writer.AddAttribute (HtmlTextWriterAttribute.Border, "0");
+ break;
}
writer.AddAttribute (HtmlTextWriterAttribute.Cellspacing, "0");
foreach (GridViewRow row in table.Rows)
{
switch (row.RowType) {
- case DataControlRowType.Header:
- if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
- break;
- case DataControlRowType.Footer:
- if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
- break;
- case DataControlRowType.Pager:
- if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
- break;
- case DataControlRowType.EmptyDataRow:
- if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
- break;
- default:
- if (rowStyle != null) rowStyle.AddAttributesToRender (writer, row);
- break;
+ case DataControlRowType.Header:
+ if (!ShowHeader) continue;
+ if (headerStyle != null)headerStyle.AddAttributesToRender (writer, row);
+ break;
+ case DataControlRowType.Footer:
+ if (!ShowFooter) continue;
+ if (footerStyle != null) footerStyle.AddAttributesToRender (writer, row);
+ break;
+ case DataControlRowType.Pager:
+ if (pagerStyle != null) pagerStyle.AddAttributesToRender (writer, row);
+ break;
+ case DataControlRowType.EmptyDataRow:
+ if (emptyDataRowStyle != null) emptyDataRowStyle.AddAttributesToRender (writer, row);
+ break;
+ default:
+ break;
}
+ if ((row.RowState & DataControlRowState.Normal) != 0 && rowStyle != null)
+ rowStyle.AddAttributesToRender (writer, row);
if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null)
alternatingRowStyle.AddAttributesToRender (writer, row);
if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null)
if (fcell != null) {
Style cellStyle = null;
switch (row.RowType) {
- case DataControlRowType.Header: cellStyle = fcell.ContainingField.HeaderStyle; break;
- case DataControlRowType.Footer: cellStyle = fcell.ContainingField.FooterStyle; break;
- default: cellStyle = fcell.ContainingField.ItemStyle; break;
+ case DataControlRowType.Header: cellStyle = fcell.ContainingField.HeaderStyle; break;
+ case DataControlRowType.Footer: cellStyle = fcell.ContainingField.FooterStyle; break;
+ default: cellStyle = fcell.ContainingField.ItemStyle; break;
}
if (cellStyle != null)
cellStyle.AddAttributesToRender (writer, cell);
}
table.RenderEndTag (writer);
}
+
+ [MonoTODO]
+ PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
+ {
+ throw new NotImplementedException ();
+ }
}
}