-
Notifications
You must be signed in to change notification settings - Fork 0
/
add-elegant-style-to-aspnet-webforms-gridview-control.html
212 lines (193 loc) · 17.7 KB
/
add-elegant-style-to-aspnet-webforms-gridview-control.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!DOCTYPE html>
<html lang="en">
<head>
<link href='//fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,700,400italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="http://www.emadmokhtar.com/theme/stylesheet/style.min.css">
<link rel="stylesheet" type="text/css" href="http://www.emadmokhtar.com/theme/stylesheet/pygments.min.css">
<link rel="stylesheet" type="text/css" href="http://www.emadmokhtar.com/theme/stylesheet/font-awesome.min.css">
<link href="http://www.emadmokhtar.com/feeds/all.atom.xml" type="application/atom+xml" rel="alternate" title="Emad Mokhtar's Framework Atom">
<link href="http://www.emadmokhtar.com/feeds/all.rss.xml" type="application/rss+xml" rel="alternate" title="Emad Mokhtar's Framework RSS">
<link rel="shortcut icon" href="http://www.emadmokhtar.com/images/favicon.ico" type="image/x-icon">
<link rel="icon" href="http://www.emadmokhtar.com/images/favicon.ico" type="image/x-icon">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="robots" content="" />
<meta name="author" content="EmadMokhtar" />
<meta name="description" content="We are developers whom use the left side of our brains that why we suck in designing; we’ll use the already exist styles while developing ASP.NET web application, that what we’ll do if we don’t have a designer in our team, but thanks for the CSS framework over the internet which make our like more easier. Nowadays I’m playing with Twitter Bootstrap CSS framework and I find myself create very neat and awesome looking ASP.NET applications by just using the already defined CSS classes in the framework, it’s so easy and the documentation is easy to understand and readable, you can find the documentation right here. So let’s get into the business, the most commonly used ASP.NET Control GridView is very ugly if you don’t apply a style to it, it’ll look like an awful HTML table with bunch of rows and columns, sure you can use the ready made styles “Auto Format” created by Microsoft team, but also you can apply much better style to it, let’s find how. I’ll show you how to apply 2 styles to GridView: Twitter Bootstrap. ASP.NET Dynamic Data. Twitter …" />
<meta name="keywords" content="aspnet, gridview">
<meta property="og:site_name" content="Emad Mokhtar's Framework"/>
<meta property="og:title" content="Add elegant style to ASP.NET WebForms GridView control"/>
<meta property="og:description" content="We are developers whom use the left side of our brains that why we suck in designing; we’ll use the already exist styles while developing ASP.NET web application, that what we’ll do if we don’t have a designer in our team, but thanks for the CSS framework over the internet which make our like more easier. Nowadays I’m playing with Twitter Bootstrap CSS framework and I find myself create very neat and awesome looking ASP.NET applications by just using the already defined CSS classes in the framework, it’s so easy and the documentation is easy to understand and readable, you can find the documentation right here. So let’s get into the business, the most commonly used ASP.NET Control GridView is very ugly if you don’t apply a style to it, it’ll look like an awful HTML table with bunch of rows and columns, sure you can use the ready made styles “Auto Format” created by Microsoft team, but also you can apply much better style to it, let’s find how. I’ll show you how to apply 2 styles to GridView: Twitter Bootstrap. ASP.NET Dynamic Data. Twitter …"/>
<meta property="og:locale" content="en_US"/>
<meta property="og:url" content="http://www.emadmokhtar.com/add-elegant-style-to-aspnet-webforms-gridview-control.html"/>
<meta property="og:type" content="article"/>
<meta property="article:published_time" content="2012-07-11 11:45:00+03:00"/>
<meta property="article:modified_time" content=""/>
<meta property="article:author" content="http://www.emadmokhtar.com/author/emadmokhtar.html">
<meta property="article:section" content="ASP.NET"/>
<meta property="article:tag" content="aspnet"/>
<meta property="article:tag" content="gridview"/>
<meta property="og:image" content="http://www.emadmokhtar.com/images/profile.jpg">
<title>Emad Mokhtar's Framework – Add elegant style to ASP.NET WebForms GridView control</title>
</head>
<body>
<aside>
<div>
<a href="http://www.emadmokhtar.com">
<img src="http://www.emadmokhtar.com/images/profile.jpg" alt="" title="">
</a>
<h1><a href="http://www.emadmokhtar.com"></a></h1>
<p>Geek developer who's in search of code perfection.</p>
<nav>
<ul class="list">
<li><a href="http://www.emadmokhtar.com">Blog</a></li>
<li><a href="http://www.emadmokhtar.com/pages/podcasts.html#podcasts">Podcasts</a></li>
<li><a href="http://www.emadmokhtar.com/pages/projects.html#projects">Projects</a></li>
<li><a href="https://emadmokhtar.github.io/resume" target="_blank">Resume</a></li>
</ul>
</nav>
<ul class="social">
<li><a class="sc-envelope-o" href="mailto:emad@emadmokhtar.com" target="_blank"><i class="fa fa-envelope-o"></i></a></li>
<li><a class="sc-github" href="https://www.github.com/EmadMokhtar" target="_blank"><i class="fa fa-github"></i></a></li>
<li><a class="sc-linkedin" href="https://www.linkedin.com/in/emadmokhtar/" target="_blank"><i class="fa fa-linkedin"></i></a></li>
<li><a class="sc-stack-overflow" href="http://stackoverflow.com/users/373051/emad-mokhtar" target="_blank"><i class="fa fa-stack-overflow"></i></a></li>
<li><a class="sc-facebook" href="https://www.facebook.com/emadmokhtarframework/" target="_blank"><i class="fa fa-facebook"></i></a></li>
<li><a class="sc-twitter" href="https://twitter.com/emadmokhtar" target="_blank"><i class="fa fa-twitter"></i></a></li>
</ul>
</div>
</aside>
<main>
<nav>
<a href="http://www.emadmokhtar.com">Home</a>
<a href="https://emadmokhtar.github.io/resume">Resume</a>
<a href="http://www.emadmokhtar.com/feeds/all.atom.xml">Atom</a>
<a href="http://www.emadmokhtar.com/feeds/all.rss.xml">RSS</a>
</nav>
<article>
<header>
<h1 id="add-elegant-style-to-aspnet-webforms-gridview-control">Add elegant style to ASP.NET WebForms GridView control</h1>
<p>Posted on Wed 11 July 2012 in <a href="http://www.emadmokhtar.com/category/aspnet.html">ASP.NET</a> <b>Read in 3 min.</b></p>
</header>
<div>
<p><img alt="5628591299_8d5839c072" src="http://www.emadmokhtar.com/images/5628591299_8d5839c072.jpg"></p>
<p>We are developers whom use the left side of our brains that why we suck in
designing; we’ll use the already exist styles while developing ASP.NET
web application, that what we’ll do if we don’t have a designer in our
team, but thanks for the CSS framework over the internet which make our
like more easier.</p>
<p>Nowadays I’m playing with <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a> CSS framework and I find myself create very neat and awesome looking ASP.NET applications by just using the already defined CSS classes in the framework, it’s so easy and the documentation is easy to understand and readable, you can find the documentation right
<a href="http://twitter.github.com/bootstrap/base-css.html">here</a>.</p>
<p>So let’s get into the business, the most commonly used ASP.NET Control
<strong>GridView</strong> is very ugly if you don’t apply a style to it, it’ll look
like an awful HTML table with bunch of rows and columns, sure you can
use the ready made styles “Auto Format” created by Microsoft team, but
also you can apply much better style to it, let’s find
how.<img alt="SNAG-0089" src="http://www.emadmokhtar.com/images/SNAG-0089.png"></p>
<p>I’ll show you how to apply 2 styles to GridView:</p>
<ol>
<li>Twitter Bootstrap.</li>
<li>ASP.NET Dynamic Data.</li>
</ol>
<h3>Twitter Bootstrap:</h3>
<p>I mentioned above nowadays I’m playing with Twitter Bootstrap and I love
its <a href="http://twitter.github.com/bootstrap/base-css.html#tables">Table
style</a>, it’s
very simple and neat and have many style can be used separately or make
a combination of them. I love to use the full combination of them and it
can be applied to the <strong>GridView</strong> by assign the <strong>CssClass</strong> property
to Twitter Bootstrap CSS classes like this:</p>
<div class="highlight"><pre><span></span><span class="p"><</span><span class="nt">asp:GridView</span> <span class="na">ID</span><span class="o">=</span><span class="s">"GridView1"</span> <span class="na">runat</span><span class="o">=</span><span class="s">"server"</span> <span class="na">AutoGenerateColumns</span><span class="o">=</span><span class="s">"False"</span>
<span class="na">DataSourceID</span><span class="o">=</span><span class="s">"XmlDataSource1"</span>
<span class="na">CssClass</span><span class="o">=</span><span class="s">"table table-striped table-bordered table-condensed"</span><span class="p">></span>
<span class="p"><</span><span class="nt">Columns</span><span class="p">></span>
<span class="p"><</span><span class="nt">asp:BoundField</span> <span class="na">DataField</span><span class="o">=</span><span class="s">"id"</span> <span class="na">HeaderText</span><span class="o">=</span><span class="s">"id"</span> <span class="na">SortExpression</span><span class="o">=</span><span class="s">"id"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">asp:BoundField</span> <span class="na">DataField</span><span class="o">=</span><span class="s">"name"</span> <span class="na">HeaderText</span><span class="o">=</span><span class="s">"name"</span> <span class="na">SortExpression</span><span class="o">=</span><span class="s">"name"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">asp:BoundField</span> <span class="na">DataField</span><span class="o">=</span><span class="s">"phone"</span> <span class="na">HeaderText</span><span class="o">=</span><span class="s">"phone"</span> <span class="na">SortExpression</span><span class="o">=</span><span class="s">"phone"</span> <span class="p">/></span>
<span class="p"></</span><span class="nt">Columns</span><span class="p">></span>
<span class="p"></</span><span class="nt">asp:GridView</span><span class="p">></span>
</pre></div>
<p>Here is the result:</p>
<p><img alt="SNAG-0091" src="http://www.emadmokhtar.com/images/SNAG-0091.png"></p>
<p>You can use style you like you can check the Table styles and make your
combination or use only one CSS class.</p>
<p>You can install Twitter Bootstrap to your solution from NuGet. Go to
Tools –> Library Package Manager –> Manage NuGet Packages for
solutions… NuGet package manager window will open, search for Twitter
Bootstrap and Install it.</p>
<p><img alt="SNAG-0087" src="http://www.emadmokhtar.com/images/SNAG-0087.png"></p>
<h3>ASP.NET Dynamic Data:</h3>
<p>One day I was checking <a href="http://msdn.microsoft.com/en-us/library/ee845452.aspx">ASP.NET Dynamic
Data</a>, I built
and started the project, and then I saw a very beautiful <strong>GridView.</strong> I
start to dig in the aspx file on how ASP.NET team made this <strong>GridView</strong>
beautiful like that, finally I found they are using a CSS specially made
for Dynamic Data, I grab it and applied it to another demo project has a
<strong>GridView</strong> and took care of the Image file used in header’s
background.</p>
<p>Here is the <strong>GridView</strong> control, take a look on <strong>CssClass</strong>,
<strong>RowStyle-CssClass</strong>, and <strong>HeaderStyle-CssClass</strong> properties:</p>
<div class="highlight"><pre><span></span><span class="p"><</span><span class="nt">asp:GridView</span> <span class="na">ID</span><span class="o">=</span><span class="s">"GridView"</span> <span class="na">runat</span><span class="o">=</span><span class="s">"server"</span> <span class="na">AutoGenerateColumns</span><span class="o">=</span><span class="s">"False"</span> <span class="na">DataSourceID</span><span class="o">=</span><span class="s">"XmlDataSource"</span>
<span class="na">CssClass</span><span class="o">=</span><span class="s">"DDGridView"</span> <span class="na">RowStyle-CssClass</span><span class="o">=</span><span class="s">"td"</span> <span class="na">HeaderStyle-CssClass</span><span class="o">=</span><span class="s">"th"</span> <span class="na">CellPadding</span><span class="o">=</span><span class="s">"6"</span><span class="p">></span>
<span class="p"><</span><span class="nt">Columns</span><span class="p">></span>
<span class="p"><</span><span class="nt">asp:BoundField</span> <span class="na">DataField</span><span class="o">=</span><span class="s">"id"</span> <span class="na">HeaderText</span><span class="o">=</span><span class="s">"id"</span> <span class="na">SortExpression</span><span class="o">=</span><span class="s">"id"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">asp:BoundField</span> <span class="na">DataField</span><span class="o">=</span><span class="s">"name"</span> <span class="na">HeaderText</span><span class="o">=</span><span class="s">"name"</span> <span class="na">SortExpression</span><span class="o">=</span><span class="s">"name"</span> <span class="p">/></span>
<span class="p"><</span><span class="nt">asp:BoundField</span> <span class="na">DataField</span><span class="o">=</span><span class="s">"phone"</span> <span class="na">HeaderText</span><span class="o">=</span><span class="s">"phone"</span> <span class="na">SortExpression</span><span class="o">=</span><span class="s">"phone"</span> <span class="p">/></span>
<span class="p"></</span><span class="nt">Columns</span><span class="p">></span>
<span class="p"></</span><span class="nt">asp:GridView</span><span class="p">></span>
</pre></div>
<p>Here is the result:</p>
<p><img alt="SNAG-0092" src="http://www.emadmokhtar.com/images/SNAG-0092.png"></p>
<p>I’ve created a Demo project, you can download it from
<a href="https://github.com/EmadMokhtar/ASPNETGridViewWithStyle">GitHub</a>.</p>
<p>Happy Developing Folks!</p>
</div>
<div class="tag-cloud">
<p>
<a href="http://www.emadmokhtar.com/tag/aspnet.html">aspnet</a>
<a href="http://www.emadmokhtar.com/tag/gridview.html">gridview</a>
</p>
</div>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'emadmokhtarsframework';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
</article>
<footer>
<p>© Emad Mokhtar </p>
<p>Built using <a href="http://getpelican.com" target="_blank">Pelican</a> - <a href="https://github.com/alexandrevicenzi/flex" target="_blank">Flex</a> theme by <a href="http://alexandrevicenzi.com" target="_blank">Alexandre Vicenzi</a></p> </footer>
</main>
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-11401860-2', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BlogPosting",
"name": "Add elegant style to ASP.NET WebForms GridView control",
"headline": "Add elegant style to ASP.NET WebForms GridView control",
"datePublished": "2012-07-11 11:45:00+03:00",
"dateModified": "",
"author": {
"@type": "Person",
"name": "EmadMokhtar",
"url": "http://www.emadmokhtar.com/author/emadmokhtar.html"
},
"image": "http://www.emadmokhtar.com/images/profile.jpg",
"url": "http://www.emadmokhtar.com/add-elegant-style-to-aspnet-webforms-gridview-control.html",
"description": "We are developers whom use the left side of our brains that why we suck in designing; we’ll use the already exist styles while developing ASP.NET web application, that what we’ll do if we don’t have a designer in our team, but thanks for the CSS framework over the internet which make our like more easier. Nowadays I’m playing with Twitter Bootstrap CSS framework and I find myself create very neat and awesome looking ASP.NET applications by just using the already defined CSS classes in the framework, it’s so easy and the documentation is easy to understand and readable, you can find the documentation right here. So let’s get into the business, the most commonly used ASP.NET Control GridView is very ugly if you don’t apply a style to it, it’ll look like an awful HTML table with bunch of rows and columns, sure you can use the ready made styles “Auto Format” created by Microsoft team, but also you can apply much better style to it, let’s find how. I’ll show you how to apply 2 styles to GridView: Twitter Bootstrap. ASP.NET Dynamic Data. Twitter …"
}
</script></body>
</html>