Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 67 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,79 @@
[![](https://img.shields.io/badge/Open_in_DevExpress_Support_Center-FF7200?style=flat-square&logo=DevExpress&logoColor=white)](https://supportcenter.devexpress.com/ticket/details/E4580)
[![](https://img.shields.io/badge/📖_How_to_use_DevExpress_Examples-e9f6fc?style=flat-square)](https://docs.devexpress.com/GeneralInformation/403183)
<!-- default badges end -->
# Grid View for ASP.NET Web Forms - How to hide a grid column on the client
<!-- run online -->
**[[Run Online]](https://codecentral.devexpress.com/e4580/)**
<!-- run online end -->

This example demonstrates how to change the visibility of the [Grid View](https://docs.devexpress.com/AspNet/5823/components/grid-view)'s [columns](https://docs.devexpress.com/AspNet/3691/components/grid-view/concepts/data-representation-basics/columns) on the client without making a round trip to the server. Check or uncheck the **Unit Price Column** check box to show or hide the **Unit Price** column.

![Hide a grid column on the client](hide-a-column.png)

## Overview

Follow the steps below to change a [column](https://docs.devexpress.com/AspNet/3691/components/grid-view/concepts/data-representation-basics/columns)'s visibility on the client.

### 1 Apply a CSS class to all cells of a column

A column can include the following cells:

* [Column Header](https://docs.devexpress.com/AspNet/3669/components/grid-view/visual-elements/column-header)
* [Edit Cell](https://docs.devexpress.com/AspNet/3680/components/grid-view/visual-elements/edit-form)
* [Data Cell](https://docs.devexpress.com/AspNet/3670/components/grid-view/visual-elements/data-cell)
* [Filter Row Cell](https://docs.devexpress.com/AspNet/3684/components/grid-view/visual-elements/filter-row)
* [Footer Cell](https://docs.devexpress.com/AspNet/3683/components/grid-view/visual-elements/footer-cell)
* [Group Footer Cell](https://docs.devexpress.com/AspNet/3815/components/grid-view/visual-elements/group-footer)

Apply your CSS class to the [CssClass](https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.style.cssclass?view=netframework-4.8#System_Web_UI_WebControls_Style_CssClass) property of every cell in a column:

```aspx
<dx:ASPxGridView ID="gvProducts" runat="server" AutoGenerateColumns="False" DataSourceID="dsProducts" KeyFieldName="ProductID">
<Columns>
<!-- ... -->
<dx:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="4">
<HeaderStyle CssClass="unitPriceColumn" />
<EditCellStyle CssClass="unitPriceColumn" />
<CellStyle CssClass="unitPriceColumn" />
<FilterCellStyle CssClass="unitPriceColumn" />
<FooterCellStyle CssClass="unitPriceColumn" />
<GroupFooterCellStyle CssClass="unitPriceColumn" />
</dx:GridViewDataTextColumn>
</Columns>
</dx:ASPxGridView>
```

### 2 Specify the display property of the CSS class

The [display](http://www.w3schools.com/cssref/pr_class_display.asp) property of the CSS class specifies the display behavior of an element. Set this property to `none` to hide the column or set it to `table-cell` to show the column.

This example uses a jQuery CSS selector to change the [display](http://www.w3schools.com/cssref/pr_class_display.asp) property value.

```javascript
<script type="text/javascript">
function SetUnitPriceColumnVisibility(visible) {
unitPriceColumnVisible = visible;
var disp = visible ? 'table-cell' : 'none';
$('td.unitPriceColumn').css('display', disp);
}
</script>
```

<!-- default file list -->
*Files to look at*:

## Files to Look At

* [Default.aspx](./CS/WebSite/Default.aspx) (VB: [Default.aspx](./VB/WebSite/Default.aspx))
* [Default.aspx.cs](./CS/WebSite/Default.aspx.cs) (VB: [Default.aspx.vb](./VB/WebSite/Default.aspx.vb))
<!-- default file list end -->
# ASPxGridView - How to hide a grid column on the client side without making a round-trip to the server
<!-- run online -->
**[[Run Online]](https://codecentral.devexpress.com/e4580/)**
<!-- run online end -->

<!-- default file list end -->

<p>This example demonstrates how to hide a grid column on the client side without making a round-trip to the server.</p><br />
<p>To accomplish this task, apply a dummy CSS class ('unitPriceColumn') to all column cells (header, data, edit, footer, group footer, and filter cells) in markup. Then, to show/hide these cells, just specify their <a href="http://www.w3schools.com/cssref/pr_class_display.asp"><u>'display'</u></a> style. Set it to the 'none' value to hide cells and to the 'table-cell' value to show cells. To specify a cell display style, I used a jQuerry CSS selector (using the 'unitPriceColumn' CSS class).</p>
## Documentation

<br/>
* [Access Columns](https://docs.devexpress.com/AspNet/3697/components/grid-view/concepts/data-representation-basics/columns/accessing-columns)
* [Grid View Examples](https://docs.devexpress.com/AspNet/3768/components/grid-view/examples)

## More Examples

- [Grid View for ASP.NET Web Forms - How to Display the Grid View in Full Screen Mode (100% Width and Height)](https://github.com/DevExpress-Examples/grid-in-full-screen-mode-in-aspnet-web-applications)
- [Grid View for ASP.NET Web Forms - How to Delete Selected Rows in a Grid](https://github.com/DevExpress-Examples/aspxgridview-delete-selected-rows)
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"runOnWeb": true,
"autoGenerateVb": true
"autoGenerateVb": false
}
Binary file added hide-a-column.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.