<?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>I Learnt Today... &#187; Visual Studio</title>
	<atom:link href="http://www.ilearnttoday.com/category/information-technology/software-development/visual-studio/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ilearnttoday.com</link>
	<description>This is where I share what I learn day by day...</description>
	<lastBuildDate>Fri, 18 May 2012 13:36:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to auto save the data table in memory into database?</title>
		<link>http://www.ilearnttoday.com/commandbinder</link>
		<comments>http://www.ilearnttoday.com/commandbinder#comments</comments>
		<pubDate>Tue, 04 Oct 2011 13:27:46 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[C# .Net]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Auto update]]></category>
		<category><![CDATA[Command Binder]]></category>
		<category><![CDATA[CommandBinder]]></category>
		<category><![CDATA[Data adaptor]]></category>
		<category><![CDATA[data table]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[synchronize]]></category>

		<guid isPermaLink="false">http://www.ilearnttoday.com/?p=479</guid>
		<description><![CDATA[2010-04-01 We frequently get to fetch data from the database, update them and then write them back to the database. Most of<a href="http://www.ilearnttoday.com/commandbinder" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p><span style="color: #c0c0c0;">2010-04-</span><span style="color: #c0c0c0;">01</span></p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "ca-pub-5478118713208336";
/* LeadIn */
google_ad_slot = "2638602320";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>We frequently get to fetch data from the database, update them and then write them back to the database.</p>
<p>Most of the time we only have to write them back as individual records.</p>
<p>How about updating a whole database table in the memory and having to synchronize all changes to the actual data table?</p>
<p>My initial thought was this would be full of complex coding. However, thanks to Microsoft, there&#8217;s nothing much to be done at all.</p>
<p>So how are we gonna do this is&#8230;</p>
<p>We will use a data adaptor to fill our data table as usual.</p>
<p>The only new thing is the use of a Command Binder.</p>
<p>Command Binder: A command binder is capable to detect changes that have occurred to a table (in the memory) and then automatically generate appropriate SQL statements to save those changes into the actual data table (in the database).</p>
<p>Following is a simple example: Scenario: In my application I had to take a database table name and present data in a data grid and then save all changes made by the user.</p>
<p>What we need: a data table an adaptor a connection a command builder I have defined them at the form level so I can use them across the form from different events.</p>
<pre class="brush: csharp; title: ; notranslate">
private DataTable _tbl;

private SqlDataAdapter _adptr;

private SqlConnection _conn;

private SqlCommandBuilder _cbldr;
</pre>
<p>Step1: Initialize connection and retrieve data from the database</p>
<pre class="brush: csharp; title: ; notranslate">
_tbl = new DataTable();
_conn = FetchData.GetOpenConnection();
_adptr = new SqlDataAdapter(&quot;Select * from &quot; + DatabaseTableName, _conn);
_cbldr = new SqlCommandBuilder(_adptr);
_adptr.Fill(_tbl);
</pre>
<p>Step2: Let the user to change data (in here simply bind the table to a grid)</p>
<pre class="brush: csharp; title: ; notranslate">
dgMainGrid.DataSource = _tbl;
</pre>
<p>Step3: Save (synchronize) changes to the actual database table Even though this is a complex process and undoubtedly would take a lot of effort to do manually, Thanks to .net framework all we need is a line of code.</p>
<pre class="brush: csharp; title: ; notranslate">
_adptr.Update(_tbl);
</pre>
<p>Once you call the adaptor to update the table, it will use the command builder attached to it to generate all necessary SQL command building. The database table is now up-to-date!</p>
<p><span style="color: #008000;">Was this post helpful to you? How can I improve? – Your comment is highly appreciated!</span></p>
<p><span style="color: #c0c0c0;">Cassian Menol Razeek</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/commandbinder/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>D LINQ : How to Map Columns Which Auto Generate Values At the Database</title>
		<link>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database</link>
		<comments>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database#comments</comments>
		<pubDate>Mon, 11 May 2009 17:37:17 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Menol]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.NET exception]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[auto-generate]]></category>
		<category><![CDATA[Cannot insert explicit value for identity column in table 'tbl_Process' when IDENTITY_INSERT is set to OFF]]></category>
		<category><![CDATA[DLINQ]]></category>
		<category><![CDATA[IDENTITY_INSERT]]></category>
		<category><![CDATA[IsDbGenerated]]></category>
		<category><![CDATA[IsDbGenerated:=True]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[primary key]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server exception]]></category>
		<category><![CDATA[Windows Application]]></category>

		<guid isPermaLink="false">http://www.ilearnttoday.com/?p=390</guid>
		<description><![CDATA[2009-05-11 I have being working on a software application made on .Net and recently my client asked me to use<a href="http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><!--[endif]--><span style="color: silver;">2009-05-11</span></p>
<p><script type="text/javascript"><!--
google_ad_client = "ca-pub-5478118713208336";
/* LeadIn */
google_ad_slot = "2638602320";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p style="text-align: justify;">I have being working on a software application made on .Net and recently my client asked me to use D LINQ instead of SQL.</p>
<p style="text-align: justify;">D LINQ has great benefits loaded! As I started working with DLINQ I started to know that preventing SQL injection is not a headache anymore and misspelled SQL queries will not trouble agian at run time because DLINQ generates all necessary SQL inside the framework!</p>
<p style="text-align: justify;">I chose to use annotations inside the class instead of using separate xml file. Following is a part of the first class I ported to D LINQ.</p>
<p style="text-align: justify;">
<pre class="brush: vb; title: ; notranslate">&lt;/p&gt;
_
Public Class Process
_
Public ProcessID As Integer
_
Public BusinessProcessID As String
_
Public ProcessText As String
...
...
</pre>
<p style="text-align: justify;">ProcessID column is the primary key of my database table tbl_Process.</p>
<p style="text-align: justify;">Important Point: I use database to auto-generate values for the primary key column (integer value incremented by one).</p>
<p style="text-align: justify;">So when I run the application, It gave me this unexpected error:</p>
<p style="text-align: justify;"><strong><em>Cannot insert explicit value for identity column in table &#8216;tbl_Process&#8217; when IDENTITY_INSERT is set to OFF.</em></strong></p>
<p style="text-align: justify;">Basically, the <strong><em>IDENTITY_INSERT</em></strong> when using the database to auto generate value for a field but when I ran a SQL insert statement at the database end it worked fine!</p>
<p style="text-align: justify;">After some tough time I found out the solution for this problem!</p>
<p style="text-align: justify;">When we use an auto-generate field in a data table we have to specifically mention it in the matching field in the appropriate class.</p>
<p style="text-align: justify;">The code to state this is:</p>
<p style="text-align: justify;"><em>Syntax:</em></p>
<p style="text-align: justify;"><strong><em>IsDbGenerated:=True</em></strong></p>
<p style="text-align: justify;">This has to be added to the annotation added for the specific column like:</p>
<p style="text-align: justify;">
<pre class="brush: vb; title: ; notranslate">&lt;/p&gt;
_
Public ProcessID As Integer
</pre>
<p style="text-align: justify;">Now D LINQ can understand that the field value is auto-generated by the database!</p>
<p style="text-align: justify;"><span style="color: green;">Was this post helpful to you? How can I improve? &#8211; Your comment is highly appreciated!</span></p>
<p style="text-align: justify;"><span style="color: silver;">Cassian Menol Razeek</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/d-linq-how-to-map-columns-which-auto-generate-values-at-the-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET &#8211; AutoPostBack : What is AutoPostBack and How AutoPostBack Works</title>
		<link>http://www.ilearnttoday.com/c-aspnet-autopostback-how-to-fire-events-for-check-boxes-at-server-side</link>
		<comments>http://www.ilearnttoday.com/c-aspnet-autopostback-how-to-fire-events-for-check-boxes-at-server-side#comments</comments>
		<pubDate>Fri, 26 Dec 2008 10:09:28 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[AutoPostBack property]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Menol]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net framework]]></category>
		<category><![CDATA[AutoPostBack]]></category>
		<category><![CDATA[AutoPostBack Example]]></category>
		<category><![CDATA[can't fire events]]></category>
		<category><![CDATA[checkbox]]></category>
		<category><![CDATA[checkbox control]]></category>
		<category><![CDATA[CheckedChanged]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[define __EVENTTARGET]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[event is not fired]]></category>
		<category><![CDATA[event not executed]]></category>
		<category><![CDATA[event not fired]]></category>
		<category><![CDATA[eventArgument)]]></category>
		<category><![CDATA[events are not fired]]></category>
		<category><![CDATA[events queued to the server]]></category>
		<category><![CDATA[execute event]]></category>
		<category><![CDATA[fire]]></category>
		<category><![CDATA[How AutoPostBack works]]></category>
		<category><![CDATA[how to use __doPostBack]]></category>
		<category><![CDATA[how __doPostBack]]></category>
		<category><![CDATA[how __EVENTARGUMENT works]]></category>
		<category><![CDATA[how __EVENTTARGET works]]></category>
		<category><![CDATA[OnChange]]></category>
		<category><![CDATA[OnChange client side event]]></category>
		<category><![CDATA[OnChange event]]></category>
		<category><![CDATA[postback]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[server side]]></category>
		<category><![CDATA[set AutoPostBack property]]></category>
		<category><![CDATA[The Use of AutoPostBack]]></category>
		<category><![CDATA[use of __EVENTARGUMENT]]></category>
		<category><![CDATA[use of __EVENTTARGET]]></category>
		<category><![CDATA[web control]]></category>
		<category><![CDATA[What is AutoPostBack]]></category>
		<category><![CDATA[what is __doPostBack]]></category>
		<category><![CDATA[what is __EVENTARGUMENT]]></category>
		<category><![CDATA[what is __EVENTTARGET]]></category>
		<category><![CDATA[what __doPostBack does]]></category>
		<category><![CDATA[__doPostBack function]]></category>
		<category><![CDATA[__doPostBack(eventTarget]]></category>
		<category><![CDATA[__EVENTARGUMENT]]></category>
		<category><![CDATA[__EVENTTARGET]]></category>

		<guid isPermaLink="false">http://ilearnttoday.wordpress.com/?p=191</guid>
		<description><![CDATA[2008-12-26 Today I was experimenting on a grid view where I was trying to select multiple rows of the grid<a href="http://www.ilearnttoday.com/c-aspnet-autopostback-how-to-fire-events-for-check-boxes-at-server-side" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p style="text-align:justify;"><span style="color:#c0c0c0;">2008-12-26<br />
</span></p>
<p style="text-align:justify;"><!--[if gte mso 9]&gt;  Normal 0   false false false        MicrosoftInternetExplorer4  &lt;![endif]--><!--[if gte mso 9]&gt;   &lt;![endif]--> Today I was experimenting on a grid view where I was trying to select multiple rows of the grid view using a check box column.</p>
<p style="text-align:justify;">I wrote some code in the <strong>CheckedChanged </strong>of <strong>checkbox </strong>but then I found that the code was not executed when the state of the checkbox is changed.</p>
<p style="text-align:justify;">So I did a little googling and found out about this AutoPostBack property. This property defines whether the control should post back to the server each time when the user interacts with the control. Or, according to this scenario, a post back will fire when the user clicks on the check box or when the <strong>Checked </strong>property is changed.</p>
<p style="text-align:justify;"><strong>AutoPostBack :</strong></p>
<p style="text-align:justify;">This value holds a boolean value (true/false)</p>
<p style="text-align:justify;">If the property is set to true, a post back is sent immediately to the server and no post back is occurred when set to false.</p>
<p style="text-align:justify;">The Use of AutoPostBack:</p>
<p style="text-align:justify;">According to MSDN, <em>for most WebControls, when AutoPostBack is false, only the events from actions that cause a net change in the state of the control are submitted to the server.</em></p>
<p style="text-align:justify;">In other words some events are not queued to the server. For example no event is fired when a user selects a value from a drop down list or when user presses Enter or Tab key after entering a value to a textbox.</p>
<p style="text-align:justify;">If you want such events to be fired then you have to enable autopostback by setting autopostback property to <em>true</em>.</p>
<p style="text-align:justify;"><strong>How AutoPostBack Works :</strong></p>
<p style="text-align:justify;">When AutoPostBack is enabled, the .Net framework automatically injects following additional items into the generated HTML code.</p>
<ol style="text-align:justify;" type="1">
<li class="MsoNormal">Two Hidden variables with      name __EVENTTARGET and __EVENTARGUMENT</li>
<li class="MsoNormal">A Java script method with      name __doPostBack (eventtarget, eventargument)</li>
<li class="MsoNormal">OnChange JavaScript event to      the control</li>
</ol>
<p style="text-align:justify;">What is <strong>__EVENTTARGET</strong> :</p>
<p style="text-align:justify;">__EVENTTARGET tells the server which control wants to fire the event so that the framework can fire the event on that control.</p>
<p style="text-align:justify;">What is <strong>__EVENTARGUMENT</strong> :</p>
<p style="text-align:justify;">__EVENTARGUMENT can be used to provide additional information to the server about the event.</p>
<p style="text-align:justify;">What is <strong>__doPostBack (eventtarget, eventargument) :</strong></p>
<p style="text-align:justify;">Parameters sent to this method holds relevant target and event argument values and this method sets those values into __EVENTTARGET and __EVENTARGUMENT hidden variables so that the server can read those.</p>
<p style="text-align:justify;">Then this method submits the form to the server where the appropriate event will be fired.</p>
<p style="text-align:justify;">What is <strong>OnChange </strong>JavaScript event to the control :</p>
<p style="text-align:justify;">Every control has a client side event called OnChange. When AutoPostBack is enabled for a control the framework sets the handler for this client side event as the __doPostBack method and will pass the name of the control as the first parameter, eventtarget.</p>
<p style="text-align:justify;">Ex/</p>
<p style="text-align:justify;">Following shows how the framework binds the __doPostBack method to the OnChange event.</p>
<p style="text-align:justify;">&lt;input type=&#8221;checkbox&#8221; <strong><em>onclick=</em></strong><em>&#8220;javascript:setTimeout(&#8216;<strong>__doPostBack(&#8216;CheckBox1&#8242;,&#8221;)</strong>&#8216;, 0)&#8221; </em>/&gt;</p>
<p style="text-align:justify;"><span style="color:#008000;">Was this post helpful to you? How can I improve? &#8211; </span><span style="color:#008000;">Your comment is highly appreciated!</span></p>
<p style="text-align:justify;"><span style="color:#c0c0c0;">Cassian Menol Razeek</span></p>
<p><strong>Recommended Books:</strong></p>
<ul>
<li>
<a href="http://www.amazon.com/gp/product/1590598938?ie=UTF8&amp;tag=ileto-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1590598938">Pro ASP.NET 3.5 in C# 2008</a><img src="http://www.assoc-amazon.com/e/ir?t=ileto-20&amp;l=as2&amp;o=1&amp;a=1590598938" width="1" height="1" border="0" alt="" style="border:none!important;margin:0!important;" /></p>
</li>
<li> <a href="http://www.amazon.com/gp/product/B000YJ2OJ2?ie=UTF8&amp;tag=ileto-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B000YJ2OJ2">Professional ASP.NET 2.0 Special Edition</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=ileto-20&amp;l=as2&amp;o=1&amp;a=B000YJ2OJ2" border="0" alt="" width="1" height="1" /></li>
<li>
<a href="http://www.amazon.com/gp/product/047018759X?ie=UTF8&amp;tag=ileto-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=047018759X">Beginning ASP.NET 3.5: In C# and VB Languages</a><img src="http://www.assoc-amazon.com/e/ir?t=ileto-20&amp;l=as2&amp;o=1&amp;a=047018759X" width="1" height="1" border="0" alt="" style="border:none!important;margin:0!important;" />
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/c-aspnet-autopostback-how-to-fire-events-for-check-boxes-at-server-side/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Save a Copy of a Visual Studio 2005 Solution</title>
		<link>http://www.ilearnttoday.com/how-to-save-a-copy-of-a-visual-studio-2005-solution</link>
		<comments>http://www.ilearnttoday.com/how-to-save-a-copy-of-a-visual-studio-2005-solution#comments</comments>
		<pubDate>Mon, 22 Dec 2008 18:42:32 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[Menol]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[.sln]]></category>
		<category><![CDATA[copy visual studio file]]></category>
		<category><![CDATA[copy visual studio project]]></category>
		<category><![CDATA[copy visual studio solution]]></category>
		<category><![CDATA[File menu]]></category>
		<category><![CDATA[How to Save a Copy of a Visual Studio 2005 Web Solution]]></category>
		<category><![CDATA[move sln file]]></category>
		<category><![CDATA[move sln files]]></category>
		<category><![CDATA[move visual studio file]]></category>
		<category><![CDATA[move visual studio project]]></category>
		<category><![CDATA[move visual studio solution]]></category>
		<category><![CDATA[save a copy]]></category>
		<category><![CDATA[save as .sln files]]></category>
		<category><![CDATA[save as sln file]]></category>
		<category><![CDATA[save as solution]]></category>
		<category><![CDATA[save as visual studio file]]></category>
		<category><![CDATA[save as visual studio project]]></category>
		<category><![CDATA[save as visual studio solution]]></category>
		<category><![CDATA[Visual Studio 2005]]></category>
		<category><![CDATA[Visual Studio 2005 solution]]></category>
		<category><![CDATA[Visual Studio solution]]></category>

		<guid isPermaLink="false">http://ilearnttoday.wordpress.com/?p=184</guid>
		<description><![CDATA[2008-12-22 Sometimes things we consider as simple take much time to be accomplished than we expect just because we forget!<a href="http://www.ilearnttoday.com/how-to-save-a-copy-of-a-visual-studio-2005-solution" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p><span style="color:#c0c0c0;">2008-12-22</span></p>
<p style="text-align:justify;">Sometimes things we consider as simple take much time to be accomplished than we expect just because we forget!</p>
<p style="text-align:justify;">Today I wanted to save a copy of a web based visual studio 2005 solution but it took life 10 minutes for me to accomplish that because I had completely forgotten the method to do it. Since keeping track of what I learn is one objective of this blog I decided to include this small detail today.</p>
<p style="text-align:justify;"><strong><strong><span style="text-decoration: underline;">How to save a copy a solution in visual studio 2005 </span></strong><span style="text-decoration: underline;"><strong></strong></span></strong><strong><span style="text-decoration: underline;">(Save As)</span></strong></p>
<p style="text-align:justify;">Select the solution (click on it) in the solution explorer</p>
<p style="text-align:justify;">Now go to File menu and there will be a command to Save the solution to any place you want.</p>
<p style="text-align:justify;">Ex/</p>
<p style="text-align:justify;">If your solution name is &#8220;My Solution.sln&#8221;</p>
<p style="text-align:justify;">When you select your solution in the solution explorer and go to the file menu, you will see command like:</p>
<p style="text-align:justify;">Save <em><em>My Solution.sln</em></em> As</p>
<p style="text-align:justify;">Simply click on that and you will get the usual Save As dialog box.</p>
<p style="text-align:justify;"><strong><strong><span style="text-decoration: underline;">Some Details</span></strong><strong></strong></strong></p>
<p style="text-align:justify;">Even though you can select the place to save project files in web based solutions such as web sites, the solution is saved in a different location which is located in your My Documents folder.</p>
<p style="text-align:justify;">The solution file contains information about your projects and files including paths so if you want to move the entire solution to a different computer to continue work on a different workstation then this tip will become handy unless you don&#8217;t forget things as I do <img src='http://www.ilearnttoday.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
<p style="text-align:justify;"><span style="color:#008000;">Was this post helpful to you? How can I improve? &#8211; </span><span style="color:#008000;">Your comment is highly appreciated!</span></p>
<p style="text-align:justify;"><span style="color:#c0c0c0;">Cassian Menol Razeek</span></p>
<p><strong>Recommended Books:</strong></p>
<ul>
<li> <a href="http://www.amazon.com/gp/product/0672328194?ie=UTF8&amp;tag=ileto-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0672328194">Microsoft &#8211; Visual Studio 2005 Unleashed</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=ileto-20&amp;l=as2&amp;o=1&amp;a=0672328194" border="0" alt="" width="1" height="1" /></li>
<li> <a href="http://www.amazon.com/gp/product/0672329727?ie=UTF8&amp;tag=ileto-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0672329727">Microsoft &#8211; Visual Studio 2008 Unleashed</a><img style="border:none!important;margin:0!important;" src="http://www.assoc-amazon.com/e/ir?t=ileto-20&amp;l=as2&amp;o=1&amp;a=0672329727" border="0" alt="" width="1" height="1" /></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/how-to-save-a-copy-of-a-visual-studio-2005-solution/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>C# ASP.NET &#8211; GridView : How to Keep Modified Data of Template Fields when Paging is Enabled?</title>
		<link>http://www.ilearnttoday.com/c-aspnet-gridview-how-to-keep-modified-data-of-template-fields-when-paging-is-enabled</link>
		<comments>http://www.ilearnttoday.com/c-aspnet-gridview-how-to-keep-modified-data-of-template-fields-when-paging-is-enabled#comments</comments>
		<pubDate>Thu, 04 Dec 2008 04:03:30 +0000</pubDate>
		<dc:creator>Menol</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[GridView]]></category>
		<category><![CDATA[Information Technology]]></category>
		<category><![CDATA[Menol]]></category>
		<category><![CDATA[PageIndexChanging Event]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[cache or session]]></category>
		<category><![CDATA[collection of rows]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[columns]]></category>
		<category><![CDATA[consultation]]></category>
		<category><![CDATA[custom columns]]></category>
		<category><![CDATA[data source]]></category>
		<category><![CDATA[data table]]></category>
		<category><![CDATA[datagrid]]></category>
		<category><![CDATA[datasource]]></category>
		<category><![CDATA[datasource property]]></category>
		<category><![CDATA[datatable]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[event handler]]></category>
		<category><![CDATA[gridview paging]]></category>
		<category><![CDATA[gridview.Rows]]></category>
		<category><![CDATA[PageIndexChanging]]></category>
		<category><![CDATA[paging]]></category>
		<category><![CDATA[postback]]></category>
		<category><![CDATA[postbacks]]></category>
		<category><![CDATA[property]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[synchronize]]></category>
		<category><![CDATA[template column]]></category>
		<category><![CDATA[template field]]></category>
		<category><![CDATA[template field in gridview]]></category>
		<category><![CDATA[template fields in datagrid]]></category>
		<category><![CDATA[text box field]]></category>
		<category><![CDATA[textbox column]]></category>
		<category><![CDATA[textbox field]]></category>

		<guid isPermaLink="false">http://ilearnttoday.wordpress.com/?p=78</guid>
		<description><![CDATA[2008-12-04 Today I had to take care of a problem of a certain company (CIS) that I consult. They had<a href="http://www.ilearnttoday.com/c-aspnet-gridview-how-to-keep-modified-data-of-template-fields-when-paging-is-enabled" class="searchmore">Read the Rest...</a><div class="clr"></div>]]></description>
			<content:encoded><![CDATA[<p><span style="color:#c0c0c0;">2008-12-04</span></p>
<p style="text-align:justify;">Today I had to take care of a problem of a certain company (CIS) that I consult. They had a problem of keeping the values modified in a template field of a gridview when the user moves from one page of the grid to another.</p>
<p style="text-align:justify;">Template fields allow us to add custom columns into a datagrid or gridview. For an instance, we can add a grid column which has a textbox in each cell.</p>
<p style="text-align:justify;">When the gridview has several pages, the gridview holds only the rows that are displayed in its Rows (collection) property. So we cannot access the values in other pages using the gridview.Rows property.</p>
<p style="text-align:justify;">Then I thought that I could access the whole collection of rows by referring to the DataSource property of the gridview. This is a good idea because even though the gridview only shows the rows on the current page for display purposes, the data source property of the gridview holds the whole collection of rows in it.</p>
<p style="text-align:justify;">ASP.Net clears the data source of any control at post backs. This is done to optimize performance of communications. In addition, the state of each control is stored in ViewState so it is not necessary to keep the datasource between postbacks.</p>
<p style="text-align:justify;">The problem is worse now because I could not use both datasource and the direct row collection from the gridview.</p>
<p style="text-align:justify;">Of course we can use either cache or session to keep the datasouce.</p>
<p style="text-align:justify;">
<pre class="brush: csharp; title: ; notranslate">

Session[&quot;DataSource&quot;] = dt;  // store our table in the session
</pre>
<p style="text-align:justify;">Then to synchronize (update) the datasource which was stored in the session we have to:</p>
<ul style="text-align:justify;">
<li>Go to each row in the gridview</li>
<li>Get the matching data row from the data table</li>
<li>Update the fields of the data table row</li>
</ul>
<p style="text-align:justify;">Since we have enabled paging for the gridview, we have to do this when ever user changes the page he/she is viewing to preserve his/her modifications.</p>
<p style="text-align:justify;">So we need to write our code in the <strong>PageIndexChanging </strong>event handler of the GridView.</p>
<p style="text-align:justify;">In my example I have two columns of the grid view called &#8220;ID&#8221; and &#8220;Name&#8221; and the name is the only template column I have used so I am only updating that column in the stored data table.</p>
<p>Code:</p>
<pre class="brush: csharp; title: ; notranslate">

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// get the datatable from the
DataTable dTable = (DataTable)Session[&quot;dataSource&quot;];

// now we will iterate through all rows of the grid
// then get the matching row from the data table (datasource of our grid)
// and append the updated data (by the user) to the selected data row
foreach (GridViewRow grv in this.GridView1.Rows)
{
// get the matching row from the data table
DataRow dRow = dTable.Rows.Find(this.GridView1.DataKeys[grv.RowIndex].Value);

// set values of updated columns : here I have only let the user to edit &quot;Name&quot; column
dRow[&quot;Name&quot;] = ((TextBox)grv.FindControl(&quot;txtName&quot;)).Text;
}

// go to the next page of the grid
this.GridView1.PageIndex = e.NewPageIndex;
this.GridView1.DataSource = (DataTable)Session[&quot;DataSource&quot;];
this.GridView1.DataBind();

// show the whole collection of data in the second grid (used only to display)
this.GridView2.DataSource = (DataTable)Session[&quot;DataSource&quot;];
this.GridView2.DataBind();
}
</pre>
<p>I have used a different gridview called GridView2 to show the whole data source without paging.</p>
<p>So don&#8217;t misunderstand the use of GridView2 in the last section of the code. It&#8217;s used only do display the whole set of data (without paging).</p>
<p>I cannot upload my code into this blog because it seems like zip files are not supported. If you like to take a glance of my code just add a comment so I&#8217;ll send the code to you via email.</p>
<p style="text-align:justify;"><span style="color:#008000;">Was this post helpful to you? How can I improve? &#8211; </span><span style="color:#008000;">Your comment is highly appreciated!</span></p>
<p style="text-align:justify;"><span style="color:#c0c0c0;">Cassian Menol Razeek</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ilearnttoday.com/c-aspnet-gridview-how-to-keep-modified-data-of-template-fields-when-paging-is-enabled/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

