<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kerry D. Wong &#187; GridView</title>
	<atom:link href="http://www.kerrywong.com/tag/gridview/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kerrywong.com</link>
	<description></description>
	<lastBuildDate>Fri, 03 Sep 2010 00:51:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Extending the GridView — Part IV</title>
		<link>http://www.kerrywong.com/2008/08/17/extending-the-gridview-%e2%80%94-part-iv/</link>
		<comments>http://www.kerrywong.com/2008/08/17/extending-the-gridview-%e2%80%94-part-iv/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 02:56:42 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C Sharp (C#)]]></category>
		<category><![CDATA[GridView]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/2008/08/17/extending-the-gridview-%e2%80%94-part-iv/</guid>
		<description><![CDATA[In the previous three posts(I, II, III), I showed you how to inherit from GridView control to create an extended control that can bind to a generic list of objects. In this final post of the series, I will show you a simple example to illustrate how to use the GridViewEx control. 4. Putting it [...]]]></description>
			<content:encoded><![CDATA[<p>In the previous three posts(<a href="/2008/08/08/extending-the-gridview-part-i/">I</a>,<a href="/2008/08/15/extending-the-gridview-&mdash;-part-ii/"> II</a>, <a href="/2008/08/16/extending-the-gridview-&mdash;-part-iii/">III</a>), I showed you how to inherit from GridView control to create an extended control that can bind to a generic list of objects. In this final post of the series, I will show you a simple example to illustrate how to use the GridViewEx control.<span id="more-327"></span></p>
<p><strong>4. Putting it all together</strong></p>
<p>In fact, using an extended control isn&#8217;t that much different than using the stock control thanks to inheritance.&nbsp; For the most part, the extended control works exactly the same as the standard GridView control. I wanted to just touch base on a couple of places that a lot of people are having problem with.</p>
<p>First is the asp tag prefix issue. By default, all the custom controls (*.ascx) will automatically show up in the Toolbox strip within Vistuo Studio. So using the extended GridView is a simple matter of drag and drop. However, the default prefix for custom control is <em>cc1</em>, and depending on how many pre-existing custom controls there are on a page, it could be <em>cc{num}</em>. This becomes hard for replacing existing GridViews with the extended GridViewEx. To resolve this naming issue, we can register the assembly which contains the extended control within system.web-&gt;pages-&gt;controls tag in web.config:</p>
<p>&nbsp;</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: rgb(163, 21, 21);">add</span><span style="color: blue;"> </span><span style="color: red;">assembly</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">ExtendedGridView</span>&quot;<span style="color: blue;"> </span><span style="color: red;">namespace</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">ExtendedGridView</span>&quot;<span style="color: blue;"> </span><span style="color: red;">tagPrefix</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">ExtendedGridView</span>&quot;<span style="color: blue;">/&gt;</span></div>
</div>
<p>With this prefix defined, we can use the tag ExtendedGridView wherever GridView is expected. By registering the prefix, we have also provided the solution to a second problem people often run into when using extended web controls&#8211;namely the ability to &quot;skin&quot; the control. With the extended control prefix registered, we can now create skins the same way as we do with other controls. For instance, my default.skin might look like:</p>
<p>&nbsp;</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div style="margin: 0px;"><span style="color: blue;">&lt;</span><span style="color: rgb(163, 21, 21);">ExtendedGridView:GridViewEx</span><span style="color: blue;"> </span><span style="color: red;">runat</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">server</span>&quot;<span style="color: blue;"> </span><span style="color: red;">SkinID</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">Professional</span>&quot;<span style="color: blue;"> </span><span style="color: red;">Font-Name</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">Arial</span>&quot;<span style="color: blue;"> </span><span style="color: red;">Font-Size</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">9pt</span>&quot;<span style="color: blue;"> </span><span style="color: red;">Cellpadding</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">1</span>&quot;<span style="color: blue;"> </span><span style="color: red;">HeaderStyle-BackColor</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">Gray</span>&quot;<span style="color: blue;"> </span><span style="color: red;">HeaderStyle-ForeColor</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">White</span>&quot;<span style="color: blue;"> </span><span style="color: red;">AlternatingRowStyle-BackColor</span><span style="color: blue;">=</span>&quot;<span style="color: blue;">LightGray</span>&quot;<span style="color: blue;"> /&gt;</span></div>
</div>
<p>In this way, the theming issue of the extended GridView is addressed.</p>
<p>The code for the code behind page to display the extended GridView is trivial:</p>
<p>&nbsp;</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> Page_Load(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridViewPager1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SelectedIndexChanged <span style="color: rgb(128, 128, 192); font-weight: bold;">+=</span> GridViewEx1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>PagerSelectedIndexChanged;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridViewEx1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataSourceChanged <span style="color: rgb(128, 128, 192); font-weight: bold;">+=</span> GridViewPager1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>GridViewDataSourceChanged;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (<span style="color: rgb(128, 128, 192); font-weight: bold;">!</span>Page<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>IsPostBack)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">SampleDataProvider</span> provider <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">SampleDataProvider</span>();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridViewEx1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> provider<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>GetSampleData();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridViewEx1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> CBSelected_CheckedChanged(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">CheckBox</span> cbSel <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> sender <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">CheckBox</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (cbSel <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">DataControlFieldCell</span> cellObj <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> cbSel<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parent <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">DataControlFieldCell</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewRow</span> rowObj <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> cellObj<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parent <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewRow</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewEx</span> gv <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> rowObj<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parent<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parent <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewEx</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">ItemVal</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span> v <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> GridViewEx1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataSource <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">ItemVal</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; v[gv<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Index(rowObj<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>RowIndex)]<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Selected <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> cbSel<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Checked;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridViewEx1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> v;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridViewEx1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
</div>
<p>As you can see,&nbsp; the code is pretty much in line with what we would use for a typical GridView control. When the page is posted back, we set the DataSource and bind the data to the grid. Everything else happens transparently behind the scene. To illustrate the capability of GridViewEx, I included a CheckBox at the end of each row, whenever the check status is changed (CBSelected_CheckedChanged) we dynamically obtain the reference to the GridViewEx object (as an alternative, we could have used the actual control (GridViewEx1) instead of going through the trouble of dynamically converting if from the sender object since GridViewEx1 exists at compile time. Should the control be created dynamically, the code here will come in handy). Please pay special attention to how the checked state is determined. Because paging might be involved when the bound list has more entries than can be displayed, the current row index on the screen might not be the same as the row index in the list. To simplify coding, I created an Index function within GridViewEx to translate the selected row index into what is stored in the list.</p>
<p align="center"><img src="/blog/wp-content/uploads/2008/08/gridviewex.jpg" alt="" /></p>
<p>The code samples provided in this series can be downloaded <a href="/blog/wp-content/uploads/2008/08/extendingthegridview.zip">here</a>.</p>
<p>Of course, there are a lot more fancy things you can do with the grid or with any objects in that matter. The only limit is your imagination&#8230;</p>
<p><strong>See also</strong></p>
<div><a href="/2008/08/08/extending-the-gridview-part-i/">Extending the GridView &mdash; Part I</a></div>
<div><a href="/2008/08/15/extending-the-gridview-&mdash;-part-ii/">Extending the GridView &mdash; Part II</a></div>
<div><a href="/2008/08/16/extending-the-gridview-&mdash;-part-iii/">Extending the GridView &mdash; Part III</a></div>
<div><a href="/2008/08/17/extending-the-gridview-&mdash;-part-iv/">Extending the GridView &mdash; Part IV</a></div>
<p>Code Download: <a href="/blog/wp-content/uploads/2008/08/extendingthegridview.zip">ExtendingTheGridView.zip</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2008/08/17/extending-the-gridview-%e2%80%94-part-iv/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extending the GridView — Part III</title>
		<link>http://www.kerrywong.com/2008/08/16/extending-the-gridview-%e2%80%94-part-iii/</link>
		<comments>http://www.kerrywong.com/2008/08/16/extending-the-gridview-%e2%80%94-part-iii/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 00:04:44 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C Sharp (C#)]]></category>
		<category><![CDATA[GridView]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/2008/08/16/extending-the-gridview-%e2%80%94-part-iii/</guid>
		<description><![CDATA[In Part II, I showed you how to extend the GridView control so that we can bind a generic list to it. Because GridViewEx inherits from GridView, it has all the functionalities GridView has (i.e. paging). Sometimes, it is desirable to change the number of items displayed on a page dynamically, to accommodate this, we [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="/2008/08/15/extending-the-gridview-&mdash;-part-ii/">Part II</a>, I showed you how to extend the GridView control so that we can bind a generic list to it. Because GridViewEx inherits from GridView, it has all the functionalities GridView has (i.e. paging). Sometimes, it is desirable to change the number of items displayed on a page dynamically, to accommodate this, we will create a GridViewPager control (ascx).<span id="more-326"></span></p>
<p><strong>3. GridViewPager</strong></p>
<p>&nbsp;Here is the code for GridViewPager:</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">partial</span> <span style="color: blue; font-weight: bold;">class</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewPager</span> : System<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Web<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>UI<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span><span style="color: rgb(43, 145, 175); font-weight: bold;">UserControl</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">delegate</span> <span style="color: blue; font-weight: bold;">void</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">SelectedIndexChangedHandler</span>(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: blue; font-weight: bold;">int</span> pageSize);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">event</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">SelectedIndexChangedHandler</span> SelectedIndexChanged;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: blue; font-weight: bold;">bool</span> _visible <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">false</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: blue; font-weight: bold;">int</span> _pageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: teal;">10</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">bool</span> Visible</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (ViewState[UniqueID] <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _visible <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">true</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">bool</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>TryParse(ViewState[<span style="color: blue; font-weight: bold;">this</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>UniqueID]<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>ToString(), <span style="color: blue; font-weight: bold;">out</span> _visible);</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> _visible;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _visible <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[UniqueID] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> _visible;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (_visible)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MainPanel<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Visible <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">true</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; MainPanel<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Visible <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">false</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">int</span> PageSize</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (ViewState[<span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Concat(UniqueID, <span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;PageSize&quot;</span>)] <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _pageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">int</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parse(DropDownItemsPerPage<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SelectedValue);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _pageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">int</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parse(ViewState[<span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Concat(UniqueID, <span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;PageSize&quot;</span>)]<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>ToString());</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> _pageSize;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _pageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[<span style="color: rgb(43, 145, 175); font-weight: bold;">String</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Concat(UniqueID, <span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;PageSize&quot;</span>)] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">void</span> OnInit(<span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DropDownItemsPerPage<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SelectedIndexChanged <span style="color: rgb(128, 128, 192); font-weight: bold;">+=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">EventHandler</span>(DropDownItemsPerPage_SelectedIndexChanged);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">base</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>OnInit(e);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> DropDownItemsPerPage_SelectedIndexChanged(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">int</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parse(DropDownItemsPerPage<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SelectedValue);</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (SelectedIndexChanged <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SelectedIndexChanged(sender, PageSize);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> Page_Load(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (<span style="color: rgb(128, 128, 192); font-weight: bold;">!</span>Page<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>IsPostBack)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DropDownItemsPerPage<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> This method links to the DataSourceChangedEvent defined in GridViewEx so that</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> we can decide whether or not to show the pager depending on whether the list</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> to be bound is empty.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;param name=&quot;sender&quot;&gt;</span><span style="color: green;">sender object</span><span style="color: gray;">&lt;/param&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;param name=&quot;isEmpty&quot;&gt;</span><span style="color: green;">whether the list to be bound is empty</span><span style="color: gray;">&lt;/param&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">void</span> GridViewDataSourceChanged(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: blue; font-weight: bold;">bool</span> isEmpty)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (isEmpty)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Visible <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">false</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Visible <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">true</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</div>
</div>
<p>As you can see, the pager control is quite simple. It communicates with GridViewEx control by the SelectedIndexChanged event. Depending on whether the state of number of items per page needs to persist between post backs, either ViewState or SessionState can be used.</p>
<p><strong>See also</strong></p>
<div><a href="/2008/08/08/extending-the-gridview-part-i/">Extending the GridView &mdash; Part I</a></div>
<div><a href="/2008/08/15/extending-the-gridview-&mdash;-part-ii/">Extending the GridView &mdash; Part II</a></div>
<div><a href="/2008/08/16/extending-the-gridview-&mdash;-part-iii/">Extending the GridView &mdash; Part III</a></div>
<div><a href="/2008/08/17/extending-the-gridview-&mdash;-part-iv/">Extending the GridView &mdash; Part IV</a></div>
<p>Code Download: <a href="/blog/wp-content/uploads/2008/08/extendingthegridview.zip">ExtendingTheGridView.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2008/08/16/extending-the-gridview-%e2%80%94-part-iii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending the GridView — Part II</title>
		<link>http://www.kerrywong.com/2008/08/15/extending-the-gridview-%e2%80%94-part-ii/</link>
		<comments>http://www.kerrywong.com/2008/08/15/extending-the-gridview-%e2%80%94-part-ii/#comments</comments>
		<pubDate>Sat, 16 Aug 2008 00:10:53 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C Sharp (C#)]]></category>
		<category><![CDATA[GridView]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/2008/08/15/extending-the-gridview-%e2%80%94-part-ii/</guid>
		<description><![CDATA[In Part I, I talked about why we needed to extend the GridView and some of the benefit in doing that. In this post, I will discuss how to extend the standard GridView control to take advantage of binding to the type safe value objects mentioned previously. 2. GridViewEx To make the binding as generic [...]]]></description>
			<content:encoded><![CDATA[<p>In<a href="/2008/08/08/extending-the-gridview-part-i/"> Part I</a>, I talked about why we needed to extend the GridView and some of the benefit in doing that. In this post, I will discuss how to extend the standard GridView control to take advantage of binding to the type safe value objects mentioned previously.<span id="more-325"></span></p>
<p><strong>2. GridViewEx</strong><br />
To make the binding as generic as possible, there are pretty much two ways. One way is to bind to an object collection of typed value objects. Since all value objects can be cast into objects, we could manipulate them generically. And because value objects are typically consisted of simple types, we could encapsulate all the operations needed for the GridView within the extended GridView itself. </p>
<p>Another solution is to utilize generics in .Net 2.0 and above. One obvious advantage is that the type information is not lost at any point of the object manipulation and thus a lot of small mistakes can be caught at compile time. This approach does have its draw backs. As you will see, because the purpose of generic types are to eliminate casting introduced by object containers, we have to change the extended GridView to accommodate the type of objects we are binding to the list whenever a new generic type is introduced. This of course requires the changing of the extended GridView control itself whenever we add a new generic type and thus might not be as convenient as the pure object oriented approach mentioned previously. However, weighing both the advantages and disadvantages I personally think this approach is more attractive. </p>
<p>So here, I will show you how to extend the GridView to handle generic lists.</p>
<p>GridViewEx inherits from GridView. We override the DataSource property so that we get a chance to inspect it before the databinding actually taking place. This gives us an opportunity to test whether the data source to be bound is empty. We use this information to decide whether to show the pager or not as you will see in a later post.</p>
<p>The initialization routine (OnInit) is overridden to setup some property values and hook up some events so that we provide row editing functionalities.</p>
<p>The RowEditing, PageSelectedIndexChanged and some of the other overridden functions are handled in a pretty standard way. To demonstrate how easy it is to add new functionality to the GridView, I added an event handler for RowDataBound. The purpose of the code for this RowDataBound event is to check if the CheckBox on a particular row is checked and if so, the background color of that row is changed. This behavior is particularly helpful for giving a visual cue to the end user which row of data he/she is currently dealing with. </p>
<p>When each row is created, OnRowCreated method is called, here we determine whether the row being created is the header or not and if so, we add an arrow to indicate the current sorting option depending on how the grid is currently sorted. If the row being created is a data row, we add some nice touch so that the data row becomes highlighted when mouse moves pass it.</p>
<p>We also have to override the OnSorting function to handle our generic lists. This is where we need to add the supported list types (see comments in code). For additional generic list types, we simply need to add three lines for each type of the list. While this might not be as convenient as using generic objects, all the changes are kept in a central place so that adding/removing types should not be an issue.</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div style="margin: 0px;"><span style="color: blue; font-weight: bold;">namespace</span> ExtendedGridView</div>
<div style="margin: 0px;">{</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Extended GridView</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Supports paging/sorting using a customized object data source.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> http://www.kerrywong.com/</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">class</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewEx</span> : <span style="color: rgb(43, 145, 175); font-weight: bold;">GridView</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">delegate</span> <span style="color: blue; font-weight: bold;">void</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">DataSourceChangedEventHandler</span>(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: blue; font-weight: bold;">bool</span> isEmpty);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">event</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">DataSourceChangedEventHandler</span> DataSourceChanged;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> A readonly unique ID for the current view.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">string</span> CurrentViewID</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Concat(<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;CurrentView_&quot;</span>, UniqueID); }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Current page id when paging is used.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> To remember the page index user selected, a session variable is used.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">int</span> CurrentPageID</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (<span style="color: rgb(43, 145, 175); font-weight: bold;">HttpContext</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Current <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">&amp;&amp;</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">HttpContext</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Current<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Session <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (<span style="color: rgb(43, 145, 175); font-weight: bold;">HttpContext</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Current<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Session[<span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Concat(<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;CurrentPageID_&quot;</span>, UniqueID)] <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">-</span><span style="color: teal;">1</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> <span style="color: blue; font-weight: bold;">int</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Parse(<span style="color: rgb(43, 145, 175); font-weight: bold;">HttpContext</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Current<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Session[<span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Concat(<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;CurrentPageID_&quot;</span>, UniqueID)]<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>ToString());</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">-</span><span style="color: teal;">1</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (<span style="color: rgb(43, 145, 175); font-weight: bold;">HttpContext</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Current <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">&amp;&amp;</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">HttpContext</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Current<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Session <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">HttpContext</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Current<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Session[<span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Concat(<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;CurrentPageID_&quot;</span>, UniqueID)] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Overrides the data source property, so that we get a chance to test whether the source </span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> being bound contains data or not.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> This is used to communicate with the pager so that for an empty list no pager is shown.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">object</span> DataSource</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (ViewState[CurrentViewID] <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> ViewState[CurrentViewID];</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> <span style="color: blue; font-weight: bold;">base</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataSource;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">base</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[CurrentViewID] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (<span style="color: blue; font-weight: bold;">value</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (DataSourceChanged <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataSourceChanged(<span style="color: blue; font-weight: bold;">this</span>, <span style="color: blue; font-weight: bold;">true</span>);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (DataSourceChanged <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataSourceChanged(<span style="color: blue; font-weight: bold;">this</span>, <span style="color: blue; font-weight: bold;">false</span>);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Set up event handlers.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">void</span> OnInit(System<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span><span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AllowPaging <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">true</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AllowSorting <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">true</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">this</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>AutoGenerateColumns <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">false</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: teal;">10</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RowCancelingEdit <span style="color: rgb(128, 128, 192); font-weight: bold;">+=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">GridViewCancelEditEventHandler</span>(GridViewEx_RowCancelingEdit);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RowDataBound <span style="color: rgb(128, 128, 192); font-weight: bold;">+=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">GridViewRowEventHandler</span>(GridViewEx_RowDataBound);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; RowEditing <span style="color: rgb(128, 128, 192); font-weight: bold;">+=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">GridViewEditEventHandler</span>(GridViewEx_RowEditing);</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">base</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>OnInit(e);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">void</span> OnPageIndexChanging(<span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewPageEventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PageIndex <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>NewPageIndex;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; CurrentPageID <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> PageIndex;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (ViewState[CurrentViewID] <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> ViewState[CurrentViewID];</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Handles the sort event.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Since the data source is a generic list, we need to cast the list</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> back to what ever type it is before we can sort. All the list types</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> need to be handled here (see comments below)</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">void</span> OnSorting(<span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewSortEventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;SortExpression&quot;</span>] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortExpression;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (ViewState[e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortExpression] <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortExpression] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortDirection;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortExpression] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> (<span style="color: olive; font-weight: bold;">SortDirection</span>)(<span style="color: teal;">1</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">-</span> (<span style="color: blue; font-weight: bold;">int</span>)ViewState[e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortExpression]);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortDirection <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> (<span style="color: olive; font-weight: bold;">SortDirection</span>)ViewState[e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortExpression];</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">object</span> o <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">null</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: green;">//This is where more list types can be added. </span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (ViewState[CurrentViewID] <span style="color: blue; font-weight: bold;">is</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">ItemVal</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">ItemVal</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span> l <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> ViewState[CurrentViewID] <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">ItemVal</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; l<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Sort(<span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">GenericComparer</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">ItemVal</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span>(e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortDirection, e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>SortExpression));</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; o <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> l;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">base</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>OnSorting(e);</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> o;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[CurrentViewID] <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> o;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">void</span> OnRowCreated(<span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewRowEventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">base</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>OnRowCreated(e);</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">&amp;&amp;</span> e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>RowType <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: olive; font-weight: bold;">DataControlRowType</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Header)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">foreach</span> (<span style="color: rgb(43, 145, 175); font-weight: bold;">TableCell</span> cell <span style="color: blue; font-weight: bold;">in</span> e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Cells)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (cell<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>HasControls())</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">LinkButton</span> button <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> cell<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Controls[<span style="color: teal;">0</span>] <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">LinkButton</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (button <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">Image</span> image <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">Image</span>();</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">string</span> sortExpression <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Empty;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: olive; font-weight: bold;">SortDirection</span> dir <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: olive; font-weight: bold;">SortDirection</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Ascending;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (ViewState[<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;SortExpression&quot;</span>] <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sortExpression <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> ViewState[<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;SortExpression&quot;</span>]<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>ToString();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dir <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> (<span style="color: olive; font-weight: bold;">SortDirection</span>)ViewState[sortExpression];</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (sortExpression <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: blue; font-weight: bold;">null</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">&amp;&amp;</span> sortExpression <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> button<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>CommandArgument)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (dir <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: olive; font-weight: bold;">SortDirection</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Ascending)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; image<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>ImageUrl <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;~/images/sort_asc.gif&quot;</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; image<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>ImageUrl <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;~/images/sort_desc.gif&quot;</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; cell<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Controls<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Add(image);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span> <span style="color: blue; font-weight: bold;">if</span> (e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>RowType <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: olive; font-weight: bold;">DataControlRowType</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>DataRow) <span style="color: green;">//Handles datarow highlighting on mouse move</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Attributes<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Add(<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;onmouseover&quot;</span>, <span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;this.originalstyle=this.style.backgroundColor;this.style.backgroundColor=&#8217;lightgreen&#8217;&quot;</span>);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Attributes<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Add(<span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;onmouseout&quot;</span>, <span style="color: rgb(163, 21, 21); font-weight: bold;">&quot;this.style.backgroundColor=this.originalstyle;&quot;</span>);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">override</span> <span style="color: blue; font-weight: bold;">void</span> OnDataBinding(System<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span><span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (CurrentPageID <span style="color: rgb(128, 128, 192); font-weight: bold;">!=</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">-</span><span style="color: teal;">1</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; PageIndex <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> CurrentPageID;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">base</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>OnDataBinding(e);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> GridViewEx_RowEditing(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewEditEventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; EditIndex <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>NewEditIndex;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> ViewState[CurrentViewID];</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> GridViewEx_RowDataBound(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewRowEventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">foreach</span> (<span style="color: rgb(43, 145, 175); font-weight: bold;">TableCell</span> cell <span style="color: blue; font-weight: bold;">in</span> e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Cells)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">foreach</span> (System<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Web<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>UI<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span><span style="color: rgb(43, 145, 175); font-weight: bold;">Control</span> c <span style="color: blue; font-weight: bold;">in</span> cell<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Controls)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (c <span style="color: blue; font-weight: bold;">is</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">CheckBox</span>)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">CheckBox</span> chkBox <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> c <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">CheckBox</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (chkBox<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Checked)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>RowState <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: olive; font-weight: bold;">DataControlRowState</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Alternate)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>BackColor <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> System<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Drawing<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span><span style="color: rgb(43, 145, 175);">Color</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>LightSteelBlue;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Row<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>BackColor <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> System<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Drawing<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span><span style="color: rgb(43, 145, 175);">Color</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>AliceBlue;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> GridViewEx_RowCancelingEdit(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewCancelEditEventArgs</span> e)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; EditIndex <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: rgb(128, 128, 192); font-weight: bold;">-</span><span style="color: teal;">1</span>;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> ViewState[CurrentViewID];</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">void</span> PagerSelectedIndexChanged(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: blue; font-weight: bold;">int</span> pageSize)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">this</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>PageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> pageSize;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataSource <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> ViewState[CurrentViewID];</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DataBind();</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> Calculate the real index since the actual index returned from the </span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> GridView is the index in relation to the current page. We need the</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> real index in order to index into the list.</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: gray;">///</span><span style="color: green;"> </span><span style="color: gray;">&lt;/summary&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">int</span> Index(<span style="color: blue; font-weight: bold;">int</span> rowIndex)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> PageIndex <span style="color: rgb(128, 128, 192); font-weight: bold;">*</span> PageSize <span style="color: rgb(128, 128, 192); font-weight: bold;">+</span> rowIndex;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">
<div>}</div>
</div>
</div>
<p>Because we are using customized objects as data bound objects, we also need to provider our own comparer so that the grid knows how to sort each column. This task is fairly easy and I modified the implementation from <a href="http://www.gridviewguy.com/ArticleDetails.aspx?articleID=203">GridViewGuy</a>. One thing you need to pay special attention is that since the comparison is done using property reflections, the property names are by default case sensitive (e.g. if you have a value property named <em>Item</em>, the binding in ASP.Net must be &quot;<em>Item</em>&quot; as well. &quot;item&quot; will give a run time error).&nbsp; The code for the comparer is as follows:</p>
<p>&nbsp;</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">class</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">GenericComparer</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span>T<span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span>: <span style="color: rgb(128, 64, 64); font-weight: bold;">IComparer</span><span style="color: rgb(128, 128, 192); font-weight: bold;">&lt;</span>T<span style="color: rgb(128, 128, 192); font-weight: bold;">&gt;</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: olive; font-weight: bold;">SortDirection</span> _direction <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: olive; font-weight: bold;">SortDirection</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Ascending;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: blue; font-weight: bold;">string</span> _expression <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Empty;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: olive; font-weight: bold;">SortDirection</span> Direction</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _direction; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _direction <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> GenericComparer(<span style="color: olive; font-weight: bold;">SortDirection</span> direction, <span style="color: blue; font-weight: bold;">string</span> expression)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _direction <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> direction;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _expression <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> expression;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">int</span> Compare(T x, T y)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">PropertyInfo</span> propertyInfo <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">typeof</span>(T)<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>GetProperty(_expression);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(128, 64, 64); font-weight: bold;">IComparable</span> obj1 <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> (<span style="color: rgb(128, 64, 64); font-weight: bold;">IComparable</span>)propertyInfo<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>GetValue(x, <span style="color: blue; font-weight: bold;">null</span>);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(128, 64, 64); font-weight: bold;">IComparable</span> obj2 <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> (<span style="color: rgb(128, 64, 64); font-weight: bold;">IComparable</span>)propertyInfo<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>GetValue(y, <span style="color: blue; font-weight: bold;">null</span>);</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (_direction <span style="color: rgb(128, 128, 192); font-weight: bold;">==</span> <span style="color: olive; font-weight: bold;">SortDirection</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Ascending)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> obj1<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>CompareTo(obj2);</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">else</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">return</span> obj2<span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>CompareTo(obj1);</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</div>
</div>
<p><strong>See also</strong></p>
<div><a href="/2008/08/08/extending-the-gridview-part-i/">Extending the GridView &mdash; Part I</a></div>
<div><a href="/2008/08/15/extending-the-gridview-&mdash;-part-ii/">Extending the GridView &mdash; Part II</a></div>
<div><a href="/2008/08/16/extending-the-gridview-&mdash;-part-iii/">Extending the GridView &mdash; Part III</a></div>
<div><a href="/2008/08/17/extending-the-gridview-&mdash;-part-iv/">Extending the GridView &mdash; Part IV</a></div>
<p>Code Download: <a href="/blog/wp-content/uploads/2008/08/extendingthegridview.zip">ExtendingTheGridView.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2008/08/15/extending-the-gridview-%e2%80%94-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extending the GridView &#8212; Part I</title>
		<link>http://www.kerrywong.com/2008/08/08/extending-the-gridview-part-i/</link>
		<comments>http://www.kerrywong.com/2008/08/08/extending-the-gridview-part-i/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 00:41:55 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C Sharp (C#)]]></category>
		<category><![CDATA[GridView]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/2008/08/08/extending-the-gridview-part-i/</guid>
		<description><![CDATA[Most business applications require presenting result sets to the end users in the form of some kind of grid views. While the default ASP.NET GridView control is sufficient for simple scenarios when doing rapid application development, its drawbacks become clear when building any large scale solutions (discussions here apply to all the current .Net frameworks, [...]]]></description>
			<content:encoded><![CDATA[<p>Most business applications require presenting result sets to the end users in the form of some kind of grid views.<span id="more-323"></span> While the default ASP.NET GridView control is sufficient for simple scenarios when doing <a href="http://en.wikipedia.org/wiki/Rapid_application_development">rapid application development</a>, its drawbacks become clear when building any large scale solutions (discussions here apply to all the current .Net frameworks, 2.0, 3.5 etc.).</p>
<p>For instance, the default data binding is limited to SqlDataSource, ObjectDataSource or a DataSet object (including DataView, DataTable, etc.). When building a large scale business solution, it is generally desirable to complete separate the data manipulation and business logic from the presentation layer and the most common solution is to employee a <a href="http://en.wikipedia.org/wiki/Model-view-controller">Model-View-Controller</a> pattern.&nbsp; This requirement makes SqlDataSource and DataSet bindings unsuitable. While ObjectDataSource does provide some level of isolation, the way business objects can be constructed is limited in order for these objects to be used as ObjectDataSource.</p>
<p>Most business objects incorporate the so-called <a href="http://en.wikipedia.org/wiki/Data_Transfer_Object">Value Object</a> data structure. Basically, it is a serializable class with the sole purpose of holding values and possibly other functionalities like data validation. Unfortunately, by default, GridView&#8217;s support for such value objects is poor (i.e. you can bind a value object to a grid view, but sorting is not supported by default). Over the years, I have seen many ad-hoc implementations to make GridView suitable for binding with customized value objects. Unfortunately, many of the solutions were implemented poorly and the implementation techniques vary from person to person, making it difficult if not impossible to maintain.</p>
<p>In the next few blog posts, I will show you how to extend the stock GridView in ASP.Net to make it suitable for using with value objects. The goal of extending the standard GridView is not only to add sorting capabilities, but to make the new component compatible with the standard GridView. I also intended to hide as much implementation details as possible so that the end users do not need to worry about the syntactical nuances as do with the standard GridView when binding to objects.</p>
<p>I assume that the development environment is Visual Studio 2005 with AJAX extension installed. The samples I show here can run within either Visual Studio 2005 (with AJAX extension) or Visual Studio 2008 without any modifications.</p>
<p><strong>1.Defining the Value Object </strong></p>
<p>As mentioned before, the reason we would like to define our own so-called value objects instead of using a DataSet to hold data is to ensure type safety. Since DataSet can hold any kind of objects, debugging becomes more difficult as error checking happens at run time not compile time. It also makes it easy to make mistakes as columns must be accessed by their names and any changes in column names could result in code broken at runtime somewhere in the UI.&nbsp; Most importantly, binding a dataset directly to the UI violates the layered design principal, making the data and the presentation tightly coupled and difficult to adapt. The solution is to create a level of indirection by utilizing the so called value objects.  Value objects are nothing fancy, they are merely a serializable class that provides the properties that represent the data (e.g. a row in a table) we are dealing with. For instance, here is what we might create as a value object for a simple phone book:</p>
<p>&nbsp;</p>
<div style="background: white none repeat scroll 0% 0%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; [<span style="color: rgb(43, 145, 175); font-weight: bold;">Serializable</span>()]</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">class</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">ItemVal</span></div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">string</span> _name <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Empty;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">string</span> _address <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Empty;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">string</span> _zipCode <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Empty;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">string</span> _phoneNumber <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: rgb(128, 128, 192); font-weight: bold;">.</span>Empty;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">bool</span> _selected <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">false</span>;</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">string</span> Name</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _name; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _name <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">string</span> Address</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _address; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _address <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">string</span> ZipCode</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _zipCode; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _zipCode <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">string</span> PhoneNumber</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _phoneNumber; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _phoneNumber <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">bool</span> Selected</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _selected; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _selected <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> ItemVal(<span style="color: blue; font-weight: bold;">string</span> name, <span style="color: blue; font-weight: bold;">string</span> address, <span style="color: blue; font-weight: bold;">string</span> zipCode, <span style="color: blue; font-weight: bold;">string</span> phoneNumber)</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _name <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> name;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _address <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> address;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _zipCode <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> zipCode;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _phoneNumber <span style="color: rgb(128, 128, 192); font-weight: bold;">=</span> phoneNumber;</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</div>
</div>
<p>By creating a collection of such value object we just defined, we have a full representation of the result set returned from the database via a query or stored procedure. And via value objects, all the accesses are guaranteed to be type safe.</p>
<p><strong>See also</strong></p>
<div><a href="/2008/08/08/extending-the-gridview-part-i/">Extending the GridView &mdash; Part I</a></div>
<div><a href="/2008/08/15/extending-the-gridview-&mdash;-part-ii/">Extending the GridView &mdash; Part II</a></div>
<div><a href="/2008/08/16/extending-the-gridview-&mdash;-part-iii/">Extending the GridView &mdash; Part III</a></div>
<div><a href="/2008/08/17/extending-the-gridview-&mdash;-part-iv/">Extending the GridView &mdash; Part IV</a></div>
<p>Code Download: <a href="/blog/wp-content/uploads/2008/08/extendingthegridview.zip">ExtendingTheGridView.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2008/08/08/extending-the-gridview-part-i/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple Row Selection With GridView</title>
		<link>http://www.kerrywong.com/2008/02/10/multiple-row-selection-with-gridview/</link>
		<comments>http://www.kerrywong.com/2008/02/10/multiple-row-selection-with-gridview/#comments</comments>
		<pubDate>Sun, 10 Feb 2008 18:36:27 +0000</pubDate>
		<dc:creator>kwong</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[GridView]]></category>

		<guid isPermaLink="false">http://www.kerrywong.com/2008/02/10/multiple-row-selection-with-gridview/</guid>
		<description><![CDATA[We often need the capability of selecting multiple rows from a grid, unfortunately the GridView component in ASP.Net 2.0 does not offer an out-of-box support for such functionality.Fortunately, implementing such behavior is pretty straight if you have a clear understanding of how the GridView component works. Many of the samples demonstrated in various other posts [...]]]></description>
			<content:encoded><![CDATA[<p>We often need the capability of selecting multiple rows from a grid, unfortunately the GridView component in ASP.Net 2.0 does not offer an out-of-box support for such functionality.<span id="more-265"></span>Fortunately, implementing such behavior is pretty straight if you have a clear understanding of how the GridView component works. Many of the samples demonstrated in various other posts require registering some&nbsp; kind of client side JavaScript, here I will show a slightly different approach in which no custom JavaScript is needed (of course, there are JavaScripts generated automatically by the framework).</p>
<p>Suppose we are creating a simple application where you can select multiple people from a contact list and then do somthing with your selection (e.g. export the selection etc.) An intuitive way is to include a column of CheckBoxes in the front of all the rows so that the staus of each CheckBox indicates whether that row is included in the user selection (See below):</p>
<table rules="all" cellspacing="0" border="1" align="center" style="border-collapse: collapse;" id="GridView1">
<tbody>
<tr>
<th align="center" scope="col">Select</th>
<th scope="col">User Name</th>
<th scope="col">Phone Number</th>
</tr>
<tr>
<td>
<input type="checkbox" name="GridView1$ctl02$CBEntrySelected" onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl02$CBEntrySelected\',\'\')', 0)" id="GridView1_ctl02_CBEntrySelected" /></td>
<td>Bob</td>
<td>(232) 111-1312</td>
</tr>
<tr>
<td>
<input type="checkbox" name="GridView1$ctl03$CBEntrySelected" onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl03$CBEntrySelected\',\'\')', 0)" id="GridView1_ctl03_CBEntrySelected" /></td>
<td>Sue</td>
<td>(088) 676-9987</td>
</tr>
<tr>
<td>
<input type="checkbox" name="GridView1$ctl04$CBEntrySelected" onclick="javascript:setTimeout('__doPostBack(\'GridView1$ctl04$CBEntrySelected\',\'\')', 0)" id="GridView1_ctl04_CBEntrySelected" /></td>
<td>Jim</td>
<td>(678) 123-4567</td>
</tr>
</tbody>
</table>
<div align="center">&nbsp;</div>
<p align="left">In this demonstration, I will use a customized object data source called UserDefinition:&nbsp;</p>
<blockquote>
<div style="background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div>[<span style="color: rgb(43, 145, 175); font-weight: bold;">Serializable</span>()]</div>
<div><span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">class</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span></div>
<div>{</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: blue; font-weight: bold;">bool</span> _entrySelected <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">false</span>;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: blue; font-weight: bold;">string</span> _userName <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: navy;">.</span>Empty;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: blue; font-weight: bold;">string</span> _phoneNumber <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">string</span><span style="color: navy;">.</span>Empty;</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">bool</span> EntrySelected</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _entrySelected; }</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _entrySelected <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">string</span> UserName</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _userName; }</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _userName <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> <span style="color: blue; font-weight: bold;">string</span> PhoneNumber</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">get</span> { <span style="color: blue; font-weight: bold;">return</span> _phoneNumber; }</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">set</span> { _phoneNumber <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">value</span>; }</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">public</span> UserDefinition(<span style="color: blue; font-weight: bold;">string</span> name, <span style="color: blue; font-weight: bold;">string</span> phone)</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _userName <span style="color: navy;">=</span> name;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; _phoneNumber <span style="color: navy;">=</span> phone;</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
<div>}</div>
</div>
</blockquote>
<p align="left">Alternatively, you could use pretty much any data sources that you are accustomed to. The concept should be similar&nbsp; enough.</p>
<p align="left">And the GridView is defined as follows:</p>
<blockquote>
<div style="background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div><span style="color: navy;">&lt;</span>asp:GridView ID<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;GridView1&quot;</span> runat<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;server&quot;</span> AutoGenerateColumns<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;False&quot;</span><span style="color: navy;">&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;</span>Columns<span style="color: navy;">&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;</span>asp:TemplateField HeaderText<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;Select&quot;</span><span style="color: navy;">&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;</span>ItemTemplate<span style="color: navy;">&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;</span>asp:CheckBox ID<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;CBEntrySelected&quot;</span> runat<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;server&quot;</span> AutoPostBack<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;True&quot;</span> Checked<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&#8216;&lt;%# Bind(&quot;EntrySelected&quot;) %&gt;&#8217;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; OnCheckedChanged<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;CBEntrySelected_CheckedStateChanged&quot;</span> <span style="color: navy;">/&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;/</span>ItemTemplate<span style="color: navy;">&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;/</span>asp:TemplateField<span style="color: navy;">&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;</span>asp:BoundField HeaderText<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;User Name&quot;</span> DataField<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;UserName&quot;</span> <span style="color: navy;">/&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;</span>asp:BoundField HeaderText<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;Phone Number&quot;</span> DataField<span style="color: navy;">=</span><span style="color: rgb(163, 21, 21);">&quot;PhoneNumber&quot;</span> <span style="color: navy;">/&gt;</span></div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: navy;">&lt;/</span>Columns<span style="color: navy;">&gt;</span></div>
<div><span style="color: navy;">&lt;/</span>asp:GridView<span style="color: navy;">&gt;</span></div>
</div>
</blockquote>
<p align="left">Note that the AutoPostBack property is set to true so that the server side code would have an opportunity to record the user&#8217;s action. So far, every thing should be pretty straightforward. The only trick is in the server side code:</p>
<blockquote>
<div style="background: white none repeat scroll 0% 50%; font-family: Courier New; font-size: 10pt; color: black; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> Page_Load(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DisplayGrid();</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">private</span> <span style="color: blue; font-weight: bold;">void</span> DisplayGrid()</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: navy;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span><span style="color: navy;">&gt;</span> list <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: navy;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span><span style="color: navy;">&gt;</span>();</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list<span style="color: navy;">.</span>Add(<span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span>(<span style="color: rgb(163, 21, 21);">&quot;Bob&quot;</span>, <span style="color: rgb(163, 21, 21);">&quot;(232) 111-1312&quot;</span>));</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list<span style="color: navy;">.</span>Add(<span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span>(<span style="color: rgb(163, 21, 21);">&quot;Sue&quot;</span>, <span style="color: rgb(163, 21, 21);">&quot;(088) 676-9987&quot;</span>));</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list<span style="color: navy;">.</span>Add(<span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span>(<span style="color: rgb(163, 21, 21);">&quot;Jim&quot;</span>, <span style="color: rgb(163, 21, 21);">&quot;(678) 123-4567&quot;</span>));</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridView1<span style="color: navy;">.</span>DataSource <span style="color: navy;">=</span> list;</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (<span style="color: navy;">!</span>Page<span style="color: navy;">.</span>IsPostBack)</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GridView1<span style="color: navy;">.</span>DataBind();</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ViewState[<span style="color: rgb(163, 21, 21);">&quot;CurrentView&quot;</span>] <span style="color: navy;">=</span> list;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> CBEntrySelected_CheckedStateChanged(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">CheckBox</span> checkBox <span style="color: navy;">=</span> sender <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">CheckBox</span>;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewRow</span> selectedRow <span style="color: navy;">=</span> checkBox<span style="color: navy;">.</span>Parent<span style="color: navy;">.</span>Parent <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">GridViewRow</span>;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: navy;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span><span style="color: navy;">&gt;</span> list <span style="color: navy;">=</span> ViewState[<span style="color: rgb(163, 21, 21);">&quot;CurrentView&quot;</span>] <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: navy;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span><span style="color: navy;">&gt;</span>;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; list[selectedRow<span style="color: navy;">.</span>RowIndex]<span style="color: navy;">.</span>EntrySelected <span style="color: navy;">=</span> checkBox<span style="color: navy;">.</span>Checked;</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">protected</span> <span style="color: blue; font-weight: bold;">void</span> BtnSubmit_Click(<span style="color: blue; font-weight: bold;">object</span> sender, <span style="color: rgb(43, 145, 175); font-weight: bold;">EventArgs</span> e)</div>
<div>&nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: navy;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span><span style="color: navy;">&gt;</span> list <span style="color: navy;">=</span> ViewState[<span style="color: rgb(163, 21, 21);">&quot;CurrentView&quot;</span>] <span style="color: blue; font-weight: bold;">as</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">List</span><span style="color: navy;">&lt;</span><span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span><span style="color: navy;">&gt;</span>;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: rgb(43, 145, 175); font-weight: bold;">StringBuilder</span> sb <span style="color: navy;">=</span> <span style="color: blue; font-weight: bold;">new</span> <span style="color: rgb(43, 145, 175); font-weight: bold;">StringBuilder</span>();</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb<span style="color: navy;">.</span>Append(<span style="color: rgb(163, 21, 21);">&quot;&lt;br /&gt;Selected items:&lt;br /&gt;&quot;</span>);</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">foreach</span> (<span style="color: rgb(43, 145, 175); font-weight: bold;">UserDefinition</span> def <span style="color: blue; font-weight: bold;">in</span> list)</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color: blue; font-weight: bold;">if</span> (def<span style="color: navy;">.</span>EntrySelected)</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; sb<span style="color: navy;">.</span>Append(<span style="color: blue; font-weight: bold;">string</span><span style="color: navy;">.</span>Format(<span style="color: rgb(163, 21, 21);">&quot;{0} : {1}&lt;br /&gt;&quot;</span>, def<span style="color: navy;">.</span>UserName, def<span style="color: navy;">.</span>PhoneNumber));</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</div>
<div>&nbsp;</div>
<div>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Label1<span style="color: navy;">.</span>Text <span style="color: navy;">=</span> sb<span style="color: navy;">.</span>ToString();</div>
<div>&nbsp;&nbsp;&nbsp; }</div>
</div>
</blockquote>
<p align="left">Note that in our CkeckBox checked event handler CBEntrySelected_CheckedStateChanged, we used the GridView object hierarchy to figure out which row was selected/unselected by user and record it accordingly in the object that the grid renders. The hierarchy is as follows:</p>
<blockquote>
<p align="left">&nbsp;CheckBox -&gt; DataControlFieldCell -&gt; GridViewRow -&gt; ChildTable -&gt; GridView</p>
</blockquote>
<p align="left">&nbsp;Also note that in our simple example, only the RowIndex is used to determine whether a row is selected or not. This only works when paging is not involved. When there are multiple pages, we have to go two hierarchies higher to the GridView level, where we can use PageIndex and PageSize to identify the correct selection (i.e. PageSize * PageIndex + RowIndex).</p>
<p align="center">&nbsp;<img src="/blog/wp-content/uploads/2008/02/multiipleselection.GIF" alt="" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.kerrywong.com/2008/02/10/multiple-row-selection-with-gridview/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
