Click here to Skip to main content
15,893,564 members
Articles / Web Development / ASP.NET

Show / Hide GridView Columns in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.82/5 (17 votes)
12 Nov 2009CPOL4 min read 315.7K   5.1K   61  
Give users the ability to show or hide GridView columns as they require.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ShowHideGridViewColumnsClient.aspx.cs" Inherits="ShowHideGridViewColumnsClient" %>

<!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>Show / Hide Gridview Columns on the Client Side</title>
    <script src="scr/ShowHideColumns.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server">
        <h3>Show / Hide Gridview Columns on the Client Side</h3>
        <a class="printHideMe" href="Default.aspx">Back to Menu</a>
        <p class="description">
            Try clicking on the minus symbols in the GridView column headers.
            <br />Use the dropdown list to show the columns again.
            <br />Try "Print Preview" in your browser to see how the page will print.
        </p> 
        <div>
            <asp:GridView ID="GridView1" runat="server" 
                OnRowCreated="GridView1_RowCreated">
                <HeaderStyle CssClass="gvHeader" />
                <RowStyle CssClass="gvRow" />
            </asp:GridView>
            <asp:Literal ID="GridView1ShowHideColumns" runat="server"></asp:Literal>
        </div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Ireland Ireland
I have been designing and developing business solutions for the aviation, financial services, healthcare and telecommunications industries since 1999. My experience covers a wide range of technologies and I have delivered a variety of web and mobile based solutions.

Comments and Discussions