Click here to Skip to main content
11,409,532 members (58,672 online)
Click here to Skip to main content
Add your own
alternative version

Add some Style to your DataGrids

, 5 Jul 2004 CPOL
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" >
<HTML>
	<HEAD>
		<title>WebForm1</title>
		<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
		<meta content="C#" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" 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">
	</HEAD>
	<body>
		<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>
			</asp:datagrid>
			<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>
			</asp:DataGrid></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)

Share

About the Author

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

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