AdvantageCMS.Core.Common.BaseClasses Namespace
Build With Advantage

AdvantageGrid Class

Reusable list-editor server control that extends Telerik RadGrid with built-in edit / delete / activate-toggle / feature-toggle / drag-drop-reorder behaviour. The host page supplies the data source through the standard NeedDataSource()()()() event and persists changes; the control renders the rows and raises strongly-typed events identifying which row was acted on (via GridDataKeyValue lists, so composite keys are supported).

Namespace:  AdvantageCMS.Web.UI.Admin
Assembly:  AdvantageCMS.Web.UI (in AdvantageCMS.Web.UI.dll)

Syntax


Remarks


Data-object conventions. To unlock the full feature set the row's data object should expose:

  • bool IsActive — required when ShowActiveButton is true. The active/inactive icon is chosen automatically per row; the toggle column auto-hides if the property is missing.
  • bool IsFeatured — required when ShowFeatureButton is true. Same auto-hide behaviour.
  • int SortOrder — set this from the OnReordered handler to persist drag-drop ordering.

Markup configuration. Declare visible columns inline with the Columns collection of GridColumnDefinition. Common attributes:

Wiring events. Subscribe in the host's OnInit; only the events you handle will surface their column/button. OnLoadObject fires for both Add (toolbar) and Edit (row pencil) — distinguish via CommandType.

Resolving the clicked row. Event args carry an DataKeyValues list keyed by DataKeyNames. Use [GetRecordFromList{T}] to look up the record in your source list. After mutating state, call Rebind()()()() to refresh.

Selection state across postbacks.DataKeyItems holds the currently-selected row's keys (XML-serialised into ViewState), useful when an external edit form needs to know which row is being saved.

Examples


Markup (host .ascx):
 
<%@ Register TagPrefix="advantage" Namespace="AdvantageCMS.Web.UI.Admin"
    Assembly="AdvantageCMS.Web.UI" %>

<advantage:AdvantageGrid runat="server" ID="grdItems"
                         DataKeyNames="Id"
                         ShowActiveButton="true"
                         ShowFeatureButton="true"
                         OnNeedDataSource="grdItems_NeedDataSource">
    <Columns>
        <advantage:GridColumnDefinition HeaderText="Name" DataField="Name" Width="200" />
        <advantage:GridColumnDefinition HeaderText="Type" DataField="TypeLabel" />
    </Columns>
</advantage:AdvantageGrid>
Code-behind (host .ascx.cs):
C#
protected override void OnInit(EventArgs e)
{
    grdItems.OnLoadObject    += grdItems_LoadObject;     // Add or Edit
    grdItems.OnDeleteObject  += grdItems_DeleteObject;
    grdItems.OnToggleActive  += grdItems_ToggleActive;   // requires IsActive on item
    grdItems.OnToggleFeature += grdItems_ToggleFeature;  // requires IsFeatured on item
    grdItems.OnReordered     += grdItems_Reordered;      // drag-drop committed
    base.OnInit(e);
}

protected void grdItems_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    grdItems.DataSource = MyItems;
}

private void grdItems_LoadObject(object sender, AdvantageGrid.AdvantageGridArgs args)
{
    ClearForm();
    if (args.CommandType == AdvantageGrid.GridCommandType.Add) return; // blank form for Add
    var item = AdvantageGrid.GetRecordFromList(MyItems, args.Item.DataKeyValues);
    // populate edit form from `item`...
}

private void grdItems_DeleteObject(object sender, AdvantageGrid.AdvantageGridArgs args)
{
    var item = AdvantageGrid.GetRecordFromList(MyItems, args.Item.DataKeyValues);
    MyItems.Remove(item);
    Save();
    grdItems.Rebind();
}

private void grdItems_ToggleActive(object sender, AdvantageGrid.AdvantageGridToggleArgs args)
{
    var item = AdvantageGrid.GetRecordFromList(MyItems, args.Item.DataKeyValues);
    item.IsActive = args.Toggle;   // true = activate, false = deactivate
    Save();
}

private void grdItems_ToggleFeature(object sender, AdvantageGrid.AdvantageGridToggleArgs args)
{
    var item = AdvantageGrid.GetRecordFromList(MyItems, args.Item.DataKeyValues);
    item.IsFeatured = args.Toggle;
    Save();
}

private void grdItems_Reordered(object sender, AdvantageGrid.AdvantageGridSortArgs args)
{
    for (int i = 0; i < args.Items.Count; i++)
    {
        var item = AdvantageGrid.GetRecordFromList(MyItems, args.Items[i].DataKeyValues);
        item.SortOrder = i;
    }
    Save();
}

Inheritance Hierarchy


Object
  Control
    WebControl
      BaseDataBoundControl
        DataBoundControl
          CompositeDataBoundControl
            RadCompositeDataBoundControl
              GridBaseDataList
                RadGrid
                  AdvantageCMS.Web.UI.Admin..::..AdvantageGrid