ASPxClientGridView.GetColumnsCount Method
Obsolete. Returns the number of columns within the client GridView.
Declaration
GetColumnsCount(): number
Returns
Type |
Description |
number |
An integer value that specifies the number of columns within the client ASPxGridView.
|
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.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DisableColumnEditorsOnClient._Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>How to iterate through column editors on the client</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" ClientInstanceName="grid" KeyFieldName="ID" OnCellEditorInitialize="ASPxGridView1_CellEditorInitialize" OnRowUpdating="ASPxGridView1_RowUpdating" Width="390px">
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataTextColumn FieldName="Name" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataDateColumn FieldName="Date" VisibleIndex="2">
</dxwgv:GridViewDataDateColumn>
<dxwgv:GridViewDataCheckColumn FieldName="Editable" VisibleIndex="3">
<PropertiesCheckEdit>
<ClientSideEvents CheckedChanged="function(s, e) {
for(i = 0; i < grid.GetColumnsCount(); i++) {
var editor = grid.GetEditor(i);
if(editor != null && editor != s)
editor.SetEnabled(s.GetChecked());
}
}" />
</PropertiesCheckEdit>
</dxwgv:GridViewDataCheckColumn>
</Columns>
</dxwgv:ASPxGridView>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace DisableColumnEditorsOnClient {
public partial class _Default : System.Web.UI.Page {
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.VisibleIndex, "Editable");
e.Editor.ClientEnabled = editable;
}
}
}
}
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="DisableColumnEditorsOnClient._Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v8.3, Version=8.3.6.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>How to iterate through column editors on the client</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dxwgv:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" ClientInstanceName="grid" KeyFieldName="ID" OnCellEditorInitialize="ASPxGridView1_CellEditorInitialize" OnRowUpdating="ASPxGridView1_RowUpdating" Width="390px">
<Columns>
<dxwgv:GridViewCommandColumn VisibleIndex="0">
<EditButton Visible="True">
</EditButton>
</dxwgv:GridViewCommandColumn>
<dxwgv:GridViewDataTextColumn FieldName="Name" VisibleIndex="1">
</dxwgv:GridViewDataTextColumn>
<dxwgv:GridViewDataDateColumn FieldName="Date" VisibleIndex="2">
</dxwgv:GridViewDataDateColumn>
<dxwgv:GridViewDataCheckColumn FieldName="Editable" VisibleIndex="3">
<PropertiesCheckEdit>
<ClientSideEvents CheckedChanged="function(s, e) {
for(i = 0; i < grid.GetColumnsCount(); i++) {
var editor = grid.GetEditor(i);
if(editor != null && editor != s)
editor.SetEnabled(s.GetChecked());
}
}" />
</PropertiesCheckEdit>
</dxwgv:GridViewDataCheckColumn>
</Columns>
</dxwgv:ASPxGridView>
</div>
</form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Namespace DisableColumnEditorsOnClient
Partial Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
ASPxGridView1.DataSource = GetDataSource()
End Sub
Private Function GetDataSource() As DataTable
Dim table As New DataTable()
table.Columns.Add("ID", GetType(Integer))
table.Columns.Add("Name", GetType(String))
table.Columns.Add("Date", GetType(DateTime))
table.Columns.Add("Editable", GetType(Boolean))
table.Rows.Add(1, "Item A", DateTime.Today, True)
table.Rows.Add(2, "Item B", DateTime.Today.AddDays(-1), False)
Return table
End Function
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
ASPxGridView1.DataBind()
End Sub
' value saving is halted
Protected Sub ASPxGridView1_RowUpdating(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)
e.Cancel = True
ASPxGridView1.CancelEdit()
End Sub
Protected Sub ASPxGridView1_CellEditorInitialize(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs)
If e.Column.FieldName <> "Editable" Then
Dim editable As Boolean = CBool(ASPxGridView1.GetRowValues(e.VisibleIndex, "Editable"))
e.Editor.ClientEnabled = editable
End If
End Sub
End Class
End Namespace
See Also