C1CheckBoxField Using C1GridView 2025v2 399

Posted by: enrique.pv-ext on 19 February 2026, 8:03 am EST

  • Posted 19 February 2026, 8:03 am EST - Updated 19 February 2026, 8:41 am EST

    Hi,

    Migrate from 2010v1 to 2025v2 399 in ASP.NET WebForms NET Framework 4.8.1.

    Using C1GridView from C1.Web.Wijmo.Controls.48.dll

    Using C1CheckBoxField column:

    Old version 2010v1

    New version 2025v2 399

    In 2025v2 399 version, it’s not appears Checkbox Column!

    Create columns dynamically using code, not markup

                    <cc1:C1GridView ID="C1GridView1" Width="100%"
                        runat="server"
                        AllowPaging="True" PageSize="30"
                        AllowSorting="True" ShowFilter="True"
                        AutogenerateColumns="False"
                        OnPageIndexChanging="C1GridView1_PageIndexChanging"
                        OnSorting="C1GridView1_Sorting"
                        OnSorted="C1GridView1_Sorted"
                        OnFiltering="C1GridView1_Filtering"
                        OnRowCreated="C1GridView1_RowCreated"
                        OnRowDataBound="C1GridView1_RowDataBound">
                        <Columns>
                        </Columns>
                    </cc1:C1GridView>

    In ConfigureGridColumns method:

    case ColumnsC1GridView1.SELECTION:
                                var check = new C1CheckBoxField();
                                check.AllowSizing = false;
                                check.ShowFilter = false;
                                check.ReadOnly = false;
                                check.ItemStyle.Width = 10;
                                this.C1GridView1.Columns.Add(check);
                                break;
    
                            case ColumnsC1GridView1.DEBT_PAYMENT:
                                col = new C1ButtonField();
                                col.AllowSizing = false;
                                col.CommandName = "DEBT_PAYMENT";
                                col.ButtonType = ButtonType.Image;
                                col.ImageUrl = "~/App_Themes/Content/Imagenes/editing.gif";
                                col.ItemStyle.Width = 10;
                                this.C1GridView1.Columns.Add(col);
                                break;

    RowCreated event, create CheckBox for Header

       protected void C1GridView1_RowCreated(object sender, C1GridViewRowEventArgs e)
       {
           Logger.Debug("C1GridView1_RowCreated");
           try
           {
               if (e.Row.RowType == C1GridViewRowType.Header ) //&& this._textsShown != null)
               {
                   var textos = this._textsShown;
    
                   var check = new CheckBox();
                   check.ID = "selectionHeader";
                   check.Attributes["onclick"] = "CheckAll(this);";
                   check.Checked = AllSelected;
                   e.Row.Cells[(int)ColumnsC1GridView1.SELECTION].Controls.Add(check);
    
                   e.Row.Cells[(int)ColumnsC1GridView1.BAG_DEBT].ToolTip = (string)this._textsShown[4];
                   e.Row.Cells[(int)ColumnsC1GridView1.OPERATOR].ToolTip = (string)this._textsShown[3];
               }

    any suggestions for use C1CheckBoxField in GridView ?

    thx a lot

  • Posted 20 February 2026, 9:09 am EST

    Hello Enrique,

    We’re investigating the behavior and will update you once we have more information.

    Regards,

    Uttkarsh.

  • Posted 23 February 2026, 4:56 am EST

    Hello Enrique,

    Please refer to the attached sample for CheckBox column implementation on server-side and let us know if you face any issues.

    Sample: GridView_Checkbox.zip

    Regards,

    Uttkarsh.

  • Posted 11 March 2026, 11:32 am EST - Updated 11 March 2026, 12:07 pm EST

    Thanks at all.

    I try your sample. I can check all, but not uncheck all:

    anyways, I get error filtering:

    ‘C1GridView1’: the Filtering event was not handled.

  • Posted 12 March 2026, 6:02 am EST

    Hello Enrique,

    We provided you a method to implement your scenario. If you want a different functionality of button click, you can modify the method accordingly.

    For example, if you want the following behavior:

    • If any checkbox is unchecked → check all
    • If all are checked → uncheck all

    Then, you can modify the CheckAll_Click() method in HeaderButtonTemplate class as follows:

    private void CheckAll_Click(object sender, ImageClickEventArgs e)
    {
        var btn = (ImageButton)sender;
        var grid = (C1GridView)btn.NamingContainer.NamingContainer;
    
        bool allChecked = true;
    
        // Step 1: Check if ALL checkboxes are checked
        foreach (C1GridViewRow row in grid.Rows)
        {
            var cb = (CheckBox)row.FindControl("chk");
            if (cb != null && !cb.Checked)
            {
                allChecked = false;
                break;
            }
        }
    
        // Step 2: Toggle state
        bool newState = !allChecked;
    
        foreach (C1GridViewRow row in grid.Rows)
        {
            var cb = (CheckBox)row.FindControl("chk");
            if (cb != null)
                cb.Checked = newState;
        }
    }

    Please let us know if you have further queries.

    Regards,

    Uttkarsh.

  • Posted 20 March 2026, 4:36 am EST

    Not working for me , toggle Check-Uncheck

    I try this:

    OnInit

    protected override void OnInit(EventArgs e)
      RestoreStateFromSession();
      BuildGridStructure();
    

    Page Load

    protected void Page_Load(object sender, EventArgs e)
                        // TODO: NEW Guardar textos para OnInit en siguientes postbacks
                        Session["TEXTS_SHOWN"] = this._textsShown;
    
                        if (!IsPostBack)
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "var SelectionDebts = [];", true);
    
                            // TODO: TEST  1. Mueve TODA la construcción de columnas al evento OnInit, NO en Page_Load
                            //// this.ConfigureGridColumns();
    
                            this.RepaintGrid();
                            ((C1BoundField)this.C1GridView1.Columns[(int)ColumnsC1GridView1.OPERATOR]).SortDirection = C1SortDirection.Ascending;
                            this.ConfigureDropDownList();
                            Session["DATA_SOURCES"] = this._dataSources;
    
                            HSelectionAll.Value = "false";
                            HUnselected.Value = "";
                            HSelected.Value = "";
                            HAllItems.Value = "";
    
                            FillHiddenSelectionDataFromMainTable();
                            SaveStateToSession();

    Filtering

    protected void C1GridView1_Filtering(object sender, C1GridViewFilterEventArgs e)
                    if (this.C1GridView1.Columns.Count == 0)
                    {
                        BuildGridStructure();
                    }
    
                    this._dataSources = Session["DATA_SOURCES"] as DataSet;
                    if (this._dataSources == null || this._dataSources.Tables["MAIN_TABLE"] == null)
                        throw new InvalidOperationException("Session[DATA_SOURCES] no contiene MAIN_TABLE");
    
                    this.C1GridView1.DataSource = HelperUtil.GetGridFilterByFieldType(this.C1GridView1.Columns, this._dataSources.Tables["MAIN_TABLE"]);
    
                    // Desactiva temporalmente reStartC1GridView1AndBind() y sustituye por un bind directo:
                    Logger.Debug("ANTES DATABIND: BAG_DEBT FilterValue=" + ((C1BoundField)C1GridView1.Columns[(int)ColumnsC1GridView1.BAG_DEBT]).FilterValue);
                    this.C1GridView1.DataBind();
                    Logger.Debug("DESPUÉS DATABIND: BAG_DEBT FilterValue=" + ((C1BoundField)C1GridView1.Columns[(int)ColumnsC1GridView1.BAG_DEBT]).FilterValue);

    RowDataBound

    protected void C1GridView1_RowDataBound(object sender, C1GridViewRowEventArgs e)
                    // *************************** TODO: NEW 
                    var cb = e.Row.FindControl("chk") as CheckBox;
                    if (cb != null)
                    {
                        var selectedIds = GetSelectedIds();
                        string rowId = GetRowId(this.C1GridView1, e.Row);
                        cb.Checked = selectedIds.Contains(rowId);
                    }
                    // ***************************

    BuildGridStructure

    private void BuildGridStructure()
                                var tf = new C1TemplateField
                                {
                                    HeaderText = string.Empty,
                                    Width = 40,
                                    HeaderTemplate = new HeaderButtonTemplate(this.CheckAll_Click_FromTemplate),
                                    ItemTemplate = new CheckBoxTemplate()
                                };
                                this.C1GridView1.Columns.Add(tf);

    CheckAll_Click_FromTemplate

    internal void CheckAll_Click_FromTemplate(object sender, ImageClickEventArgs e)
    {
        var btn = (ImageButton)sender;
        var grid = btn.NamingContainer?.NamingContainer as C1GridView;
        if (grid == null) return;
    
        var selectedIds = GetSelectedIds();
        var visibleIds = new List<string>();
    
        foreach (C1GridViewRow row in grid.Rows)
        {
            if (row.RowType != C1GridViewRowType.DataRow)
                continue;
    
            string rowId = GetRowId(grid, row);
            if (!string.IsNullOrWhiteSpace(rowId))
                visibleIds.Add(rowId);
        }
    
        // ¿Todos los visibles están ya seleccionados?
        bool allVisibleChecked = visibleIds.Count > 0 &&
                                 visibleIds.All(id => selectedIds.Contains(id));
    
        bool newState = !allVisibleChecked;
    
        foreach (C1GridViewRow row in grid.Rows)
        {
            if (row.RowType != C1GridViewRowType.DataRow)
                continue;
    
            var cb = row.FindControl("chk") as CheckBox;
            if (cb == null)
                continue;
    
            string rowId = GetRowId(grid, row);
            if (string.IsNullOrWhiteSpace(rowId))
                continue;
    
            cb.Checked = newState;
    
            if (newState)
                selectedIds.Add(rowId);
            else
                selectedIds.Remove(rowId);
        }
    
        SaveSelectedIds(selectedIds);
    
        // Reflejarlo en tus hidden fields
        HSelectionAll.Value = (after.UncheckedCount == 0 && after.CheckedCount > 0)
            ? "true"
            : "false";
    
        HSelected.Value = string.Join(",", after.CheckedIds);
        HUnselected.Value = string.Join(",", after.UncheckedIds);
    
        SaveStateToSession();
        UpdatePanelGrid.Update();
    }

    HeaderButtonTemplate

    public class HeaderButtonTemplate : ITemplate
        {
            private readonly ImageClickEventHandler _handler;
            private readonly string _imageUrl;
            private readonly string _toolTip;
    
            public HeaderButtonTemplate(ImageClickEventHandler handler,
                                        string imageUrl = "~/App_Themes/Content/Imagenes/ico_ok.png",
                                        string toolTip = "Seleccionar / deseleccionar todos")
            {
                _handler = handler ?? throw new ArgumentNullException(nameof(handler));
                _imageUrl = imageUrl;
                _toolTip = toolTip;
            }
    
            public void InstantiateIn(Control container)
            {
                var btn = new ImageButton();
                btn.ID = "checkallbutton";
                btn.ImageUrl = _imageUrl;
                btn.Width = 16;
                btn.Height = 16;
                btn.ToolTip = _toolTip;
                btn.Click += _handler;
    
                container.Controls.Add(btn);
            }
        }
  • Posted 20 March 2026, 4:51 am EST

    Helper methods in aspx:

            private HashSet<string> GetSelectedIds()
            {
                var ids = Session[SESSION_SELECTED_IDS] as HashSet<string>;
                if (ids == null)
                {
                    ids = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                    Session[SESSION_SELECTED_IDS] = ids;
                }
                return ids;
            }
    
            private void SaveSelectedIds(HashSet<string> ids)
            {
                Session[SESSION_SELECTED_IDS] = ids;
            }
    
            private void SaveStateToSession()
            {
                Session[SESSION_DATA_SOURCES] = this._dataSources;
                Session[SESSION_TEXTS_SHOWN] = this._textsShown;
                Session[SESSION_SELECTION_ALL] = HSelectionAll?.Value;
                Session[SESSION_SELECTED] = HSelected?.Value;
                Session[SESSION_UNSELECTED] = HUnselected?.Value;
                Session[SESSION_ALL_ITEMS] = HAllItems?.Value;
            }
    
            private void RestoreStateFromSession()
            {
                if (Session[SESSION_DATA_SOURCES] is DataSet ds)
                    this._dataSources = ds;
    
                if (Session[SESSION_TEXTS_SHOWN] != null)
                    this._textsShown = Session[SESSION_TEXTS_SHOWN] as Hashtable;
    
                if (Session[SESSION_SELECTION_ALL] != null)
                    HSelectionAll.Value = Session[SESSION_SELECTION_ALL].ToString();
    
                if (Session[SESSION_SELECTED] != null)
                    HSelected.Value = Session[SESSION_SELECTED].ToString();
    
                if (Session[SESSION_UNSELECTED] != null)
                    HUnselected.Value = Session[SESSION_UNSELECTED].ToString();
    
                if (Session[SESSION_ALL_ITEMS] != null)
                    HAllItems.Value = Session[SESSION_ALL_ITEMS].ToString();
            }
    
            private string GetRowId(C1GridView grid, C1GridViewRow row)
            {
                try
                {
                    if (grid.DataKeys != null &&
                        row.RowIndex >= 0 &&
                        row.RowIndex < grid.DataKeys.Count)
                    {
                        var dk = grid.DataKeys[row.RowIndex];
                        if (dk != null && dk.Value != null)
                            return Convert.ToString(dk.Value);
                    }
                }
                catch
                {
                    // Fallback si hiciera falta
                }
    
                return "ROW_" + row.RowIndex;
            }
    
            private void FillHiddenSelectionDataFromMainTable()
            {
                if (_dataSources == null ||
                    _dataSources.Tables == null ||
                    _dataSources.Tables["MAIN_TABLE"] == null)
                    return;
    
                string colIDs = string.Join(",",
                    _dataSources.Tables["MAIN_TABLE"]
                        .AsEnumerable()
                        .Select(r => Convert.ToString(r["ID"]))
                        .Where(id => !string.IsNullOrWhiteSpace(id)));
    
                HUnselected.Value = colIDs;
                HAllItems.Value = colIDs;
            }
  • Posted 20 March 2026, 5:29 am EST

    Before, it was used hidden fields and javascript for check - uncheck:

    HiddenFields

    <asp:HiddenField ID="HSelectionAll" runat="server" />
                    <asp:HiddenField ID="HSelected" runat="server" />
                    <asp:HiddenField ID="HUnselected" runat="server" />
                    <asp:HiddenField ID="HAllItems" runat="server" />

    Javascript:

            var ChangeSelection = function (oCheck, id) {
                try {
    
                    var s = document.getElementById('<%=HSelected.ClientID %>').value;
                    var u = document.getElementById('<%=HUnselected.ClientID %>').value;
                    var value, oSelected, oUnselected;
                    eval("oSelected = [" + s + "]; oUnselected = [" + u + "];");
    
                    value = oCheck.checked;
    
                    if (value) {
                        //Remove from Unselecteds
                        var iUnselected = oUnselected.indexOf(id);
                        if (iUnselected >= 0) {
                            oUnselected.splice(iUnselected, 1);
                        }
    
                        //Add to Selecteds
                        var iSelected = oSelected.indexOf(id);
                        if (iSelected < 0) {
                            oSelected.push(id);
                        }
                    }
                    else {
                        //Remove from Selecteds
                        var iSelected = oSelected.indexOf(id);
                        if (iSelected >= 0) {
                            oSelected.splice(iSelected, 1);
                        }
    
                        //Add to Unselecteds
                        var iUnselected = oUnselected.indexOf(id);
                        if (iUnselected < 0) {
                            oUnselected.push(id);
                        }
                    }
    
                    document.getElementById('<%=HSelected.ClientID %>').value = oSelected.join();
                    document.getElementById('<%=HUnselected.ClientID %>').value = oUnselected.join();
                }
                catch (e) {
                    alert("ChangeSelection: " + e);
                }
            };
    
            var ChangeAll = function (value) {
                var all = document.getElementById('<%=HAllItems.ClientID %>').value;
    
                if (value) {
                    document.getElementById('<%=HSelected.ClientID %>').value = all;
                    document.getElementById('<%=HUnselected.ClientID %>').value = "";
                } else {
                    document.getElementById('<%=HSelected.ClientID %>').value = "";
                    document.getElementById('<%=HUnselected.ClientID %>').value = all;
                }
    
            };
    
            function CheckAll(oCheck) {
                try {
                    document.getElementById('<%=HSelectionAll.ClientID %>').value = oCheck.checked;
    
                    for (var x in SelectionDebts) {
                        var c = document.getElementById(SelectionDebts[x].ctr);
                        if (c) {
                            c.checked = oCheck.checked;
                        }
                    }
                    ChangeAll(oCheck.checked);
                }
                catch (e) {
                    alert("CheckAll: " + e);
                }
            }

    BAckend code:

    SelectionDebts = [];

       protected void Page_Load(object sender, EventArgs e)
                   if (!IsPostBack)
                   {
                       ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "var SelectionDebts = [];", true);
    
            HSelectionAll.Value = "false";
            HUnselected.Value = "";
            HSelected.Value = "";
            HAllItems.Value = "";
           FillHiddenSelectionDataFromMainTable();
            SaveStateToSession();
    
            if (_dataSources != null &&
           _dataSources.Tables != null &&
           _dataSources.Tables["MAIN_TABLE"] != null)
            {
                string colIDs = string.Empty;
                foreach (DataRow row in _dataSources.Tables["MAIN_TABLE"].Rows)
                {
                    colIDs += string.IsNullOrEmpty(colIDs) ? "" : ",";
                    colIDs += string.Format("{0}", row["ID"]);
                }
                HUnselected.Value = colIDs;
                HAllItems.Value = colIDs;
            }
    
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), "SelectionDebts = [];", true);
    
            AllSelected = bool.Parse(HSelectionAll.Value);
            AllSelected = bool.TryParse(HSelectionAll.Value, out bool b) && b;
            SelectedRows = new List<string>(HSelected.Value.Split(','));
            SelectedRows = string.IsNullOrWhiteSpace(HSelected.Value)
                                   ? new List<string>()
                                   : new List<string>(HSelected.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
    
            //is a postback
            this._dataSources = Session["DATA_SOURCES"] as DataSet;
        }
    }

    ChangeSelection and SelectionDebts.push

    protected void C1GridView1_RowDataBound(object sender, C1GridViewRowEventArgs e)
    {
                    ControlCollection checkControls = e.Row.Cells[(int)ColumnsC1GridView1.SELECTION].Controls;
                    foreach (WebControl ctrl in checkControls)
                    {
                        ctrl.Enabled = true;
                        ctrl.Attributes["operator_id"] = operatorId.ToString();
                        ctrl.Attributes["onclick"] = string.Format("ChangeSelection(this,{0});", operatorId);
    
                        if (ctrl.GetType() == typeof(CheckBox))
                            ((CheckBox)ctrl).Checked = SelectedRows.Contains(operatorId.ToString());
    
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), Guid.NewGuid().ToString(), string.Format(" SelectionDebts.push({{ ctr:'{0}', id: {1} }});", ctrl.ClientID, operatorId), true);
                    }

    do you recommended use javascript client to check-uncheck checkbox ?

    any suggestions, please’?

    thanks all

  • Posted 23 March 2026, 3:33 am EST

    Hello Enrique,

    Thank you for sharing your implementation details. We can see your application includes several requirements that our original sample did not cover:

    • Session-backed selection state persisted across postbacks and pages
    • Hidden fields (HSelected, HUnselected, HAllItems, HSelectionAll) as the source of truth for selection
    • Client-side ChangeSelection() JavaScript to update hidden fields instantly on individual checkbox clicks without triggering a postback
    • Header button toggle that checks/unchecks all rows across all pages (not just the current page)
    • RowDataBound restoring each checkbox’s checked state from the persisted selection
    • DataKeyNames used to reliably identify rows via DataKeys

    We have updated our sample to include all of the above. Please refer to the attached sample: GridView_Checkbox.zip

    To answer your questions directly:

    Should you use client-side JavaScript or server-side for check/uncheck?

    The recommended approach is a hybrid, which is what our updated sample uses. Individual row checkbox clicks are handled client-side (via ChangeSelection() JS) — this updates the hidden fields instantly with no postback and gives the user immediate feedback. The header button toggle is handled server-side since it needs to apply state across all pages, not just the visible rows. The hidden fields bridge the two: they are posted back on every postback so the server always receives the latest client-side state.

    Why was the toggle not unchecking?

    It seems the toggle logic in our previous sample was evaluating only the rendered rows of the current page to determine checked state, which would not be compatible with your implementation that persists selection across pages via hidden fields and session. Please let us know if our current solution works for you.

    Please let us know if this helps or if anything is missing from your implementation.

    Regards,

    Uttkarsh.

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels