Click here to Skip to main content
15,886,003 members
Articles / Web Development / HTML

Add some Style to your DataGrids

Rate me:
Please Sign up or sign in to vote.
4.60/5 (31 votes)
5 Jul 2004CPOL4 min read 255.1K   4.4K   109  
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)


Written By
Web Developer
United States United States
Steve is a software developer working in Minneapolis, MN.

Comments and Discussions