Click here to Skip to main content
12,999,417 members (84,187 online)
Click here to Skip to main content


108 bookmarked
Posted 5 Jul 2004

Add some Style to your DataGrids

, 5 Jul 2004
Use CSS style sheets to apply re-usable styles across all of your grids.
<%@ Page language="c#" Codebehind="MyGrid.aspx.cs" AutoEventWireup="false" Inherits="GridStyles.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="C#" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="" name="vs_targetSchema">
		<LINK title="Tan" media="screen" href="styles.css" type="text/css" rel="stylesheet">
		<LINK title="Blue" media="screen" href="styles2.css" type="text/css" rel="stylesheet">
		<LINK title="print" media="print" href="printstyles.css" type="text/css" rel="stylesheet">
		<form id="Form1" method="post" runat="server">
			<h1>Table 1 - no sorting or paging</h1>
			<asp:datagrid id="DataGrid1" runat="server" CssClass="Grid">
				<HeaderStyle CssClass="GridHeader"></HeaderStyle>
				<ItemStyle CssClass="GridItem"></ItemStyle>
				<AlternatingItemStyle CssClass="GridAltItem"></AlternatingItemStyle>
			<h1>Table 2 - with sorting and paging</h1>
			<asp:DataGrid id="DataGrid2" runat="server" AllowSorting="True" CssClass="Grid" AllowPaging="True">
				<AlternatingItemStyle CssClass="GridAltItem"></AlternatingItemStyle>
				<ItemStyle CssClass="GridItem"></ItemStyle>
				<HeaderStyle CssClass="GridHeader"></HeaderStyle>
				<PagerStyle CssClass="GridPager"></PagerStyle>

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.


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


About the Author

Steven Campbell
Web Developer
United States United States
Steve is a software developer working in Minneapolis, MN.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170624.1 | Last Updated 6 Jul 2004
Article Copyright 2004 by Steven Campbell
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid