Skip to main content

ASPxClientGridView.GetColumnCount Method

Returns the number of columns within the client GridView.

Declaration

GetColumnCount(): number

Returns

Type Description
number

The number of columns within the client GridView.

Example

The example demonstrates how to dynamically disable editors on Edit Form, when an editor's value is changed.This approach cannot be used when edit templates are defined.

<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" ClientInstanceName="grid" 
                 KeyFieldName="ID" OnCellEditorInitialize="ASPxGridView1_CellEditorInitialize" OnRowUpdating="ASPxGridView1_RowUpdating" Width="390px">
    <Columns>
        <dx:GridViewCommandColumn >
            <EditButton Visible="True" />
        </dx:GridViewCommandColumn>
        <dx:GridViewDataTextColumn FieldName="Name" />
        <dx:GridViewDataDateColumn FieldName="Date" />
        <dx:GridViewDataCheckColumn FieldName="Editable" >
            <PropertiesCheckEdit>
                <ClientSideEvents CheckedChanged="function(s, e) {
                                    for(i = 0; i &lt; grid.GetColumnsCount(); i++) {
                                        var editor = grid.GetEditor(i);
                                        if(editor != null &amp;&amp; editor != s)
                                            editor.SetEnabled(s.GetChecked());
                                    }
                                  }" />
            </PropertiesCheckEdit>
        </dx:GridViewDataCheckColumn>
    </Columns>
</dx:ASPxGridView>
protected void Page_Init(object sender, EventArgs e) {
    ASPxGridView1.DataSource = GetDataSource();
}
private DataTable GetDataSource() {
    DataTable table = new DataTable();
    table.Columns.Add("ID", typeof(int));
    table.Columns.Add("Name", typeof(string));
    table.Columns.Add("Date", typeof(DateTime));
    table.Columns.Add("Editable", typeof(bool));
    table.Rows.Add(1, "Item A", DateTime.Today, true);
    table.Rows.Add(2, "Item B", DateTime.Today.AddDays(-1), false);
    return table;
}
protected void Page_Load(object sender, EventArgs e) {
    ASPxGridView1.DataBind();
}
// value saving is halted
protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {
    e.Cancel = true;
    ASPxGridView1.CancelEdit();
}
protected void ASPxGridView1_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e) {
    if(e.Column.FieldName != "Editable") {
        bool editable = (bool)ASPxGridView1.GetRowValues(e.);
        e.Editor.ClientEnabled = editable;
    }
}
See Also