<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3726050755669934165</id><updated>2011-11-27T16:28:08.754-08:00</updated><category term='Javacript Internals'/><category term='Debug Javascript'/><title type='text'>C# / Asp.Net / AJAX / Sql Blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>23</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-7196973830131320216</id><published>2010-12-16T20:32:00.001-08:00</published><updated>2010-12-16T20:32:32.114-08:00</updated><title type='text'>Hello Swati</title><content type='html'>&lt;span xmlns=''&gt;&lt;p&gt;Hi This is Swati
&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Writing a test blog post from MS Word
&lt;/li&gt;&lt;li&gt;&lt;span style='background-color:red'&gt;Kaise ho
&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-7196973830131320216?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/7196973830131320216/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=7196973830131320216' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/7196973830131320216'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/7196973830131320216'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2010/12/hello-swati.html' title='Hello Swati'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-9216099496689222430</id><published>2008-12-13T19:49:00.001-08:00</published><updated>2008-12-13T19:49:41.283-08:00</updated><title type='text'>SQL Interview Questions - Time Series Based Problems</title><content type='html'>&lt;p&gt;   &lt;br /&gt;I was just wondering about time-series based SQL problems, and decided to put up a data sample based on the tea &amp;amp; chocolate consumption of Microsoft &amp;amp; Sun Microsystems. Let's take the sample data below.&lt;/p&gt;  &lt;table style="width: 583pt; border-collapse: collapse" cellspacing="0" cellpadding="0" width="776" border="0" x:str="x:str"&gt;&lt;colgroup&gt;&lt;col style="width: 82pt; mso-width-source: userset; mso-width-alt: 3986" width="109" /&gt;&lt;col style="width: 65pt; mso-width-source: userset; mso-width-alt: 3145" width="86" /&gt;&lt;col style="width: 53pt; mso-width-source: userset; mso-width-alt: 2560" width="70" /&gt;&lt;col style="width: 87pt; mso-width-source: userset; mso-width-alt: 4242" width="116" /&gt;&lt;col style="width: 69pt; mso-width-source: userset; mso-width-alt: 3364" width="92" /&gt;&lt;col style="width: 53pt; mso-width-source: userset; mso-width-alt: 2596" width="71" /&gt;&lt;col style="width: 81pt; mso-width-source: userset; mso-width-alt: 3949" width="108" /&gt;&lt;col style="width: 93pt; mso-width-source: userset; mso-width-alt: 4534" width="124" /&gt;&lt;/colgroup&gt;&lt;tbody&gt;     &lt;tr style="height: 12.75pt" height="17"&gt;       &lt;td class="xl24" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; width: 82pt; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: #ff9900" align="center" width="109" height="17"&gt;&lt;strong&gt;&lt;span style="font-size: 10pt; font-family: arial"&gt;SALESORDERID&lt;/span&gt;&lt;/strong&gt;&lt;/td&gt;        &lt;td class="xl24" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; font-weight: bold; font-size: 10pt; border-left-color: windowtext; width: 65pt; border-bottom: windowtext 0.5pt solid; font-family: arial; background-color: #ff9900" align="center" width="86"&gt;ITEM_NAME&lt;/td&gt;        &lt;td class="xl25" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; font-weight: bold; font-size: 10pt; border-left-color: windowtext; width: 53pt; border-bottom: windowtext 0.5pt solid; font-family: arial; background-color: #ff9900" align="center" width="70"&gt;QUANTITY&lt;/td&gt;        &lt;td class="xl25" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; font-weight: bold; font-size: 10pt; border-left-color: windowtext; width: 87pt; border-bottom: windowtext 0.5pt solid; font-family: arial; background-color: #ff9900" align="center" width="116" x:str="COST_PER_UNIT "&gt;COST_PER_UNIT&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;/td&gt;        &lt;td class="xl26" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; font-weight: bold; font-size: 10pt; border-left-color: windowtext; width: 69pt; border-bottom: windowtext 0.5pt solid; font-family: arial; background-color: #ff9900" align="center" width="92" x:str="ORDERDATE "&gt;ORDERDATE&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;/td&gt;        &lt;td class="xl26" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; font-weight: bold; font-size: 10pt; border-left-color: windowtext; width: 53pt; border-bottom: windowtext 0.5pt solid; font-family: arial; background-color: #ff9900" align="center" width="71"&gt;DUEDATE&lt;/td&gt;        &lt;td class="xl24" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; font-weight: bold; font-size: 10pt; border-left-color: windowtext; width: 81pt; border-bottom: windowtext 0.5pt solid; font-family: arial; background-color: #ff9900" align="center" width="108" x:str="ORDERSTATUS "&gt;ORDERSTATUS&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;/td&gt;        &lt;td class="xl24" style="border-right: windowtext 0.5pt solid; border-top: windowtext 0.5pt solid; font-weight: bold; font-size: 10pt; border-left-color: windowtext; width: 93pt; border-bottom: windowtext 0.5pt solid; font-family: arial; background-color: #ff9900" align="center" width="124" x:str="CUSTOMERNAME "&gt;CUSTOMERNAME&lt;span style="mso-spacerun: yes"&gt;&amp;#160;&lt;/span&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-weight: bold; font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;1&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;45.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;1.2900&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39507"&gt;2/29/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39538"&gt;3/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;2&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;30.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;1.2500&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39568"&gt;4/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;3&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;90.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;1.5000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39599"&gt;5/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;4&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;12.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39629"&gt;6/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39691"&gt;8/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;5&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;34.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;4.3800&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39507"&gt;2/29/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39568"&gt;4/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;6&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;45.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;3.9900&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39538"&gt;3/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39599"&gt;5/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;7&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;79.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;3.5000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39568"&gt;4/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;8&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;36.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;5.3800&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39629"&gt;6/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;9&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;12.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;4.3800&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;10&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;TEA&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;50.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;4.2200&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39690"&gt;8/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39721"&gt;9/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;11&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;110.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;0.6900&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39538"&gt;3/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39568"&gt;4/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;12&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;130.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;1.2200&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39568"&gt;4/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39599"&gt;5/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;13&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;76.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;0.5500&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39599"&gt;5/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39629"&gt;6/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;14&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;200.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;0.8900&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39629"&gt;6/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;15&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;230.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;0.2300&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39691"&gt;8/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;16&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;210.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;0.7800&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39691"&gt;8/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39721"&gt;9/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;17&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;199.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;1.1000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39721"&gt;9/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39752"&gt;10/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;SUN&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;18&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;102.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39507"&gt;2/29/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39538"&gt;3/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;19&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;245.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39538"&gt;3/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39568"&gt;4/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;20&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;312.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39568"&gt;4/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39599"&gt;5/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;21&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;345.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39599"&gt;5/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39629"&gt;6/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;22&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;307.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39629"&gt;6/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;23&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;120.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39644"&gt;7/15/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;24&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;300.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39660"&gt;7/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39691"&gt;8/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;25&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;299.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39691"&gt;8/31/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39721"&gt;9/30/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;26&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;290.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39721"&gt;9/30/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39752"&gt;10/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;27&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;10.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39726"&gt;10/5/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39752"&gt;10/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;28&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;12.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39736"&gt;10/15/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39752"&gt;10/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;      &lt;tr style="font-size: 10pt; font-family: arial; height: 12.75pt" height="17"&gt;       &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; height: 12.75pt; background-color: transparent" align="center" height="17" x:num="x:num"&gt;29&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;CHOCOLATE&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;12.0000&lt;/td&gt;        &lt;td class="xl28" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="x:num"&gt;2.0000&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39741"&gt;10/20/2008&lt;/td&gt;        &lt;td class="xl29" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center" x:num="39752"&gt;10/31/2008&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;P&lt;/td&gt;        &lt;td class="xl27" style="border-right: windowtext 0.5pt solid; border-left-color: windowtext; border-top-color: windowtext; border-bottom: windowtext 0.5pt solid; background-color: transparent" align="center"&gt;MICROSOFT&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;     &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: green; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;--Write a query to get the TOTAL AMOUNT SPENT on tea consumption by each company between 03/31/2008 and 08/31/2008 &lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;SELECT&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt; CUSTOMERNAME&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: fuchsia"&gt;SUM&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: #000000"&gt;QUANTITY&lt;/span&gt;&lt;span style="color: gray"&gt;*&lt;/span&gt;&lt;span style="color: #000000"&gt;COST_PER_UNIT&lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;FROM&lt;/span&gt;&lt;span style="color: #000000"&gt; #TMP_SALES &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;WHERE&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt; ORDERDATE &lt;/span&gt;&lt;span style="color: gray"&gt;BETWEEN&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;'03/31/2008'&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;AND&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: red"&gt;'08/31/2008' &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;GROUP&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;BY&lt;/span&gt;&lt;span style="color: #000000"&gt; CUSTOMERNAME &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: #000000; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&amp;#160;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: green; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;--QUERY TO FIND AVERAGE NUMBER OF DAYS EACH CUSTOMER GIVES FOR AN ORDER &lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;SELECT&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt; CUSTOMERNAME&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: fuchsia"&gt;AVG&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: fuchsia"&gt;DATEDIFF&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: #000000"&gt;D&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: #000000"&gt; ORDERDATE&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: #000000"&gt; DUEDATE&lt;/span&gt;&lt;span style="color: gray"&gt;)) &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;FROM&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt; #TMP_SALES &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;GROUP&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;BY&lt;/span&gt;&lt;span style="color: #000000"&gt; CUSTOMERNAME &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: #000000; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&amp;#160;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: green; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;--QUERY TO FIND THE MONTHS WHEN EACH CUSTOMER DID &lt;/span&gt;&lt;font color="#008000"&gt;NOT PLACE&lt;/font&gt;&lt;/p&gt; &lt;/street&gt;--&lt;font color="#008000"&gt;ANY ORDERS &lt;/font&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: blue; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;SELECT&lt;/span&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;*&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: blue"&gt;FROM&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000"&gt;#TMP_SALES &lt;/span&gt;&lt;span style="color: blue"&gt;WHERE&lt;/span&gt;&lt;span style="color: #000000"&gt; SALESORDERID &lt;/span&gt;&lt;span style="color: gray"&gt;NOT&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;IN &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;( &lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000; mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;SELECT&lt;/span&gt;&lt;span style="color: #000000"&gt; T_OUTER&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;SALESORDERID &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000; mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;FROM&lt;/span&gt;&lt;span style="color: #000000"&gt; #TMP_SALES T_OUTER &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000; mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: gray"&gt;INNER&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;JOIN&lt;/span&gt;&lt;span style="color: #000000"&gt; #TMP_SALES T_INNER &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000; mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: blue"&gt;ON&lt;/span&gt;&lt;span style="color: #000000"&gt; T_OUTER&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;CUSTOMERNAME &lt;/span&gt;&lt;span style="color: gray"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; T_INNER&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;CUSTOMERNAME &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000; mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: gray"&gt;AND&lt;/span&gt;&lt;span style="color: #000000"&gt; T_OUTER&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;ITEM_NAME &lt;/span&gt;&lt;span style="color: gray"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; T_INNER&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;ITEM_NAME &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt; mso-layout-grid-align: none"&gt;&lt;span style="font-size: 10pt; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;span style="color: #000000; mso-tab-count: 1"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/span&gt;&lt;span style="color: gray"&gt;AND&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: fuchsia"&gt;MONTH&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: #000000"&gt;T_OUTER&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;ORDERDATE&lt;/span&gt;&lt;span style="color: gray"&gt;)&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;=&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: fuchsia"&gt;MONTH&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: fuchsia"&gt;DATEADD&lt;/span&gt;&lt;span style="color: gray"&gt;(&lt;/span&gt;&lt;span style="color: #000000"&gt;M&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: #000000"&gt; &lt;/span&gt;&lt;span style="color: gray"&gt;-&lt;/span&gt;&lt;span style="color: #000000"&gt;1&lt;/span&gt;&lt;span style="color: gray"&gt;,&lt;/span&gt;&lt;span style="color: #000000"&gt; T_INNER&lt;/span&gt;&lt;span style="color: gray"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;ORDERDATE&lt;/span&gt;&lt;span style="color: gray"&gt;)) &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;)&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;font color="#008000"&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoNormal" style="margin: 0in 0in 0pt"&gt;&lt;span style="font-size: 10pt; color: gray; font-family: &amp;#39;Courier New&amp;#39;; mso-no-proof: yes"&gt;&lt;font color="#008000"&gt;&amp;#160;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/span&gt;&lt;/span&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-9216099496689222430?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/9216099496689222430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=9216099496689222430' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/9216099496689222430'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/9216099496689222430'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2008/12/sql-interview-questions-time-series.html' title='SQL Interview Questions - Time Series Based Problems'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-9190030064480711639</id><published>2008-09-09T12:53:00.001-07:00</published><updated>2008-09-11T08:14:23.266-07:00</updated><title type='text'>Email Attachments using C#</title><content type='html'>&lt;p class="normal text"&gt;How to automatically generate e-mails with attachments from your C# Code ?&lt;/p&gt;&lt;p class="normal text"&gt;Now-a-days everyone wants Emails to be generated from the applciaiton itself. in my previous blog I have already discussed how to generate simple text e-mails.&lt;/p&gt;&lt;p class="normal text"&gt;But if you want to generate e-mails with attachments , still its not difficult at all. I have done it for sending an Excel Attachment. The txt attachment again is simpler, you just need to follow the same logic as excel but less complicated to copy and send. So, Lets Start.&lt;/p&gt;&lt;pre&gt;&lt;span style="font-family:georgia;"&gt;&lt;b&gt;PART I &lt;/b&gt;

The code below shows the following steps for copying the excel sheet to be posted into the mailing attachment sheet(If you already have the sheet and just need to mail it, you can skip this part):-&lt;/span&gt;&lt;span style="font-family:georgia;"&gt;
&lt;b&gt;1. &lt;/b&gt;Create a new excel workbook.
&lt;b&gt;2. &lt;/b&gt;Create a new Directory.
&lt;b&gt;3. &lt;/b&gt;Copy the old sheet to the new workbook sheet
&lt;b&gt;4. &lt;/b&gt;You can turn on the displays on/off for the sheet by just doing
          application.displayAlerts = false/true;
&lt;b&gt;5. &lt;/b&gt;Save the new workbook with the name required and close the excel.For saving
          you can use
            newWorkbook.saveAs(Save Name,System.Type.Missing,
            System.Type.Missing,System.Type.Missing,false, false,
            XlSaveAsAccessMode.xlNoChange,System.Type.Missing,
            System.Type.Missing,System.Type.Missing,
            System.Type.Missing,System.Type.Missing);
          and for closing you can use
            newWorkbook.Close(false,false,System.Type.Missing);
&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="normal text"&gt;
&lt;span style="font-family:georgia;"&gt;&lt;b&gt;PART II &lt;/b&gt;

Now, the steps below shows the e-mailing of the excel sheet as an attachment.
&lt;b&gt;1. &lt;/b&gt;Make an object of MailMessage.
&lt;b&gt;2. &lt;/b&gt;Set the parameters ,
          TO(toAddress); FROM(fromAddress); SUBJECT(a string one liner);     
          BODY(message to write inside the main body of mail);
&lt;b&gt;3. &lt;/b&gt;Set the MailAttachment object with the filename to send an simply add the
           Attachment to the mail message.
&lt;b&gt;4. &lt;/b&gt;SmtpMail.SmptServer needs to be set. It is the address of your office mail
          server.And then finally the message needs to be send, SmtpMail.Send();&lt;/span&gt;
&lt;/pre&gt;

&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: Consolas, "Courier New", Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SendEmail()
{

    Excel.Workbook newWorkbook = &lt;span class="kwrd"&gt;this&lt;/span&gt;.thisApplication.Workbooks.Add
                                 (XlWBATemplate.xlWBATWorksheet);

    &lt;span class="kwrd"&gt;string&lt;/span&gt; windowsLogin = Environment.UserName.ToString();

    &lt;span class="kwrd"&gt;object&lt;/span&gt; m = System.Reflection.Missing.Value;

    &lt;span class="kwrd"&gt;string&lt;/span&gt; fMsg = windowsLogin + &lt;span class="str"&gt;@"@gmail.com"&lt;/span&gt;;

    &lt;span class="kwrd"&gt;string&lt;/span&gt; note = &lt;span class="str"&gt;""&lt;/span&gt;;

    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {

         Directory.CreateDirectory(&lt;span class="str"&gt;"ForEmail"&lt;/span&gt;);

         Directory.SetCurrentDirectory(&lt;span class="str"&gt;"ForEmail"&lt;/span&gt;);

         oldSheet.Copy(newWorkbook.Sheets[1],System.Type.Missing);

         Excel.Worksheet emailingSheet = ExcelHelpers.GetWorksheet
                                          (newWorkbook, &lt;span class="str"&gt;"Recap"&lt;/span&gt;);

         Excel.Range tempRange= emailingSheet.UsedRange;

         Excel.Worksheet copySheet = ExcelHelpers.GetWorksheet
                                          (newWorkbook, &lt;span class="str"&gt;"Sheet1"&lt;/span&gt;);

         newWorkbook.Sheets.FillAcrossSheets
                                 (tempRange,XlFillWith.xlFillWithAll);
         &lt;span class="kwrd"&gt;string&lt;/span&gt; accountName = acctComboBox.Text.Trim();

         copySheet.Cells[5,2] = accountName;

         thisApplication.DisplayAlerts = &lt;span class="kwrd"&gt;false&lt;/span&gt;;

         emailingSheet.Delete();

         thisApplication.DisplayAlerts = &lt;span class="kwrd"&gt;true&lt;/span&gt;;

         copySheet.Columns.AutoFit();

         newWorkbook.SaveAs(&lt;span class="str"&gt;"Info.xls"&lt;/span&gt;,System.Type.Missing,
            System.Type.Missing,System.Type.Missing,&lt;span class="kwrd"&gt;false&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;,
            XlSaveAsAccessMode.xlNoChange,System.Type.Missing,
            System.Type.Missing,System.Type.Missing,
            System.Type.Missing,System.Type.Missing);

         newWorkbook.Close(&lt;span class="kwrd"&gt;false&lt;/span&gt;,&lt;span class="kwrd"&gt;false&lt;/span&gt;,System.Type.Missing);
       

       

//***************************PART TWO BEGINS HERE******************************//

         &lt;span class="kwrd"&gt;string&lt;/span&gt; to = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

         &lt;span class="kwrd"&gt;for&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; r = 2; r &amp;lt; 10; r++)

         {

             &lt;span class="kwrd"&gt;if&lt;/span&gt;(((Range)mEmailSheet.Cells[r, 1]).Text != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp;

                  ((&lt;span class="kwrd"&gt;string&lt;/span&gt;)((Range)mEmailSheet.Cells[r, 1]).Text).Length &amp;lt; 1)

             {

                     &lt;span class="kwrd"&gt;break&lt;/span&gt;;

             }

             &lt;span class="kwrd"&gt;if&lt;/span&gt;(to == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
               to = (&lt;span class="kwrd"&gt;string&lt;/span&gt;)((Range)mEmailSheet.Cells[r, 1]).Text+&lt;span class="str"&gt;";"&lt;/span&gt;;

             &lt;span class="kwrd"&gt;else&lt;/span&gt;

               to = to +((Range)mEmailSheet.Cells[r, 1]).Value2.ToString()+ &lt;span class="str"&gt;";"&lt;/span&gt;;

         }

         MailMessage message = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailMessage();

         message.To = to;

         message.From = fMsg.ToString();

         message.Subject=&lt;span class="str"&gt;"Email Submitted "&lt;/span&gt; ;  

         message.Body =&lt;span class="str"&gt;"Attachment enclosed"&lt;/span&gt;;

         Thread.Sleep(3000);

         DirectoryInfo dirInfo = &lt;span class="kwrd"&gt;new&lt;/span&gt; DirectoryInfo(Directory.GetCurrentDirectory
                                                                            ());

         FileInfo[] fInfo = dirInfo.GetFiles();

         &lt;span class="kwrd"&gt;string&lt;/span&gt; fileName = fInfo[0].Name;

         MailAttachment attach = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailAttachment
                                 (Directory.GetCurrentDirectory() +

                                 &lt;span class="str"&gt;@"\"+fileName,
                                 System.Web.Mail.MailEncoding.Base64);

         message.Attachments.Add(attach);

         SmtpMail.SmtpServer = "&lt;/span&gt;xyz.CompanyDomain.com&lt;span class="str"&gt;";

         SmtpMail.Send(message);

         MessageBox.Show("&lt;/span&gt;E-Mail send.&lt;span class="str"&gt;");

         Directory.SetCurrentDirectory("&lt;/span&gt;..&lt;span class="str"&gt;");

         Directory.Delete("&lt;/span&gt;ForEmail&lt;span class="str"&gt;",true);

     }

     catch(Exception e)

     {

          Console.WriteLine(e);

          newWorkbook.Close(false,false,System.Type.Missing);

          Directory.SetCurrentDirectory("&lt;/span&gt;..&lt;span class="str"&gt;");

          Directory.Delete("&lt;/span&gt;ForEmail",&lt;span class="kwrd"&gt;true&lt;/span&gt;);

     }

}
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-9190030064480711639?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/9190030064480711639/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=9190030064480711639' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/9190030064480711639'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/9190030064480711639'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2008/09/how-to-automatically-generate-e-mails.html' title='Email Attachments using C#'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-8050101970938730922</id><published>2008-06-04T08:55:00.000-07:00</published><updated>2008-09-11T08:12:45.268-07:00</updated><title type='text'>How to automatically generate E-mails from your C# code?</title><content type='html'>Generating E-mails through C# code can be very helpful to users. They just need to click a button and boom, the information is sent on the e-mail to the required people.

If you want to generate a normal E-mail without attachment, these are the steps you can write:--

1. You need to include ,
&lt;span style="color:#0033ff;"&gt;using&lt;/span&gt; System.Web.Mail;

2. The code for sending e-mail is as follows,

&lt;span style="color:#0033ff;"&gt;string&lt;/span&gt; userID = Environment.UserName.ToString();
MailMessage message = &lt;span style="color:#0033ff;"&gt;new &lt;/span&gt;MailMessage();
&lt;span style="color:#0033ff;"&gt;string&lt;/span&gt; windowsLogin = Environment.UserName.ToString();
&lt;span style="color:#0033ff;"&gt;string&lt;/span&gt; fromMsg =windowsLogin+@"@companyDomainName.com";
&lt;span style="color:#0033ff;"&gt;string&lt;/span&gt; toMsg = &lt;span style="color:#0033ff;"&gt;null &lt;/span&gt;;

toMsg = &lt;span style="color:#0033ff;"&gt;(string)&lt;/span&gt; ((Range)sheet.Cells[i,15]).Text; // In case of Excel Application "To field can take in any constant or user supplied value from Text box etc.

message.To = toMsg.ToString();
message.From = fromMsg.ToString();
message.Body = "STATUS HAS BEEN CONFIRMED. PLEASE CHECK YOUR RESPECTIVE UPDATES FROM THE APPLICATION.";
message.Subject=" STATUS CONFIRMED BY " + userID.ToUpper();
SmtpMail.SmtpServer = "server-name.com";
SmtpMail.Send(message);
&lt;span style="font-family:georgia;"&gt;Console.WriteLine(“E-mail Has Been Sent successfully”);


&lt;/span&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:georgia;"&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:georgia;font-size:100%;"&gt;You have to know your server name so that you can send an e-mail. For knowing this, go to your Outlook Express&lt;/span&gt;
&lt;?xml:namespace prefix = o /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p class="MsoNormal"&gt;&lt;span style="font-family:georgia;"&gt;Click on Tools --&gt; &lt;/span&gt;&lt;span style="font-family:georgia;"&gt;Send/Receive --&gt; &lt;/span&gt;&lt;span style="font-family:georgia;"&gt;Send/Receive Settings --&gt; &lt;/span&gt;&lt;span style="font-family:georgia;"&gt;Define Send/Receive Groups &lt;/span&gt;&lt;span style="FONT-FAMILY: Wingdings; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-: symbolfont-family:Arial;" &gt;
&lt;/span&gt;&lt;span style="font-family:georgia;"&gt;--&gt; Edit --&gt; &lt;/span&gt;&lt;span style="font-family:georgia;"&gt;Account Properties --&gt; &lt;/span&gt;&lt;/p&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:georgia;"&gt;There you find Microsoft Exchange Server&lt;/span&gt;&lt;span style="font-family:georgia;"&gt; name written in General Tab
&lt;/p&gt;&lt;/span&gt;&lt;p class="MsoNormal"&gt;&lt;span style="font-family:georgia;"&gt;Also in Tools --&gt; &lt;/span&gt;&lt;span style="font-family:georgia;"&gt;Options --&gt; &lt;/span&gt;&lt;span style="font-family:georgia;"&gt;Mail Setup --&gt; &lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-family:georgia;"&gt;
You can find Send/Receive Settings , this will take you to the same pop-up , Define Send/Receive &lt;span style="font-family:georgia;"&gt;Groups.&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:georgia;"&gt;
&lt;/span&gt;&lt;/span&gt;
In case you want to Email an attachment using C# , please read my another blog topic "Emailing Attachments ". &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-8050101970938730922?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/8050101970938730922/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=8050101970938730922' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/8050101970938730922'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/8050101970938730922'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2008/06/how-to-automatically-generate-e-mails.html' title='How to automatically generate E-mails from your C# code?'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-8231867791741985293</id><published>2008-06-03T12:47:00.000-07:00</published><updated>2008-09-11T08:06:12.956-07:00</updated><title type='text'>Using Microsoft.Office.Interop.Excel, How to sort rows in a worksheet?</title><content type='html'>It is very easy to sort rows using Microft.Office.Interop.Excel in a worksheet.

&lt;span style="color:#000099;"&gt;&lt;b&gt;PART I - SORTING BASED ON 1 OR 2 COLUMNS &lt;/b&gt;
&lt;/span&gt;We can use the Sort method of the NamedRange object to sort the data in a worksheet.

Just create a Range object i.e.
Excel.Range sRng;

Also, you already have a worksheet object,
Worksheet SummSheet;

Now assign Range to sRng ,

sRng = SummSheet.get_Range("A4","N" + rowNum);// here A4 is the starting cell and N"rowNum" is the ending cell


Apply this sort method


&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: Consolas, "Courier New", Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;
sRng.Sort(sRng.Columns[1,System.Type.Missing],XlSortOrder.xlAscending, sRng.Columns[10,System.Type.Missing], System.Type.Missing,XlSortOrder.xlAscending,  System.Type.Missing,XlSortOrder.xlAscending,XlYesNoGuess.xlNo,System.Type.Missing,System.Type.Missing,XlSortOrientation.xlSortColumns,XlSortMethod.xlPinYin,XlSortDataOption.xlSortNormal,XlSortDataOption.xlSortNormal,XlSortDataOption.xlSortNormal);&lt;/pre&gt;

In the above method we are sorting the rows as per 1st column .In case 1st column has same values the row will be sorted according to the 10th column. The Sorting Order is Ascending order.

The same can be applied for Descending Order also. Only the SortOrder needs to be changed.

&lt;span style="color:#000099;"&gt;&lt;b&gt;PART II - SORTING BASED ON MORE THAN 2 COLUMNS &lt;/b&gt;
&lt;/span&gt;In case you need to sort the rows based on more than 2 columns, we can implement ICOMPARABLE Interface's CompareTo method.

We can have a class implement IComparable Interface and then re-define the CompareTo method. For e.g.

&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: Consolas, "Courier New", Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TryCompare:IComparable
{
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ID
 {
  get
  {
   &lt;span class="kwrd"&gt;return&lt;/span&gt; Did;
  }
  set
  {
   Did = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
  }
 }
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; QuanDiff
 {
  get
  {
   &lt;span class="kwrd"&gt;return&lt;/span&gt; DQuanDiff;
  }
  set
  {
   DQuanDiff = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
  }
 }
 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; PriceDiff
 {
  get
  {
   &lt;span class="kwrd"&gt;return&lt;/span&gt; DPriceDiff;
  }
  set
  {
   DPriceDiff = &lt;span class="kwrd"&gt;value&lt;/span&gt;;
  }
 }


 &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; CompareTo(&lt;span class="kwrd"&gt;object&lt;/span&gt; obj)
 {
  TryCompare CompareObj =(TryCompare)obj;
  &lt;span class="kwrd"&gt;int&lt;/span&gt; compResults = &lt;span class="kwrd"&gt;this&lt;/span&gt;.ID.CompareTo(CompareObj.ID);
  &lt;span class="kwrd"&gt;if&lt;/span&gt;(compResults==0)
  {
   &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;.QuanDiff==CompareObj.QuanDiff)
   {
    &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;.PriceDiff==CompareObj.PriceDiff)
     &lt;span class="kwrd"&gt;return&lt;/span&gt; 0;
    &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;.PriceDiff&amp;gt;CompareObj.PriceDiff)
     &lt;span class="kwrd"&gt;return&lt;/span&gt; 1;
    &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;.PriceDiff&amp;amp;lt;CompareObj.PriceDiff)
                  &lt;span class="kwrd"&gt;return&lt;/span&gt; -1;
   }
   &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;.QuanDiff&amp;gt;CompareObj.QuanDiff)
   {
    &lt;span class="kwrd"&gt;return&lt;/span&gt; 1;
   }
   &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;.QuanDiff&amp;amp;lt;CompareObj.QuanDiff)
              {
               &lt;span class="kwrd"&gt;return&lt;/span&gt; -1;
              }
  }
  &lt;span class="kwrd"&gt;return&lt;/span&gt; compResults;
 }

}
&lt;/pre&gt;
So in the example above , we are sorting based on 3 values.
Now we just need to call ,

TryCompareObj.Sort();

This will solve all our sorting requirements.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-8231867791741985293?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/8231867791741985293/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=8231867791741985293' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/8231867791741985293'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/8231867791741985293'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2008/06/using-microsoftofficeinteropexcel-how.html' title='Using Microsoft.Office.Interop.Excel, How to sort rows in a worksheet?'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-182715618321426539</id><published>2008-06-03T12:29:00.000-07:00</published><updated>2008-06-03T12:47:21.209-07:00</updated><title type='text'>To convert an INT into ASCII Char</title><content type='html'>Converting INTEGER into an ASCII char is very simple . In C# we dont need to do anything special, just type-cast the INT into a CHAR.

int i = 65;
char a = (char) i;
Console.WriteLine("Result : "+a.toString());

Result : A

Converting ASCII char into an INTEGER is also same way but vice versa.Type-casting CHAR into an INT.

char a = 'A';
int i = (int) a;
Console.WriteLine("Result : "+i.toString());

Result : 65&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-182715618321426539?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/182715618321426539/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=182715618321426539' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/182715618321426539'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/182715618321426539'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2008/06/to-convert-int-into-ascii-char.html' title='To convert an INT into ASCII Char'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-5544736351178332958</id><published>2008-05-29T06:57:00.000-07:00</published><updated>2008-05-29T07:58:23.303-07:00</updated><title type='text'>Error : The assembly  could not be found at  or could not be loaded</title><content type='html'>I have an excel application created using .Net framework 1.1 and Microsoft Office Excel 2003. This application named CBlotter with the same settings and dll in all the user computers was running fine but only in 1 computer , I encountered the error saying


&lt;strong&gt;"The assembly CBlotter could not be found at .\CBlotter_bin\ or could not be loaded.

You can still edit and save the document.Contact your administrator or the author of this document for further assistance."&lt;/strong&gt;


I checked all the user permissioning of the folder.

I gave the full trust policy if not already given to the folder by using Caspol.exe(Code Access Security Policy Tool). This can be done by going to the specified v1.1/v2.0 folder.

If you want to grant full trust to a local folder , then type

caspol -u -ag All_Code -url C:\&lt;foldername&gt;\&lt;foldername&gt;\* FullTrust -n "&lt;name&gt;" -d
"&lt;description&gt;"

If you want to grant full trust to a netwrok folder , then type

caspol -pp off -m -ag LocalIntranet_Zone -url \\&lt;servername&gt;\&lt;foldername&gt;\* FullTrust -n "&lt;name&gt;" -d "&lt;description&gt;"

After assigning the right permissioning and full trust , usually the assembly loading/cannot find error goes away but in my case it dint.

So Now, I checked for the assemblies required for my .net code to run . In VS2003 we add reference to the COM library called 'Microsoft Excel 11.0 Object Library'. This helps us use the Excel Objects and write our piece of code using VS2003.

When I checked the library in assembly cache (GAC), using microsoft 1.1 configuration GUI, I was not able to locate the assembly. This actually raised a question as Microsoft Office Excel 2003 and .Net 1.1 framework was completely installed on User's PC then why were the Primary Interop Libraries (PIA) missing.
After researching I found out that these libraries require re-registration or installation sometimes when some other office application initiates a setup that causes library registration to be rewritten.

In my case Microsoft Excel SP3 installation had removed the PIAs altogether . So I just installed the PIAs again by going to the site &lt;a href="http://support.microsoft.com/kb/897646"&gt;http://support.microsoft.com/kb/897646&lt;/a&gt;

This solved my problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-5544736351178332958?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/5544736351178332958/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=5544736351178332958' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/5544736351178332958'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/5544736351178332958'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2008/05/error-assembly-could-not-be-found-at-or.html' title='Error : The assembly &lt;app name&gt; could not be found at &lt;location&gt; or could not be loaded'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-40469848370222253</id><published>2008-01-01T20:02:00.000-08:00</published><updated>2008-01-01T22:05:55.894-08:00</updated><title type='text'>Access Previous Page's Controls Using Cross Page Postback</title><content type='html'>&lt;p class="subHeading"&gt;
    How to access previous page's controls
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    Before Asp.Net 2.0 was introduced, accessing the previous page's controls from 
    a given page was a tricky affair. You had to use nice but not so right features 
    like Session, HttpContext, even cookies in some cases, to persist relevant 
    information from one page to another. Session is useful when you have to 
    persist a bunch of data across the user's session, but it is not suitable for 
    passing random values between pages. The primary reason for this being that as 
    your application gets more and more complex, the Session state could become 
    cluttered and confusing because of similarly named session values, and could 
    easily become a maintainence nightmare. After a period of time, you would not 
    remember what Session state variables you used to pass values between which 
    pages.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    Asp.Net 2.0 comes with a very handy feature called the PreviousPage property. 
    This is a public property of the Page class, and refers to the PreviousPage 
    instance. Using this property, you can access the previous page's &lt;b&gt;public&lt;/b&gt; 
    properties. You can also access the previous page's controls using the 
    FindControll method.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    Let us take an example. Suppose we have the following web page, that has a 
    simple textbox and a button. Note that the button's &lt;b&gt;PostBackUrl&lt;/b&gt; property 
    is set to another page, meaning that when the button is clicked, the current 
    webform will post back to the PostBackUrl page (If you are not clear with cross 
    page HTTP postbacks, look at &lt;a href="javascript:window.open('http://dotnetsavvyblog.blogspot.com/2007/12/passing-values-using-http-post-in.html');"&gt;
     this post&lt;/a&gt;).
   &lt;/p&gt;
   &lt;pre class="csharpcode"&gt;
    &lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %&amp;gt;&lt;/span&gt;

    &lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="Button1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;PostBackUrl&lt;/span&gt;&lt;span class="kwrd"&gt;="~/Default2.aspx"&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Button"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="TextBox1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:TextBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
     &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
   &lt;/pre&gt;
   &lt;p class="normalText"&gt;
    What happens here is that Asp.Net looks at the PostBackUrl property of the 
    button and understands that form needs to be submitted to another form. To 
    achieve this, it emits a javascript function called &lt;b&gt;WebForm_DoPostBackWithOptions&lt;/b&gt;
    that makes sure that the form is correctly submitted to another page. To 
    further understand what I am saying, look at the source for your page (right 
    click, view source). Here's what our button looks like in actual HTML :
   &lt;/p&gt;
   &lt;pre class="csharpcode"&gt;
     &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="Button1"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Button"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&amp;amp;quot;Button1&amp;amp;quot;, &amp;amp;quot;&amp;amp;quot;, false, &amp;amp;quot;&amp;amp;quot;, &amp;amp;quot;Default2.aspx&amp;amp;quot;, false, false))"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Button1"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
   &lt;/pre&gt;
   &lt;p class="normalText"&gt;
    Now to understand fully how Asp.Net posts back to another form, we must first 
    understand the mechanism Asp.Net uses to postback a form. If you carefully look 
    at the above HTML source for the button, you will see that onclick, the button 
    calls a javascript method called [WebForm_DoPostBackWithOptions]. This method 
    comes out of the box with Asp.Net. To view it's contents, we need to find the 
    Javascript file to which the method belongs to. If you glance at the HTML 
    source of the page, you will see that there is a file called WebResource.axd 
    included with your page :
   &lt;/p&gt;
   &lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="/WebSites1/WebResource.axd?d=wKUbMd8wFV3uZ8WZXaQryA2&amp;amp;amp;t=633245101798773778"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
   &lt;/pre&gt;
   &lt;p class="normalText"&gt;
    To look at the actual webresource.axd, do this : Internet Explorer --&gt; Tools 
    --&gt; Settings --&gt; View Files. This will open up a folder, where there will be 
    one or many instances of WebResource.axd. This is a standard Javascript file 
    that contains common Asp.Net page related functionality.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    You can go through the WebForm_DoPostBackWithOptions method in the file to 
    understand the exact mechanism for postback. Specifically, note how the 
    [action] property of the webform is changed to the other page. Upon form 
    submission, Asp.Net posts the form to the other page, instead of doing a normal 
    page postback to itself. Upon postback, even though the form posts to another 
    page, the original page's page lifecycle executes upto the [OnLoadComplete] 
    event. After that, Asp.Net transfers the page execution to the other page (I 
    assume it does a Server.Transfer), and also sets the IsCrossPagePostback 
    property for the next page. Once on the other page, it continues the normal 
    page lifecycle of the other page, and renders on page.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    All this can get a bit confusing, so let's go through the entire thing again :
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    1. The first page is Page_A. User clicks a button that has the PostBackURL 
    property set to Page_B.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    2. Upon the button click, the [WebForm_DoPostBackWithOptions] javascript method 
    is called. This method is part of the WebResource.axd file.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    3. This method sets the form's [action] property to the Page_B, and posts the 
    form.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    4. Page_A page lifecycle starts executing upto the OnLoadComplete event, after 
    which Asp.Net transfers execution to the Page_B, also setting Page_B's 
    [IsCrossPagePostback] property on the way. Also, Page_B's PreviousPage property 
    is set to the Page instance object of Page_A. (You know that each page is 
    compiled into an object that derives from System.Web.UI.Page, right. That's the 
    Page Instance Object I was referring to.)
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    5. Page_B page now starts executing it's normal page lifecycle. Since 
    PreviousPage refers to the instance of Page_A, you can access any public 
    property on the page, any web control on the page, infact, you can call public 
    methods on Page_A.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    6. Page_B now executes its normal page lifecycle, accessing public 
    properties/methods/controls on Page_A if required, and renders it's HTML.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    I would have loved to explain how I figured out all this internal stuff about 
    Cross Page postbacks, but can't for "lack of space" (it's more like "lack of 
    desire to keep on drooling on the same thing" ;) ), but you can take a look at 
    the source code &lt;a onclick="javascript:window.open('http://aspspider.info/sdhoble123/articlesite/a%5F3/crosspage/codeview');return false;" href="javascript:return false;"&gt;right here&lt;/a&gt; I used to figure out what I did. You can put this 
    code into Debug, setting breakpoints at various key methods to understand how 
    it works.
   &lt;/p&gt;
   &lt;p class="normalText"&gt;
    An oh yes, do remember that you can access 1. Public Properties, 2. Page 
    Controls, 3. Static Variables, 4. Call public methods, using the PreviousPage 
    property. So go ahead and play around with this powerful feature, and find 
    interesting ways to use it in your Asp.Net WebApps.
   &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-40469848370222253?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/40469848370222253/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=40469848370222253' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/40469848370222253'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/40469848370222253'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2008/01/access-previous-pages-controls-using.html' title='Access Previous Page&apos;s Controls Using Cross Page Postback'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-7649468217485113499</id><published>2007-12-27T20:42:00.001-08:00</published><updated>2007-12-27T20:42:37.882-08:00</updated><title type='text'>Passing values using HTTP POST in Asp.Net</title><content type='html'>&lt;div class="subHeading"&gt;
            By doing HTTP POST to another page
        &lt;/div&gt;
        &lt;p class="normalText"&gt;
            A lot of Asp.Net developers might not be aware of this, but one of the ways of passing
            values from one page to another is a normal HTTP POST. Before we dive into it, let
            me ask if you know exactly what this means : "An Asp.Net webform posts back to itself".
        &lt;/p&gt;
        &lt;p class="normalText"&gt;
            Basically, when you click on a button to submit a webform, you are sending that
            form back to the server. Here, webform means whatever falls between the &amp;lt;form&amp;gt;&amp;lt;/form&amp;gt;
            tags on your page. In technologies such as ASP, you can have multiple &amp;lt;form&amp;gt;&amp;lt;/form&amp;gt;
            elements on the same web page. When the user posts back the form, the [action] attribute
            of the form decides to which page the form gets submitted.
        &lt;/p&gt;
        &lt;p class="normalText"&gt;
            For example, suppose you have a form that looks like this :
        &lt;/p&gt;
        &lt;div class="csharpcode"&gt;
            &lt;pre class="alt"&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;action&lt;/span&gt;&lt;span
    class="kwrd"&gt;="PostPage.aspx"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="SimplePageForm"&lt;/span&gt; &lt;span
        class="attr"&gt;method&lt;/span&gt;&lt;span class="kwrd"&gt;="Post"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
            &lt;pre&gt;    Please enter text here that you want to see on the next page : &lt;span class="kwrd"&gt;
                &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span
                    class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="myText"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span
                        class="kwrd"&gt;="theTxt"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
            &lt;pre class="alt"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;hr&lt;/span&gt; &lt;span
                class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
            &lt;pre&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span
                class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="btn"&lt;/span&gt; &lt;span
                    class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSubmit"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
            &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span
                class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
        &lt;/div&gt;
        &lt;p class="normalText"&gt;
            We basically want to create a form that posts to some other page. For e.g., our
            current form has action="PostPage.aspx". This means that when you submit the current
            page, it shall post back to PostPage.aspx page, and not to itself. The current FORM's
            elements shall be available on this other ASPX page, and can be accessed using the
            .net Request object.
        &lt;/p&gt;
        &lt;p class="normalText"&gt;
            Let me dwell a little bit more on this. On the current form, you have a textbox
            with the [name] property set to "myText". When you post this page, the entire form's
            data posts back to the server as a name-value collection. Meaning, a name-value
            collection will be sent back to the server, where one entry has name = "myText",
            and value = whatever value you entered in the textbox. There will be similar name-value
            pair entries for other controls on the page. As an aside, note that HTML handles
            the POSTed values differently for different controls. For e.g., for a textbox, the
            value is set to whatever text you enter in the textbox, whereas for a dropdown list,
            it will be set to the value that has been selected at the time of postback.
        &lt;/p&gt;
        &lt;p class="normalText"&gt;
            Bear in mind that the form is posted to a different page, i.e., PostPage.aspx, so
            the name-value collection is accessible on the PostPage.aspx. Instead of providing
            you with the raw posted values, Asp.Net wraps this information in the Request object.
            You can access the posted value using &lt;b&gt;Request.Form["myText"]&lt;/b&gt;. Again, as an
            aside ;), if you are using &amp;lt;input type="file"&amp;gt; on your form, i.e., if you
            are using a file upload control, the story is slightly different. In this case,
            you can access the path of the files to be uploaded using Request.Files.
        &lt;/p&gt;
        &lt;p class="normalText"&gt;
            Finally, all we need to do in the PostPage.aspx is to access the posted values using
            the Request.Form collection. Take a look at the source code below, before we move
            to the final "prescriptive guidance" for this type of solution.
        &lt;/p&gt;
        &lt;div class="csharpcode"&gt;
            &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;/pre&gt;
            &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data;&lt;/pre&gt;
            &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Configuration;&lt;/pre&gt;
            &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections;&lt;/pre&gt;
            &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;/pre&gt;
            &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Security;&lt;/pre&gt;
            &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI;&lt;/pre&gt;
            &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls;&lt;/pre&gt;
            &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls.WebParts;&lt;/pre&gt;
            &lt;pre&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.HtmlControls;&lt;/pre&gt;
            &lt;pre class="alt"&gt;&amp;nbsp;&lt;/pre&gt;
            &lt;pre&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; A_2_Default : System.Web.UI.Page&lt;/pre&gt;
            &lt;pre class="alt"&gt;{&lt;/pre&gt;
            &lt;pre&gt;    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span
                class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)&lt;/pre&gt;
            &lt;pre class="alt"&gt;    {&lt;/pre&gt;
            &lt;pre&gt;    Response.Write(&lt;span class="str"&gt;"You typed in : "&lt;/span&gt; + Request.Form[&lt;span
                class="str"&gt;"myText"&lt;/span&gt;]);&lt;/pre&gt;
            &lt;pre class="alt"&gt;    }&lt;/pre&gt;
            &lt;pre&gt;}&lt;/pre&gt;
        &lt;/div&gt;
        &lt;p class="normalText"&gt;
        As is evident, we just get the posted value for the control named "myText" using the Request.Form collection, and print it out.
        &lt;/p&gt;
        &lt;p class="normalText"&gt;
        The above solution is not feasible if you are trying to pass values between ASPX pages. The simple reason for this being that Asp.Net does not allow &amp;lt;form&amp;gt;&amp;lt;/form&amp;gt; elements to post to any
        other form other than itself. However, you can have multiple HTML forms on your webpage (ones without runat="server"). The advantage of doing this is that it allows you to show one/more forms to the user at the same time. Depending
        upon the user action, one of the form is posted back. This way, each form can have its own "processing page" to which it posts back on each submit. I'm not saying this is the best practice solution, but just that even simple HTTP POST can be handy at times.
        &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-7649468217485113499?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/7649468217485113499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=7649468217485113499' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/7649468217485113499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/7649468217485113499'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/12/passing-values-using-http-post-in.html' title='Passing values using HTTP POST in Asp.Net'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-1394583941698178125</id><published>2007-12-05T10:42:00.000-08:00</published><updated>2007-12-05T21:06:57.143-08:00</updated><title type='text'>How to run serverside code from client side script</title><content type='html'>In the last article, we saw how to access server side control values on the client side. However, an even more interesting (and lesser known) mechanism in Asp.Net is running server side code in client side script. This can come in very handy in some situations, as we'll see through the following example.
Suppose we need to create a graphical representation of some quantity. Let us say we have two variables on the server side, a [barCount] variable, to indicate the value to be shown on the graph, and a maxCount variable, that determines the maximum value that can be shown in the graph. To give you an idea of what I'm talking about, look at the following screenshot:
&lt;a href="http://bp3.blogger.com/_3nOSNIc4Nj0/R1b3PVA-KCI/AAAAAAAAADE/tPyWyr4uexw/s1600-h/untitled.bmp"&gt;&lt;img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://bp3.blogger.com/_3nOSNIc4Nj0/R1b3PVA-KCI/AAAAAAAAADE/tPyWyr4uexw/s400/untitled.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5140567867401316386" /&gt;&lt;/a&gt;
The variables [maxCount] and [barCount] are serverside variables in your C# code behind file. Note that they have to be made public. maxCount is the total number of bars on the graph, while barCount gives the actual value to be represented on the graph.
How did we do it ? One way, of course, is to use a repeater control, and modify it to render the required output. We are not particularly in favor of this approach, because a repeater is more conducive to databinding kind of functionality, not the one we are discussing here. Instead, here's the code we used :

&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: Consolas, "Courier New", Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
You Entered :
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
maxCount = &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=maxCount &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
barCount = &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=barCount &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;table&lt;/span&gt; &lt;span class="attr"&gt;width&lt;/span&gt;&lt;span class="kwrd"&gt;="100%"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;&lt;span class="kwrd"&gt;for&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; maxCount; i++ ) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
               &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;{ &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
                  &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;  &lt;span class="kwrd"&gt;if&lt;/span&gt;( i &amp;lt;= barCount )  &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;  { &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="border-right: #000000 1px solid; border-top: #000000 1px solid; border-left: #000000 1px solid;
color: #6600ff; border-bottom: #000000 1px solid; background-color: #0000cc;"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="attr"&gt;&amp;amp;nbsp;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; }&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; else&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;  { &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="border-right: #000000 1px solid; border-top: #000000 1px solid; border-left: #000000 1px solid;
border-bottom: #000000 1px solid;"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="attr"&gt;&amp;amp;nbsp;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;  }&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;table&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;Recall that the &lt;label class="asp"&gt;&amp;lt;% &amp;nbsp; %&amp;gt;&lt;/label&gt; blocks are used to emit server side code on the client side. What is happening here is that when the Page HTML is being generated, the [for] loop code gets executed. Since we declared barCount &amp; maxCount as public variables, these are accessible in the code block. Depending on these values, an appropriate number of &lt;label class="kwrd"&gt;&amp;lt;&lt;/label&gt;&lt;label class="html"&gt;TD&lt;/label&gt;&lt;label class="kwrd"&gt;&amp;gt;&lt;/label&gt; elements are inserted in the code, which eventually gives us the output graph.
Please note that the script blocks are executed during the [RENDER] phase of the page. It means that if you are setting the variable values multiple times during your page lifecycle, the value set just prior to Render will be used. 

Keep in mind the following points about client code blocks :
 This mechanism was put in place for backward compatibility with ASP.
 Only public variables / properties / methods are accessible in the client code blocks.
 Should be used only where appropriate.
Check out the actual source code &lt;a href="http://aspspider.info/sdhoble123/articlesite/a_2/Default.aspx"&gt;here&lt;/a&gt;. View the running application &lt;a href="http://aspspider.info/sdhoble123/articlesite/a_2/Page_1.aspx"&gt;here&lt;/a&gt;.
Happy Coding !!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-1394583941698178125?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/1394583941698178125/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=1394583941698178125' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1394583941698178125'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1394583941698178125'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/12/how-to-run-serverside-code-from-client.html' title='How to run serverside code from client side script'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_3nOSNIc4Nj0/R1b3PVA-KCI/AAAAAAAAADE/tPyWyr4uexw/s72-c/untitled.bmp' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-1322336568140749906</id><published>2007-11-29T21:29:00.000-08:00</published><updated>2007-11-30T06:53:38.710-08:00</updated><title type='text'>How to refer a server side control inside client side script</title><content type='html'>Referencing a control inside a user control / master page on the client side is a little complicated because Asp.Net "fudges" the ID of all controls rendered as part of a user control, or a master page template. We'll look at the "why" of this a little later in the article, but let us look at the "how" of it with an example. Create a simple User Control which has a single button btnInput :
&lt;pre class="csharpcode"&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="UsrCtrl.ascx.cs" Inherits="A_1_UsrCtrl" %&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;function&lt;/span&gt; btnClicked(btnID)
    {
        &lt;span class="kwrd"&gt;var&lt;/span&gt; obj = document.getElementById(&lt;span class="str"&gt;"&amp;lt;%=btnInput.ClientID %&amp;gt;"&lt;/span&gt;);
        alert(&lt;span class="str"&gt;'There is a button named : '&lt;/span&gt; + obj.id + &lt;span class="str"&gt;' on this user control'&lt;/span&gt;);
    }
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btnInput"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="btnClicked()"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
Pay attention to the javascript function - we're getting the object using document.getElementById( ... ), and displaying an alert box with the ID of our button. Embed this on an Aspx page, and run it. When the button is clicked, you get the following error :
&lt;a href="http://bp1.blogger.com/_3nOSNIc4Nj0/R0-hW-ZNWmI/AAAAAAAAAC8/AiESM49g1Hg/s1600-R/untitled.bmp"&gt;&lt;img style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;" src="http://bp1.blogger.com/_3nOSNIc4Nj0/R0-hW-ZNWmI/AAAAAAAAAC8/kWDIdnXkfMM/s400/untitled.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5138503115930950242" /&gt;&lt;/a&gt;
So what happened ? To understand, view the source of your page (you can do this by right click on the page --&gt; View Source). Look at our button control in the rendered HTML, it looks something like this :
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="UsrCtrl1$btnInput"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="UsrCtrl1_btnInput"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="btnClicked()"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
What happened ? The ID of the User Control has been prepended to the front of the button's ID. You might be wondering, "why on earth would asp.net fudge the ID of controls". 

To understand why, imagine a situation where you have created five different user controls, each having a label named "btnInput". When you put all these five user controls on a single page, and if Asp.Net renders all the controls as is, we would have five buttons on the same webpage, having the ID "btnInput". This would not be acceptable, since each HTML element on a web page should have a unique ID. But in this case, when the page renders, there would be no way to distinguish which button is from which usercontrol, since all of them have the same ID. That is the reason for the following rule in Asp.Net :

"If a control is embedded in a user control / master page, it's ID property is prepended with the parent user control's ID when the page is rendered".

That is the reason that the user control's ID has been prepended to the button's ID in our above example. But this behavior creates problems in client side script. You would normally try to refer to a control as 
&lt;br /&gt;
document.getElementById([control id]
&lt;br /&gt;
But in our case, you can't just use the control's ID. You have to use the actual "fudged" ID of the control.

To account for this behavior in our client side javascript, we can use a handy asp.net control property called "ClientID". This property is always set to the actual ID of the control on the rendered page. Which means that if the control is not inside a user control, the ClientID would be same as the ID, but if the control is inside a user control, the ClientID will be 
[User Control ID]_[Control ID]. For e.g. in our case, ClientID will be set to "UsrCtrl1_btnInput". Here's how to use it to get the actual ID of a page webcontrol :

&lt;pre class="csharpcode"&gt;
    function btnClicked(btnID)
    {
        var obj = document.getElementById("&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;=btnInput.ClientID &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;");
        alert('There is a button named : ' + obj.id + ' on this user control');
    }&lt;/pre&gt;

Look at the highlighed code. The magic here is the &lt;span class="csharpcode"&gt;
 &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ... &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt; &lt;/span&gt; block. What this does is that when the page is rendered(as html), it executes the code between the &lt;pre class="csharpcode"&gt;
 &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= ... &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt; &lt;/pre&gt;, and places the result of the embedded code in its place. Please note the fact that the code blocks are evaluated after the Render page method fires. So, if you are changing the server side variable in different methods, (say, page_load, preRender, and some event handler), only the most recent value will be reflected on the client side (in our case, the value set in the preRender method). 

The above highlighted line looks like the following when the page is rendered :

&lt;pre class="csharpcode"&gt;
var obj = document.getElementById("UsrCtrl1_btnInput");&lt;/pre&gt;

Once you have this, you can access the control on the client side just like any other normal control. Interestingly, the &lt;%= %&gt; blocks are not limited to only control properties. You can even call the page's public methods, and the returned values will be substituted in the output HTML. For e.g., let's say we have a C# method codeBehindMethod() that always returns "TEST". The following line is gonna show an alert box with the message "TEST".
&lt;br /&gt;
&lt;pre class="csharpcode"&gt;
alert(&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= codeBehindMethod() &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;);&lt;/pre&gt;
&lt;br /&gt;
Until now, we saw how to access a server side variables in client side script. However, it is also possible to run your C# code on the client side. This can be put to use to achieve some pretty sleek functionality. In my next post, we'll see how to execute C# code on the client side to achieve convenient results.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-1322336568140749906?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/1322336568140749906/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=1322336568140749906' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1322336568140749906'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1322336568140749906'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/how-to-refer-server-side-control-inside.html' title='How to refer a server side control inside client side script'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_3nOSNIc4Nj0/R0-hW-ZNWmI/AAAAAAAAAC8/kWDIdnXkfMM/s72-c/untitled.bmp' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-1183340700619262183</id><published>2007-11-23T21:53:00.000-08:00</published><updated>2007-11-29T20:43:17.609-08:00</updated><title type='text'>How to pass values from popup window to calling page</title><content type='html'>Passing values from popup window to parent page can get tricky sometimes, especially if you are attempting to do heavy duty stuff in the popup window. The best way to do this is to create hidden variables on the parent page, and populate these from the popup window with whatever values need to be passed to the parent.
As usual, let us take an example. Suppose we have the following requirement :
1. Create an .aspx page, that opens a popup window on a button click.
2. The popup window that opens up should have a user information form that collects UserName, Address, Phone No.
3. Upon filling up the details, the user shall click a button that closes the window and passes the information to the main page.
4. The user information from the popup window should be displayed on the main page now.
So basically, we need to pass values from the popup window to the parent page. Let us look at the parent page code first :
&lt;pre class="csharpcode"&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;function&lt;/span&gt; openWindow()
        {
            window.open(&lt;span class="str"&gt;'/website3/testpage.aspx'&lt;/span&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="str"&gt;'height=200,width=400,status=yes,toolbar=no,menubar=no,location=no'&lt;/span&gt;);
            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        }
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="openWindow();"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;b&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Information from the popup window :&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;b&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                UserName :
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="lblUName"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                Address :
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="lblAddress"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                Phone no :
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="lblPhone"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;
Run the page and click on the button to open a popup window that shows the a page TestPage.aspx. This is the aspx page for our popup window. As per the requirements, this should have some data entry fields in which the user can enter values, and also a button that closes the window. Upon window close, the user-entered values should be persisted to the main page. Look at the code below :
&lt;pre class="csharpcode"&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" %&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Popup Window&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;function&lt;/span&gt; passValues()
        {
            ;
        }
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                UserName :
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="txtUName"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                Address :
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="txtAddress"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                Phone No. :
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="txtPhone"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="passValues(); window.close()"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
Note that we have created the function passValues but have not yet implemented it. Now run the main page, you should see something like this :
&lt;a href="http://bp3.blogger.com/_3nOSNIc4Nj0/R0e-seZNWkI/AAAAAAAAACs/TsqVj8dPcGs/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5136283571321657922" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_3nOSNIc4Nj0/R0e-seZNWkI/AAAAAAAAACs/TsqVj8dPcGs/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt;
So much for laying the groundwork. The tough task now is to propagate the values that the user enters in the popup window, to the parent page. As you can guess, we'll have to first access the popup window's parent window, and once we have the parent window reference, we can get the required elements by doing the following :
[parentWindow Object].document.getElementById('lblUName');
To access an element on the parent window, you can do the following :

window.opener.document.getElementById('lblPhone').innerText = 'xyz';

Look at the code below to get a better idea of what we are talking about :
&lt;pre class="csharpcode"&gt;
        function passValues()
        {
            window.opener.document.getElementById('lblUName').innerText = document.getElementById('txtUName').value;
            window.opener.document.getElementById('lblAddress').innerText = document.getElementById('txtAddress').value;
            window.opener.document.getElementById('lblPhone').innerText = document.getElementById('txtPhone').value;
        }&lt;/pre&gt;
This function grabs the window's parentWindow's document object, and searches for the required elements (lblUName, lblAddress, lblPhone) therein. It assigns these objects the values from the popup window textboxes.
Now to complicate things a little bit further, let us try to access elements of the parent page that are in an iFrame. Here's the (modified) parent page :
&lt;pre class="csharpcode"&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
.
.
.
.
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                Phone no :
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="lblPhone"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;iframe&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="HTMLPage.htm"&lt;/span&gt; &lt;span class="attr"&gt;width&lt;/span&gt;&lt;span class="kwrd"&gt;="400px"&lt;/span&gt; &lt;span class="attr"&gt;height&lt;/span&gt;&lt;span class="kwrd"&gt;="200px"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;iframe&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
Confused ? Review the screenshot below to jog your memory :

&lt;a href="http://bp1.blogger.com/_3nOSNIc4Nj0/R0e_v-ZNWlI/AAAAAAAAAC0/6IIFBg2qeGg/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5136284730962827858" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_3nOSNIc4Nj0/R0e_v-ZNWlI/AAAAAAAAAC0/6IIFBg2qeGg/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt;
Our goal here is this :
-- When the user clicks the Submit button on the popup window, the UserName, Address and Phone no. fields should be displayed on the parent page. In addition to that, the UserName should also be propagated to the iFrame's page's [lblPopupValue] label control. To achieve this, we would have to access the [frames] collection of the parent window object. To cut a long story short, here's the magical line of code :

window.&lt;strong&gt;&lt;em&gt;opener.frames(0).document.getElementById('lblPopupValue')&lt;/em&gt;&lt;/strong&gt;.innerText = 'blah blah';

Pardon the blah blah. Here's the complete code :
&lt;pre class="csharpcode"&gt;
        function passValues()
        {
            window.opener.document.getElementById('lblUName').innerText = document.getElementById('txtUName').value;
            window.opener.document.getElementById('lblAddress').innerText = document.getElementById('txtAddress').value;
            window.opener.document.getElementById('lblPhone').innerText = document.getElementById('txtPhone').value;   
            window.opener.frames(0).document.getElementById('lblPopupValue').innerText = document.getElementById('txtUName').value;
        }
&lt;/pre&gt;


`
And that's it. To summarize, we've successfully opened / closed a popup window, passed values to the parent window, and passed values to an iFrame embedded in the parent window.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-1183340700619262183?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/1183340700619262183/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=1183340700619262183' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1183340700619262183'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1183340700619262183'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/how-to-pass-values-from-popup-window-to.html' title='How to pass values from popup window to calling page'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp3.blogger.com/_3nOSNIc4Nj0/R0e-seZNWkI/AAAAAAAAACs/TsqVj8dPcGs/s72-c/untitled.bmp' height='72' width='72'/><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-732416960642747496</id><published>2007-11-19T20:14:00.000-08:00</published><updated>2007-11-19T20:24:38.849-08:00</updated><title type='text'>How to call a javascript method from the server side code</title><content type='html'>Calling a javascript method from a server side control requires adding an attribute to the control. Let us take an example --
Suppose we have a simple asp.net button on our web page, and want to display a javascript alert when this button is clicked. Our first instinct would be to put the script in the .aspx page itself, like this :
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Javascript Experiment&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="btnClickMe"&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;     &lt;span class="attr"&gt;OnClick&lt;/span&gt;&lt;span class="kwrd"&gt;="alert('Clicked');"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;


Try compiling it (in VS 2005), and you get the following error :

&lt;span style="font-size:85%;"&gt;error CS1012: Too many characters in character literal&lt;/span&gt;

Why ? Because the [OnClick] here refers to the serverside OnClick event(the one
you define in your code-behind). It does not refer to the javascript onclick event
of the button. So how do you "tell" the server-side button control to call the client
side onclick event ? By writing the following in your code-behind :

&lt;pre class="csharpcode"&gt;btnClickMe.Attributes.Add(&lt;span class="str"&gt;"onclick"&lt;/span&gt;, &lt;span class="str"&gt;"alert('Clicked');"&lt;/span&gt;);
&lt;/pre&gt;


Recall that each asp.net server control is rendered as an HTML element on the page. So before including the above line in our code, here's how our button is rendered :

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="btnClickMe"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btnClickMe"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;
&lt;/pre&gt;&lt;/span&gt;

As you can see, our button [btnClickMe] is rendered as an &amp;lt;input /&amp;gt; html element. It has four attributes :
type, name, value, and ID. When we add the Attributes.Add method to our code-behind, here's how the button looks :

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="btnClickMe"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="alert('Clicked');"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btnClickMe"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;
&lt;/span&gt;&lt;/pre&gt;

Note the [onclick] attribute rendered here. This basically causes
the "alert" to be shown when the button's onclick event is raised (in other words,
when the button is clicked). You can further extend this example to call a javascript
method that does something meaningful on the button click. Guess it can look something
like this :

&lt;pre class="csharpcode"&gt;
btnClickMe.Attributes.Add(&lt;span class="str"&gt;"onclick"&lt;/span&gt;, &lt;span class="str"&gt;"someMeaningfulMethod();"&lt;/span&gt;);&lt;/pre&gt;
So to summarize, we don't directly call the javascript method from the server side
code. Instead, we add attributes to the control so that when the control is rendered
(as html) on the browser, it also contains the attributes (event handlers, in this
case) we have added.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-732416960642747496?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/732416960642747496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=732416960642747496' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/732416960642747496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/732416960642747496'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/how-to-call-javascript-method-from.html' title='How to call a javascript method from the server side code'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-5367880373924798464</id><published>2007-11-17T21:34:00.000-08:00</published><updated>2007-11-25T06:31:15.306-08:00</updated><title type='text'>How to access a client-side control in asp.net code behind file</title><content type='html'>Accessing client-side variables/elements on the server side is not a straightforward affair. This is because the elements you create using javascript are not "server" controls, so you cannot directly access them in your code behind code like regular asp.net server controls (&lt;em&gt;by the way, server controls are controls that have the runat="server" attribute set&lt;/em&gt;.)

To achieve this functionality, we use hidden controls. Hidden controls are HTML controls that remain "hidden" on the page. In other words, you can assign a text value to the hidden controls (just like label, textbox etc.), but their contents are not rendered on the screen. By creating hidden controls with runat="server" set, we can access them both on client-side and server-side code.

Let us take an example. Suppose we have a simple .aspx page which has three elements :
1. An Asp.Net ListBox control,
2. A button for adding new options to the listbox, and
3. A button for posting back the page.

Here's what it looks like :


&lt;pre class="csharpcode"&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;function&lt;/span&gt; myMethod()
        {
            &lt;span class="kwrd"&gt;var&lt;/span&gt; listbox = document.getElementById(&lt;span class="str"&gt;'ListBox1'&lt;/span&gt;);
            &lt;span class="kwrd"&gt;var&lt;/span&gt; newElement = document.createElement(&lt;span class="str"&gt;'option'&lt;/span&gt;);
            newElement.text = &lt;span class="str"&gt;'Test'&lt;/span&gt;;
            listbox.options.add(newElement);
            window.&lt;span class="kwrd"&gt;event&lt;/span&gt;.returnValue = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        }       
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit1"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="myMethod();"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt;
                &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Add Element"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ListBox&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="ListBox1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:ListBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit2"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="PostBack Page"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;Run the above page. Observe that on clicking on the first button, our javascript method "myMethod()" successfully adds new elements to the listbox. However, as soon as you postback the page using the second button, the elements that you added are lost.

Why ? The reason for this is that although we have added the controls on the client-side, the viewstate variable on our page hasn't changed at all. It still says that the page has only one server control - the Listbox. So while processing the page upon postback, when asp.net constructs the "tree" of all controls on the page, it does not realize that there have been a few listbox elements added to the page on the client side (because the viewstate doesn't say so). Hence, when it renders back the page upon postback, it just renders an empty listbox.

To get around this, we would have to make an "entry" for the new elements in the viewstate, which is not possible because viewstate is encrypted. The second option is to use a hidden variable with runat="server", and put a comma seperated list of the new listbox elements added in this hidden variable. That way, when the page posts back, we read the value in the hidden variable and accordingly add new elements to the Listbox. Here's the modified .Aspx page for this :

&lt;pre class="csharpcode"&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;language&lt;/span&gt;&lt;span class="kwrd"&gt;="javascript"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;function&lt;/span&gt; myMethod()
        {
            &lt;span class="kwrd"&gt;var&lt;/span&gt; listbox = document.getElementById(&lt;span class="str"&gt;'ListBox1'&lt;/span&gt;);
            &lt;span class="kwrd"&gt;var&lt;/span&gt; newElement = document.createElement(&lt;span class="str"&gt;'option'&lt;/span&gt;);
            newElement.text = &lt;span class="str"&gt;'Test'&lt;/span&gt;;
            listbox.options.add(newElement);
            &lt;b&gt;document.getElementById(&lt;span class="str"&gt;'hdnListElements'&lt;/span&gt;).value = document.getElementById(&lt;span class="str"&gt;'hdnListElements'&lt;/span&gt;).value + &lt;span class="str"&gt;','&lt;/span&gt; + newElement.text;&lt;/b&gt;
            window.&lt;span class="kwrd"&gt;event&lt;/span&gt;.returnValue = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        }         
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit1"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;span class="kwrd"&gt;="myMethod();"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt;
                &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Add Element"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ListBox&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="ListBox1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:ListBox&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Submit2"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="submit"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="PostBack Page"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="hidden"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="hdnListElements"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;Observe carefully the highlighted line. We are basically creating a comma-seperated list of all the elements added to the listbox on the clientside. On the server-side, we read these values, and populate the listbox with the newly added child elements. Here's the C# code :

&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Configuration;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Security;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.WebControls.WebParts;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.UI.HtmlControls;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;partial&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; _Default : System.Web.UI.Page
{
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
            &lt;span class="kwrd"&gt;string&lt;/span&gt; str = hdnListElements.Value;
            &lt;span class="rem"&gt;// If the hidden variable is empty, no new elements added.&lt;/span&gt;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!String.IsNullOrEmpty(str))
            {
                &lt;span class="rem"&gt;// Split the comma-seperated list into an array of strings.&lt;/span&gt;
                &lt;span class="kwrd"&gt;string&lt;/span&gt;[] strArray = str.Split(&lt;span class="str"&gt;","&lt;/span&gt;.ToCharArray(),StringSplitOptions.RemoveEmptyEntries);
                &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; sTemp &lt;span class="kwrd"&gt;in&lt;/span&gt; strArray)
                {
                    &lt;span class="rem"&gt;// foreach newly added element, add a ListItem to the listbox control&lt;/span&gt;
                    ListBox1.Items.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; ListItem(sTemp, sTemp));
                }
                &lt;span class="rem"&gt;// Clear the hidden variable, so it does not contain the currently added elements.&lt;/span&gt;
                hdnListElements.Value = String.Empty;
            }
    }
}&lt;/pre&gt;And that is it. That's a pure and simple way to access client-side variables / controls in server-side code.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-5367880373924798464?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/5367880373924798464/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=5367880373924798464' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/5367880373924798464'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/5367880373924798464'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/how-to-access-client-side-control-in.html' title='How to access a client-side control in asp.net code behind file'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-2723730700396443009</id><published>2007-11-14T20:48:00.000-08:00</published><updated>2007-11-14T20:57:37.853-08:00</updated><title type='text'>Adding Rows dynamically to a gridview [Part 2]</title><content type='html'>In our &lt;a href="http://dotnetsavvyblog.blogspot.com/2007/11/all-of-us-have-at-some-point-or-other.html"&gt;last post&lt;/a&gt;, we saw how to add a row dynamically to a gridview. But we still have to see how to persist values added on the client side to the server side.
We shall not be using the recent AJAX based methodologies, instead we'll be using the good old fashioned way of persisting client side data to the server-side -- hidden variables.
Before we move further, we need to make two changes to the gridview we created in our last post:
1) Add a hidden variable with runat="server", and id="hdnRowCount". This will contain the number of rows in the gridview when the gridview was created, so that we can identify which rows have been dynamically added by the user.

2) Add a hidden variable with runat="server" and id ="hdnPostAddedRows". This variable is responsible for persisting the changes we made on the client side to the server side. More on how to do this later in the article. Here is how the updated page looks like :
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="Head1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:GridView&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="GridView1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;AutoGenerateColumns&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt; &lt;span class="attr"&gt;DataKeyNames&lt;/span&gt;&lt;span class="kwrd"&gt;="WorkOrderID"&lt;/span&gt;
                &lt;span class="attr"&gt;DataSourceID&lt;/span&gt;&lt;span class="kwrd"&gt;="SqlDataSource1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Columns&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="WorkOrderID"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="WorkOrderID"&lt;/span&gt; &lt;span class="attr"&gt;InsertVisible&lt;/span&gt;&lt;span class="kwrd"&gt;="False"&lt;/span&gt;
                        &lt;span class="attr"&gt;ReadOnly&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="WorkOrderID"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="ProductID"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="ProductID"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="ProductID"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="OrderQty"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="OrderQty"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="OrderQty"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="StockedQty"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="StockedQty"&lt;/span&gt; &lt;span class="attr"&gt;ReadOnly&lt;/span&gt;&lt;span class="kwrd"&gt;="True"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="StockedQty"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="ScrappedQty"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="ScrappedQty"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="ScrappedQty"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="StartDate"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="StartDate"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="StartDate"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="EndDate"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="EndDate"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="EndDate"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="DueDate"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="DueDate"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="DueDate"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="ScrapReasonID"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="ScrapReasonID"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="ScrapReasonID"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:BoundField&lt;/span&gt; &lt;span class="attr"&gt;DataField&lt;/span&gt;&lt;span class="kwrd"&gt;="ModifiedDate"&lt;/span&gt; &lt;span class="attr"&gt;HeaderText&lt;/span&gt;&lt;span class="kwrd"&gt;="ModifiedDate"&lt;/span&gt; &lt;span class="attr"&gt;SortExpression&lt;/span&gt;&lt;span class="kwrd"&gt;="ModifiedDate"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Columns&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:GridView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="SqlDataSource1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;ConnectionString&lt;/span&gt;&lt;span class="kwrd"&gt;="&amp;lt;%$ ConnectionStrings:AdventureWorksConnectionString %&amp;gt; "&lt;/span&gt;
                &lt;span class="attr"&gt;SelectCommand&lt;/span&gt;&lt;span class="kwrd"&gt;="select top 10 * from Production.WorkOrder"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="hidden"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="hdnRowCount"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="hidden"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="hdnPostAddedRows"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
Next, let us revise the problem we're trying to solve here : We are adding new rows to a gridview using client side script. These rows are not accessible on the server side, and there are no events being raised for these new rows on the server side. Our objective is to persist the rows that have been added, to the database. So, the question here is, "&lt;em&gt;How do we access controls added to the page on the client side using Javascript, in our server side (or C# / VB.Net) code ?"&lt;/em&gt;

To solve this, we are going to create a pipe-delimited string for all the values inserted on client side, and put that string in the hidden variables created above. For e.g., if the following three rows were added to our gridview

Saurabh 45 Testing Data Description
Swati 89 Some more description
TestName 2322 End of new rows

We shall convert this into the following string :
Saurabh45Testing Data Description~~Swati89Some more description~~TestName2322End of new rows

In the above case, the character "" is the column seperator, while the character combination "~~" is the row seperator.

Once we put this string in one of the hidden variables created above, and post back the page. Upon postback, on the server side, we can still access the hidden variable, since we declared it with runat="server". We shall read values from the hidden variable, and run an insert query for each row inserted into the gridview.
First, in your Page_Load method, populate the number of rows in the gridview in the hidden variable we created above (hdnRowCount)
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Page_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    hdnRowCount.Value = GridView1.Rows.Count;
}&lt;/pre&gt;Next, add a button "Save" to the page that triggers the save process :
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Button&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSave"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;OnClick&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSave_Click"&lt;/span&gt; &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Save"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;Also create a server side event handler btnSave_Click.

Next, create a javascript function that will construct the pipe-delimited string we discussed above. Here's a short pseudocode :
&lt;pre class="csharpcode"&gt;{
    1. Get the number of rows originally present in the gridview using the hidden variable hdnRowCount
    2. Create a variable strExpression, and set it to blank ""
    2. Loop through all the newly added rows
    {
        Note : Ignore the first cell, since this is blank.
        3. Read the second cell, append a "" character at the end
        4. Read the third cell, append a "" character at the end
        .
        .
        .
        .
        8. Read the eigth cell, append a "" character at the end
        9. Append a row seperator character, "~~" at the end of the row
        10. Append the string created above to strExpression variable.
    }
    10. strExpression is the string we want. Assign this to the hidden variable "hdnPostAddedRows" so we can access this on the server side.
}
&lt;/pre&gt;

Before we dive into the code, let us ponder over one question. How do we access the values the user has inserted in the table cells. For this, we need to access the individual textboxes in the table cells. We can do this using :

table.rows([rowcount]).cells([cell number]).childNodes(0).value

This would first access the cell using table.rows([rowcount]).cells([cell number]), and extract the value of the first child of the cell (childNodes(0).value).
Again, if one of the columns is a checkbox, you cannot do a .childNodes(0).value to get its value. The reason being, a checkbox does not have a "value" property. Instead, it has the "checked" property. So, to access a checkbox in a table, we need to use :

table.rows([rowcount]).cells([cell number]).childNodes(0).checked

Let us look at the code now :

&lt;pre class="csharpcode"&gt;
            function fn_BuildPostback()
            {
                var rowCount = 0;
                var strExpression = &lt;span class="str"&gt;''&lt;/span&gt;;
            var table = document.getElementById(&lt;span class="str"&gt;"GridView1"&lt;/span&gt;);

    &lt;span class="rem"&gt;//        1. Get the number of rows originally present in the gridview using the     //        hidden variable hdnRowCount&lt;/span&gt;
                var originalRowCount = parseInt(document.getElementById(&lt;span class="str"&gt;"hdnRowCount"&lt;/span&gt;).&lt;span class="kwrd"&gt;value&lt;/span&gt;);
           
            &lt;span class="kwrd"&gt;if&lt;/span&gt; ( originalRowCount == table.rows.length )
            {
                &lt;span class="rem"&gt;// No new rows have been added&lt;/span&gt;
                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="str"&gt;""&lt;/span&gt;;
            }
 
    &lt;span class="rem"&gt;//    2. Loop through all the newly added rows            &lt;/span&gt;
                &lt;span class="kwrd"&gt;for&lt;/span&gt; ( rowCount = originalRowCount - 1; rowCount &amp;lt; table.rows.length ; rowCount++ )
                {
                    var str = &lt;span class="str"&gt;''&lt;/span&gt;;
                    var &lt;span class="kwrd"&gt;operator&lt;/span&gt; = &lt;span class="str"&gt;''&lt;/span&gt;;
                 
                    var tr = table.rows(rowCount);
        &lt;span class="rem"&gt;// Ignore the first column, move to the second one.&lt;/span&gt;
                    str = str + tr.cells(1).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                
                    str = str + tr.cells(2).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                
                    str = str + tr.cells(3).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                
                    str = str + tr.cells(4).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                
                    str = str + tr.cells(5).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                
                    str = str + tr.cells(6).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                
                    str = str + tr.cells(7).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                
                    str = str + tr.cells(8).childNodes(0).&lt;span class="kwrd"&gt;value&lt;/span&gt; + &lt;span class="str"&gt;''&lt;/span&gt;;                

               strExpression = strExpression + str + &lt;span class="str"&gt;'~~'&lt;/span&gt;;
                }

                10. strExpression &lt;span class="kwrd"&gt;is&lt;/span&gt; the &lt;span class="kwrd"&gt;string&lt;/span&gt; we want. Assign &lt;span class="kwrd"&gt;this&lt;/span&gt; to the hidden variable &lt;span class="str"&gt;"hdnPostAddedRows"&lt;/span&gt; so we can access &lt;span class="kwrd"&gt;this&lt;/span&gt; on the server side.
                document.getElementById(&lt;span class="str"&gt;'hdnPostAddedRows'&lt;/span&gt;).&lt;span class="kwrd"&gt;value&lt;/span&gt; = strExpression;
            }

&lt;/pre&gt;

The above function just reads the dynamically added rows of the table one by one, and consolidates the contents of the rows into a single, pipe-delimited string. We assign this string to the hidden variable 'hdnPostAddedRows', which is also accessible on the server side in your c# code.
The next thing that needs to be done is to call this function when the user clicks the button "btnSave". That is easy, just add the following line at the end of your page_load method :

btnSave.Attributes.Add("onclick", "fn_BuildPostback();")

If you run the code now, here's the sequence of events :
1. You dynamically add rows to the gridview. Enter some test values, and hit "Save" button.

2. That would create the pipe-delimited string, assign it to the hidden variable, and finally post back the page.

3. Upon postback, the btnSave_Click event handler is called.

Inside the event handler, we can write code to split the string into individual rows, and fire insert statements (or stored procedures, as in this case) for each row. Here's a sample code that you might want to build upon :
&lt;pre class="csharpcode"&gt;
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnSave_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        &lt;span class="kwrd"&gt;string&lt;/span&gt; hdnExpr = hdnPostAddedRows.Value;
        &lt;span class="kwrd"&gt;int&lt;/span&gt; count = 0;
        &lt;span class="kwrd"&gt;int&lt;/span&gt; originalRowCount = Convert.ToInt32(hdnRowCount.Value.ToString().Trim());
     
        &lt;span class="kwrd"&gt;string&lt;/span&gt; [] exprArray = hdnExpr.Split(&lt;span class="str"&gt;"~~"&lt;/span&gt;.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
        &lt;span class="kwrd"&gt;string&lt;/span&gt; [] rowArgs;
        SqlConnection conn = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(&lt;span class="str"&gt;@"Data Source=wwwddsd331337\SQLExpress;Initial Catalog=TestDB;User Id=sd;Password=xyz;"&lt;/span&gt;);
        conn.Open();

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; expression &lt;span class="kwrd"&gt;in&lt;/span&gt; exprArray)
        {
            &lt;span class="rem"&gt;// If this is an extra row added on client side&lt;/span&gt;
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (count + 1 &amp;gt; originalRowCount)
            {
                SqlCommand command = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlCommand(&lt;span class="str"&gt;"re_InsertRow"&lt;/span&gt;, conn);
                command.CommandType = CommandType.StoredProcedure;
                SqlParameter param;
                rowArgs = expression.Split(&lt;span class="str"&gt;""&lt;/span&gt;.ToCharArray());

                param = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@workorderid"&lt;/span&gt;, rowArgs[0]);
                param.Direction = ParameterDirection.Input;
                param.DbType = (DbType)SqlDbType.Int;
                command.Parameters.Add(param);

                param = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@productid"&lt;/span&gt;, rowArgs[1]);
                param.Direction = ParameterDirection.Input;
                param.DbType = (DbType)SqlDbType.Int;
                command.Parameters.Add(param);

                param = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@orderqty"&lt;/span&gt;, rowArgs[2]);
                param.Direction = ParameterDirection.Input;
                param.DbType = (DbType)SqlDbType.VarChar;
                param.Size = 30;
                command.Parameters.Add(param);

                param = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlParameter(&lt;span class="str"&gt;"@stockedqty"&lt;/span&gt;, rowArgs[3]);
                param.Direction = ParameterDirection.Input;
                param.DbType = (DbType)SqlDbType.VarChar;
                param.Size = 7;
                command.Parameters.Add(param);
            .
            .
            .
            .
            .
            &lt;span class="rem"&gt;// Add parameters for all columns&lt;/span&gt;
                }

                command.ExecuteNonQuery();
            }
            count++;
        }
    &lt;span class="rem"&gt;// Call a method to bind the gridview again.&lt;/span&gt;
        LoadGridData();
    }
&lt;/pre&gt;

That's it !! You've created a gridview with client-side insert functionality. Give yourself a pat on the back, and be prepared for all the good comments ur gonna receive from your website users for making their life easier.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-2723730700396443009?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/2723730700396443009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=2723730700396443009' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/2723730700396443009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/2723730700396443009'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/adding-rows-dynamically-to-gridview.html' title='Adding Rows dynamically to a gridview [Part 2]'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-361208147778649617</id><published>2007-11-11T20:02:00.000-08:00</published><updated>2007-11-18T05:08:05.167-08:00</updated><title type='text'>Adding client side insert update delete functionality to a Gridview</title><content type='html'>&lt;p&gt;All of us have, at some point or the other, worked with providing Insert / Update / Delete functionality in a datagrid, and you can find quite a few good articles on this topic. Each approach uses some sort of server side code when modifying rows of a datagrid. There is nothing wrong with this as such, but it could become frustrating for the user because of the continous round trips to the server when modifying rows. We have decided to start a series of tutorials explaining the task of building up an client side insert / update / delete gridview.&lt;/p&gt;&lt;p&gt;We have split the operation of dynamically adding rows to a gridview into two phases :
1. Create a javascript function that dynamically adds a new row to the gridview.
2. Create a button on your page that calls this function when clicked. &lt;/p&gt;Simple, huh. To get started, create an aspx page as below, and populate the gridview with records from the AdventureWorks.Production.WorkOrder table (You can use any other database, but then you would have to modify the code below to work with the columns in your database). Please be sure of the following factors when you create the gridview :

a) The query for your SQLDataSource should be the following :
"select top 10 * from Production.WorkOrder"
This will limit the number of rows returned, and save you time unnecessarily waiting for the page to load, in addition to putting less burden on your database.
b) Disable paging for the gridview, so that we do not have a pager at the bottom of our gridview.
c) Make sure that you are not using master pages, or the gridview is not part of a user control. This is because when a control is placed inside a parent control, user control, or a master page, it's HTML id is prepended with some string identifying the parent. More on this in a later post.

If you do not know how to do this, please refer to this &lt;a href="http://msdn2.microsoft.com/en-us/library/aa479347.aspx"&gt;documentation on msdn &lt;/a&gt;to make sure the above simple conditions are met. Note that we have also added an html button named "btnAddRow" with runat = "server" set. Once done, here's what our page looks like. &lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
 font-size: small;
 color: black;
 font-family: Consolas, "Courier New", Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}

.csharpcode pre { margin: 0em; }

.csharpcode .rem { color: #008000; }

.csharpcode .kwrd { color: #0000ff; }

.csharpcode .str { color: #006080; }

.csharpcode .op { color: #0000c0; }

.csharpcode .preproc { color: #cc6633; }

.csharpcode .asp { background-color: #ffff00; }

.csharpcode .html { color: #800000; }

.csharpcode .attr { color: #ff0000; }

.csharpcode .alt
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0em;
}

.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;
&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btnAddRow"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Add"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:GridView&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="myGridView"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;DataSourceID&lt;/span&gt;&lt;span class="kwrd"&gt;="SqlDataSource1"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Columns&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:TemplateField&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;HeaderTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        Modify
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;HeaderTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:TemplateField&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Columns&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:GridView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:SqlDataSource&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="SqlDataSource1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;ConnectionString&lt;/span&gt;&lt;span class="kwrd"&gt;="&amp;lt;%$ ConnectionStrings:AdventureWorksConnectionString %&amp;gt;"&lt;/span&gt;
            &lt;span class="attr"&gt;SelectCommand&lt;/span&gt;&lt;span class="kwrd"&gt;="SELECT top 10 * FROM [Production].[WorkOrder]"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:SqlDataSource&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;

&lt;p&gt;
Test the page by running it once, the output should show 10 rows from the AdventureWorks.Production.WorkOrder
database table. &lt;/p&gt;&lt;p&gt;Note that I have added a template column as the first column, so that the first column always shows empty when the gridview is rendered on browser. This column has been intentionally left blank so we can show the insert / update / delete buttons. &lt;/p&gt;&lt;p&gt;&lt;/p&gt;&lt;p&gt;Next, take a moment to inspect the HTML code of your application. You can do this by right clicking on your page and choosing "View Source". Our gridview now looks like this (text clipped for brevity) :
&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;table&lt;/span&gt; &lt;span class="attr"&gt;cellspacing&lt;/span&gt;&lt;span class="kwrd"&gt;="0"&lt;/span&gt; &lt;span class="attr"&gt;rules&lt;/span&gt;&lt;span class="kwrd"&gt;="all"&lt;/span&gt; &lt;span class="attr"&gt;border&lt;/span&gt;&lt;span class="kwrd"&gt;="1"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="myGridView"&lt;/span&gt; &lt;span class="attr"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;="border-collapse:collapse;"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
                        Modify
                    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;WorkOrderID&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;ProductID&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;OrderQty&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;StockedQty&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;ScrappedQty&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;StartDate&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;EndDate&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;DueDate&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;ScrapReasonID&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt; &lt;span class="attr"&gt;scope&lt;/span&gt;&lt;span class="kwrd"&gt;="col"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;ModifiedDate&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;th&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="attr"&gt;&amp;amp;nbsp;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;1&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;722&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;8&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;8&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;0&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;7/4/2001 12:00:00 AM&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;7/14/2001 12:00:00 AM&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;7/15/2001 12:00:00 AM&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="attr"&gt;&amp;amp;nbsp;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;7/14/2001 12:00:00 AM&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;table&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;This reiterates the fact that &lt;strong&gt;our gridview is actually rendered as an html table in the user's browser&lt;/strong&gt;. It also means that if we want to dynamically add some rows to the gridview, we are actually adding rows to an HTML table. Our goal is that when the user clicks on the "Add" button that we created in our aspx page, a new row should be dynamically added to the gridview. For this, I have created a short pseudocode which we could base our code upon.
&lt;pre class="csharpcode"&gt;{
    // 1. Get the &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;table&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; element corresponding to the gridview from the page's DOM.

    // 2. Insert a new row in the table fetched in step 1.

    // 3. Insert an empty cell for the first "Modify" column

    // 4. Insert an empty cell for "WorkOrderID" in the row created in step 2. above.
        // In the cell created above, add a textbox in which the user will input the workorderID value he wishes to insert.
    // 5. Insert an empty cell for ProductID in the row created above.
        // In the cell created above, add a textbox in which the user will input the ProductID value he wishes to insert.
    // 6. Insert an empty cell for OrderQty in the row created above.
        // In the cell created above, add a textbox in which the user will input the OrderQty value he wishes to insert.
    .
    .
    .
    .
    // N. Insert cells similar to the above for the remaining columns (StockedQty,ScrappedQty,StartDate, EndDate, DueDate, ScrapReasonID, ModifiedDate)
}&lt;/pre&gt;&lt;p&gt;So, basically we're getting the table object from the DOM, and adding a new row and new cells dynamically using javascript. Before you look at the code, recall that you can add a child element to a parent element using the &lt;strong&gt;&lt;em&gt;&lt;u&gt;parentElement.appendChild(childElement)&lt;/u&gt;&lt;/em&gt;&lt;/strong&gt; method. But if you are adding a new table row (child), to a table (parent), you can directly use the &lt;strong&gt;&lt;u&gt;&lt;em&gt;tableName.insertRow()&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt; method. Similarly, to add a new table cell to a row, use the &lt;strong&gt;&lt;em&gt;&lt;u&gt;tableRow.insertCell() &lt;/u&gt;&lt;/em&gt;&lt;/strong&gt;method. Let us see the code now : &lt;pre class="csharpcode"&gt;
            function fn_AddFilterRow()
            {
        &lt;span class="rem"&gt;// 1. Get the &amp;lt;table&amp;gt; element corresponding to the gridview from the document&lt;/span&gt;
            var table = document.getElementById(&lt;span class="str"&gt;'myGridView'&lt;/span&gt;);

        &lt;span class="rem"&gt;// 2. Insert a new row in the table fetched in step 1.&lt;/span&gt;
                var newRow = table.insertRow();

        &lt;span class="rem"&gt;// 3. Insert an empty cell for the first "Modify" column&lt;/span&gt;
                &lt;span class="rem"&gt;// Column 1 : An empty cell for the "Modify" column&lt;/span&gt;
                var newCell = newRow.insertCell();
                newCell.appendChild(btnDelete);

        &lt;span class="rem"&gt;// 4. Insert an empty cell for "WorkOrderID" in the row created in step 2. above.                                    &lt;/span&gt;
                &lt;span class="rem"&gt;// Column 1 : WorkOrderID&lt;/span&gt;
                newCell = newRow.insertCell();
        &lt;span class="rem"&gt;// In the cell created above, add a textbox in which the user will input the  workorderID value he wishes to insert.&lt;/span&gt;
            var newTextBox = document.createElement(&lt;span class="str"&gt;'input'&lt;/span&gt;);
            newTextBox.type = &lt;span class="str"&gt;'text'&lt;/span&gt;;
            newCell.appendChild(newTextBox);
    
        &lt;span class="rem"&gt;// 5. Insert an empty cell for ProductID in the row created above.&lt;/span&gt;
                &lt;span class="rem"&gt;// Column 2 : ProductID &lt;/span&gt;
                newCell = newRow.insertCell();
        &lt;span class="rem"&gt;// In the cell created above, add a textbox in which the user will input the ProductID value he wishes to insert.&lt;/span&gt;
            var newTextBox = document.createElement(&lt;span class="str"&gt;'input'&lt;/span&gt;);
            newTextBox.type = &lt;span class="str"&gt;'text'&lt;/span&gt;;
            newCell.appendChild(newTextBox);

        &lt;span class="rem"&gt;// 6. Insert an empty cell for OrderQty in the row created above.                                &lt;/span&gt;
                &lt;span class="rem"&gt;// Column3 : OrderQty&lt;/span&gt;
                newCell = newRow.insertCell();
        &lt;span class="rem"&gt;// In the cell created above, add a textbox in which the user will input the OrderQty value he wishes to insert.&lt;/span&gt;
            var newTextBox = document.createElement(&lt;span class="str"&gt;'input'&lt;/span&gt;);
            newTextBox.type = &lt;span class="str"&gt;'text'&lt;/span&gt;;
            newCell.appendChild(newTextBox);
        .
        .
        .
        .
        .
        .
        .
        &lt;span class="rem"&gt;// Do the same for the remaining columns.&lt;/span&gt;

        }
&lt;/pre&gt;&lt;p&gt;The last step here is to write some code so that when the button "btnAddRow" gets clicked , our javascript function fn_AddFilterRow gets called. This is easy. Go to your code behind page. In the Page_Load method, add the following line&lt;/p&gt;&lt;pre class="csharpcode"&gt; btnAddRow.Attributes.Add("onclick", "fn_AddFilterRow();");&lt;/pre&gt;&lt;p&gt;That's it. Let it rip, and see for yourself. Launch the page in IE, and click on the button to add a new row to the gridview. &lt;/p&gt;&lt;p&gt;Note that each time you click on the button, you'd get a new row added to the gridview, which is pretty cool if users want to add multiple rows at a time. &lt;/p&gt;&lt;p&gt;
Okay, that's half the battle won. The other half is accessing the contents of the newly inserted row on the server side, and eventually inserting the row into the database. We shall discuss that in our next post.&lt;/p&gt;&lt;p&gt;Just so you know, the above is a very basic implementation of the client side editing capability. Notably, you might want to experiment a little bit to fix the following flaws

1. The new row always comes in as a standard with no formatting applied. But if the table has some formatting applied, your new row should also have the same color, font size, alignment etc. as the other gridview rows.
2. Currently we're adding textboxes for all columns in the new row. But there may be situations where you would want the user to choose from a dropdown list, or a checkbox (e.g. a column for sex can have values Male / Female / Yes, Please ;) ). Our gridview does not handle this.
3. If there was a footer/pager present, the code would have to be adjusted. The reason being the new row is always added after the last row of the &amp;lt;table&amp;gr;. The new row should ideally be added just above the footer, not below it.
4. Code does not handle the situation where the gridview is empty, i.e. no rows are being displayed. &lt;/p&gt;&lt;p&gt;
Nevertheless, this is a good starting point and you can definitely build up on the fundamentals you learnt here. In the next post, we'll complete the circle by persisting the row entries we added here to the database.
&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-361208147778649617?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/361208147778649617/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=361208147778649617' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/361208147778649617'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/361208147778649617'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/all-of-us-have-at-some-point-or-other.html' title='Adding client side insert update delete functionality to a Gridview'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-9207426601832268615</id><published>2007-11-07T21:20:00.000-08:00</published><updated>2007-11-09T20:10:44.671-08:00</updated><title type='text'>How to add HTML controls / elements dynamically to a page</title><content type='html'>How to add HTML controls / elements dynamically to a page
------------------------------------------------------------------------------------------------
Hmm .... now there's a familiar javascript problem. You know what javascript is ... know how it works ... know that you can manipulate controls, but how do you actually add new elements to the page using JS.
To revise our principles and beliefs -- The javascript hierarchy looks like this :
Document --&gt; HTML --&gt; Body --&gt; Page Elements.
The above expression omits one essential fact though - "Controls on a page can be children of other controls on the page". Confused ? Let's look at an example :

&lt;pre class="csharpcode"&gt;
&lt;span style="color:#6633ff;"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="myDiv"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btn"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/pre&gt;
In the above html, the &amp;lt;input&amp;gt; element with id = "btn", is a CHILD OF the &amp;lt;div&amp;gt; element.Getting the hang of it ??!
Let's fudge up things a little bit &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="myDiv"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btn"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="childDiv"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="childH"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; Child &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;Again, the hierarchy we have is :
&lt;a href="http://bp1.blogger.com/_3nOSNIc4Nj0/RzKh_doIsjI/AAAAAAAAACc/mtH-K6QkahM/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5130341037185217074" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://bp1.blogger.com/_3nOSNIc4Nj0/RzKh_doIsjI/AAAAAAAAACc/mtH-K6QkahM/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt;
Meaning, myDiv element has two children - btn, and childDiv. In turn, childDiv has one child of its own, called childH. Now do you get the hang of it ??!!. If not, look at my earlier post on &lt;a href="http://dotnetsavvyblog.blogspot.com/2007/11/how-to-debug-javascript-dom.html"&gt;debugging javascript&lt;/a&gt;, and try debugging this piece of HTML script. Pay close attention to the "children" properties of the elements.


Please note that the parent-child relationship determines how elements are displayed on the page. In the above case, the button "myBtn" will be shown "inside" the myDiv element's area on screen. Again, the childH element will be shown inside the childDiv area, which in turn falls inside the area for myDiv, which in turn falls in the area for &amp;lt;body&amp;gt; . When an element is child of the &amp;lt;body&amp;gt; element, it is not shown as a part of any other control, because &amp;lt;body&amp;gt; tag stands for the entire browser area. More on this in a later post.


All right, now about adding elements dynamically. There are roughly two situations where you would be adding an element to an html page :
1) Adding an element directly to the page's &amp;lt;body&amp;gt;.
2) Adding an element as a child of some other element.
Let us look at case # 1 first - Adding an element to the &amp;lt;body&amp;gt; tag.

Theoretically, this is the same as the case # 2, with the only difference that the element that you add is a child of the &amp;lt;body&amp;gt; element. First, we need to define an event. An event is (usually) some kind of action that the user will perform on the browser while viewing a web page. The action can be a button click, or moving the mouse or even typing something in a textbox. The reason we're associating an event here is to allow the user to trigger the process of adding a control dynamically. Meaning, the javascript that dynamically adds the controls to the page should be called only when the user performs that action. &lt;pre class="csharpcode"&gt;&lt;span style="color:#6633ff;"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="myDiv"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="btn"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Click Me"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="childDiv"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="childH"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; Child &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="button"&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="addCtrl"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="Add a new Elt"&lt;/span&gt; &lt;span class="attr"&gt;onclick&lt;/span&gt;&lt;/span&gt;&lt;span style="color:#6633ff;"&gt;&lt;span class="kwrd"&gt;="var elt = document.getElementById('childDiv');
var newElt = document.createElement('LABEL');
newElt.innerText = 'I was just added';
elt.appendChild(newElt);"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/pre&gt;Ok, so here we go. First, look at the line beginning with "onclick". This is like telling the browser, "Whenever the user does a click on this button (that is, clicks the button), run this piece of javascript". Simple, huh. And lets dissect the javascript --
&lt;span style="color:#6633ff;"&gt;var elt = document.getElementById('childDiv');
&lt;/span&gt;You should be familiar with this. If not, look at my post on &lt;a href="http://dotnetsavvyblog.blogspot.com/2007/11/how-to-debug-javascript-dom.html"&gt;javascript debugging&lt;/a&gt;. This is fetching the object for childDiv, and assigning to the variable 'elt'.


Next up,
&lt;span style="color:#6633ff;"&gt;var newElt = document.createElement('LABEL');
&lt;/span&gt;Here, we are creating a new element of type 'label'. Usually, when you need to display some plain text on the screen, we use this type of element. The new element is now stored in the 'newElt' variable.


Next,
newElt.innerText = 'I was just added';
This is basically setting a property for that control, so that when the object is shown on the browser, it writes "I was just added" on screen, and we know that it exists.


&lt;span style="color:#6633ff;"&gt;elt.appendChild(newElt);&lt;/span&gt;
Now this is the most critical part. We are adding the element we created above using the 'createElement' method, to the element that elt refers to. Meaning, we are adding the newly created element 'newElt' to the 'childDiv' element. Once done, the hierarchy would look like this :
&lt;a href="http://bp3.blogger.com/_3nOSNIc4Nj0/RzKjn9oIskI/AAAAAAAAACk/LOYKjws4Ad0/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5130342832481546818" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://bp3.blogger.com/_3nOSNIc4Nj0/RzKjn9oIskI/AAAAAAAAACk/LOYKjws4Ad0/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt; You can verify this by running the page. Initially you will not see any label text. As soon as you click the button, the text "I was just added" will appear. I would also advise that you look at what is happening by debugging the javascript. In case you are not familiar with debugging javascript, you can refer to my &lt;a href="http://dotnetsavvyblog.blogspot.com/2007/11/how-to-debug-javascript-dom.html"&gt;earlier post&lt;/a&gt;.
Hmm ... that was fun and easy. Next time, we will look at a related problem - dynamically building html tables. Keep learning.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-9207426601832268615?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/9207426601832268615/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=9207426601832268615' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/9207426601832268615'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/9207426601832268615'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/how-to-add-html-controls-elements.html' title='How to add HTML controls / elements dynamically to a page'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp1.blogger.com/_3nOSNIc4Nj0/RzKh_doIsjI/AAAAAAAAACc/mtH-K6QkahM/s72-c/untitled.bmp' height='72' width='72'/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-1200511263144813783</id><published>2007-11-07T16:33:00.000-08:00</published><updated>2007-11-07T16:46:56.548-08:00</updated><title type='text'>To add value in Hashtable from SQLReader</title><content type='html'>&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;If you want to add the values to HashTable which you are reading through SQLDataReader , then this is what you have to write,&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;Hashtable myHash =new Hashtable();&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;while(reader.Read())&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;{ &lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;      string type = reader.GetString(0).Trim(); &lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;      int num = reader.GetInt32(1).Trim(); &lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;      myhash.Add(num,type); &lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;}&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;Now if you want to add more than one values to Hashtable while reading it from a SQLDataReader, you will have to put the values in a class and make an object of it to insert in the value for Hashtable. It goes like this :&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;&lt;/span&gt;

&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;public class myClass
{
    private string sType;
    private int sNumber;
    private Datetime stimeType;
    public myClass(string Type,int Number,Datetime timeType)
    {
         sType = Type;
         sNumber = Number;
         stimeType = timeType;
     }
     public string getType()
     {
         return sType;
     }
     public int getNumber()
     {
         return sNumber;
     }
     public Datetime gettimeType()
     {
         return stimeType;
     }
}
&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;public void readVal()&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;{&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;       Hashtable myHash =new Hashtable();
       while(reader.Read())
       {
            string type = reader.GetString(0).Trim();
            int num = reader.GetInt32(1).Trim();
            Datetime time= reader.GetDateTime(2);
            myClass myObj = new myClass(type,num,time);
            myhash.Add(num,myObj); &lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;       }&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;}&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-1200511263144813783?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/1200511263144813783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=1200511263144813783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1200511263144813783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1200511263144813783'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/to-add-value-in-hashtable-from.html' title='To add value in Hashtable from SQLReader'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-6139989210070919081</id><published>2007-11-06T19:20:00.000-08:00</published><updated>2008-01-01T21:26:37.344-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Javacript Internals'/><category scheme='http://www.blogger.com/atom/ns#' term='Debug Javascript'/><title type='text'>How to debug the javascript DOM [Part 2]</title><content type='html'>&lt;p class="normalText"&gt;Well, let me summarize what we understood until now&lt;/p&gt;

&lt;p class="normalText"&gt;A] Whatever you see on the browser (including this page), is all pure HTML&lt;/p&gt;
&lt;p class="normalText"&gt;B] When the browser "draws" the HTML as buttons, textboxes, colors etc., it also creates a hierarchy of objects called the DOM model.&lt;/p&gt;
&lt;p class="normalText"&gt;C] The elements are in this order : HTML --&amp;gt; BODY --&amp;gt; Other Elements&lt;/p&gt;

&lt;p class="normalText"&gt;You might be saying "All right, I get it ... but is there a way I can physically see this hierarchy ??". The answer is Yes. But, you should have either Visual Studio or Microsoft Script Editor installed on you machine. Let us see how.&lt;/p&gt;
&lt;p class="normalText"&gt;
First, create a simple test page called HelloWorld.html. Here's the text&lt;/p&gt;
&lt;p class="normalText"&gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;div id="myDiv"&amp;gt;
&amp;lt;input type="button" id="btn" value="Click Me"&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/p&gt;
&lt;p class="normalText"&gt;
Type the above in a simple notepad and save it as HelloWorld.html. Next, open this page in internet explorer by double clicking on it. You'll see something like this :
&lt;a href="http://bp3.blogger.com/_3nOSNIc4Nj0/RzEyI2IpV-I/AAAAAAAAAAM/aGGQVU7ic3s/s1600-h/untitled.bmp"&gt;&lt;/a&gt;

For debugging purposes, we would have to add some javascript to this page. Let's tweak the HTML slightly :&lt;/p&gt;

&lt;p class="normalText"&gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;title&amp;gt;Untitled Page&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body onload="&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;var theDiv = document.getElementById('myDiv');"&lt;/span&gt;&lt;/strong&gt;&amp;gt;
&amp;lt;div id="myDiv"&amp;gt;
&amp;lt;input type="button" id="btn" value="Click Me"&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/p&gt;
&lt;p class="normalText"&gt;
As you can see, I have added some javascript to the page (now you know what it looks like). Let's dissect it a little bit before diving into how to debug it.
&lt;strong&gt;&lt;span style="color:#ff0000;"&gt;&amp;lt;body onload="XXXXXX" .....&lt;/span&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p class="normalText"&gt;
The above line is like effectively telling the browser that "When you start drawing this &amp;lt;body&amp;gt; element, that is, when you "load" this body element, before doing anything else, execute the statements given by XXXXXXX".
So, as soon as the browser starts drawing the &amp;lt;body&amp;gt; element on the page, it stops the drawing and first starts executing the javascript. Let's move to the Javascript now.
var theDiv = document.getElementById('myDiv');
var -- whenever you create a variable in javascript, the type has to be var only. No matter if it's an int, float, date, even an object, the Type is always VAR.
So we declare a variable called "theDiv".
Before you wonder what document.getElementById(...) means, let me remind you the hierarchy. HTML --&amp;gt; BODY --&amp;gt; Other Elements
&lt;/p&gt;
&lt;p class="normalText"&gt;
Keep in mind all the page elements (including HTML, and BODY), are part of the page's document. Thats one of the reasons the DOM stands for Document Object Model. So effectively, here's the object hierarchy diagram for any HTML page :
&lt;a href="http://bp0.blogger.com/_3nOSNIc4Nj0/RzHoJGIpWOI/AAAAAAAAACM/t8tQBxQJDsw/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5130136693515049186" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp0.blogger.com/_3nOSNIc4Nj0/RzHoJGIpWOI/AAAAAAAAACM/t8tQBxQJDsw/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt; So what document.getElementById('myDiv') is doing is searching for an element called "myDiv" in the document object's children. That is gonna return the &amp;lt;div&amp;gt; element that we created in our HTML, and this value is assigned to the variable theDiv.
&lt;/p&gt;
&lt;p class="normalText"&gt;
Whew, so far so good. Now let's get our hands dirty with some debugging stuff. Open the page in a browser, go to Tools -- &amp;gt; Internet Options --&amp;gt; Advanced --&amp;gt; Browsing section. Uncheck the "Disable Script Debugging (Internet Explorer)" and "Disable Script Debugging (Other)" checkboxes.
&lt;a href="http://bp2.blogger.com/_3nOSNIc4Nj0/RzHiVmIpWII/AAAAAAAAABc/HzypixFUS6o/s1600-h/untitled.bmp"&gt;&lt;/a&gt;
Next, go to your page, from menu choose view --&amp;gt; Script Debugger --&amp;gt; Break at next statement
Once done, refresh the page. Immediately you should see the a window similar to the one below :
&lt;a href="http://bp0.blogger.com/_3nOSNIc4Nj0/RzE8YGIpWHI/AAAAAAAAABU/FGp233xPU8o/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5129947835213109362" style="FLOAT: left; MARGIN: 0px 10px 10px 0px; CURSOR: hand" alt="" src="http://bp0.blogger.com/_3nOSNIc4Nj0/RzE8YGIpWHI/AAAAAAAAABU/FGp233xPU8o/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p class="normalText"&gt;Choose "Yes", a new session of Visual Studio / Script debugger will open. Once open, you'll see a window like this :&lt;/p&gt;
&lt;p&gt;&lt;a href="http://bp1.blogger.com/_3nOSNIc4Nj0/RzHkqWIpWLI/AAAAAAAAAB0/SBzpUhCOK24/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5130132866699188402" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_3nOSNIc4Nj0/RzHkqWIpWLI/AAAAAAAAAB0/SBzpUhCOK24/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;p class="normalText"&gt;The yellow arrow on the left tells you on which line the debugger is currently at.
--Select the text "document.getElementById('myDiv') as shown above.
--Right click on the text and choose "Add Watch". The add watch command is used to add the chosen expression to a Watch window, where you can actually see what it's value is. As the program runs, you can see the value change on the fly. On choosing "Add Watch", you'll see a window like this (it usually pops up at the bottom of the Visual Script Debugger window) :&lt;/p&gt;&lt;div&gt;
&lt;/div&gt;&lt;a href="http://bp1.blogger.com/_3nOSNIc4Nj0/RzHlEWIpWMI/AAAAAAAAAB8/gvSPdT8S818/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5130133313375787202" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp1.blogger.com/_3nOSNIc4Nj0/RzHlEWIpWMI/AAAAAAAAAB8/gvSPdT8S818/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt;Expand the selection by clicking on the [+] symbol, and voila, you're looking at the internals of the "myDiv" object. Remember, this is actually the Object Representation of the page's myDiv element. If you change this object, the page myDiv will also change, and vice versa.

&lt;p class="normalText"&gt;Let's make sense of some of the more important properties --&gt;&lt;/p&gt;
&lt;p class="normalText"&gt;-- id : The id of the element (in our case, "myDiv")&lt;/p&gt;
&lt;p class="normalText"&gt;-- tagName : The TYPE of the element, whether it's a &amp;lt;div&amp;gt; or an &amp;lt;input&amp;gt; element, or is it &amp;lt;document&amp;gt;, or &amp;lt;body&amp;gt; ... get the point ?!!&lt;/p&gt;
&lt;p class="normalText"&gt;-- parentElement : The parent of the current element. In our case, myDiv is a child of the &amp;lt;body&amp;gt; element object (remember the hierarchy ?). So the parentElement should be the document.
To confirm, expand the parentElement by clicking the [+] sign, and check out the tagName property of the parent Element. Sure enough, it says "BODY".&lt;/p&gt;

&lt;p class="normalText"&gt;Before going further, scroll down to the "document" element and expand it. Here's what you see :
&lt;a href="http://bp3.blogger.com/_3nOSNIc4Nj0/RzHlw2IpWNI/AAAAAAAAACE/tQ6lclv5K2w/s1600-h/untitled.bmp"&gt;&lt;img id="BLOGGER_PHOTO_ID_5130134077879965906" style="DISPLAY: block; MARGIN: 0px auto 10px; CURSOR: hand; TEXT-ALIGN: center" alt="" src="http://bp3.blogger.com/_3nOSNIc4Nj0/RzHlw2IpWNI/AAAAAAAAACE/tQ6lclv5K2w/s400/untitled.bmp" border="0" /&gt;&lt;/a&gt;This is the page's document object, which houses all other page element object (including &amp;lt;html&amp;gt;, &amp;lt;body&amp;gt; etc. If you look carefully, you'll see it also contains Scripts, images, links, frames etc. page elements. More on this later.
&lt;/p&gt;
&lt;p class="normalText"&gt;
Next up,
OffsetLeft, offsetTop, offsetWidth, offsetHeight : Determine the position of the element on the page.&lt;/p&gt;
&lt;p class="normalText"&gt;
InnerHTML : The html inside this element&lt;/p&gt;
&lt;p class="normalText"&gt;InnerText : If you wanna write some text in an element, you use this.&lt;/p&gt;
&lt;br /&gt;
.
&lt;br /&gt;
.
&lt;br /&gt;
.
&lt;br /&gt;
.
&lt;p class="normalText"&gt;There's a hundred other properties that I'd like to go through, but let's stop here for lack of space and time. For more info, you can always checkout the description for &amp;lt;div&amp;gt; element on the MSDN site http://msdn2.microsoft.com/en-us/library/ms535240.aspx.&lt;/p&gt;

&lt;p class="normalText"&gt;To cut a long story short, if you want to look at the internals of the various objects on an HTML page, you can do so by starting to debug the page and looking at various page objects. In my next post, I'll look at the internals of some of the most common operations that you need to perform in javascript while creating websites.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-6139989210070919081?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/6139989210070919081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=6139989210070919081' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/6139989210070919081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/6139989210070919081'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/how-to-debug-javascript-dom.html' title='How to debug the javascript DOM [Part 2]'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://bp0.blogger.com/_3nOSNIc4Nj0/RzHoJGIpWOI/AAAAAAAAACM/t8tQBxQJDsw/s72-c/untitled.bmp' height='72' width='72'/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-8299274975406393496</id><published>2007-11-06T09:51:00.000-08:00</published><updated>2008-01-16T08:18:10.974-08:00</updated><title type='text'>To retrieve fields using SQLReader</title><content type='html'>&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;Whenever the fields needs to be retrieved from SQL Database,&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;The smartest way is to do it when there is lot of data to retrieve is through the SQLDataReader.&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;The code can look like this :--&lt;/span&gt;
&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;private&lt;/span&gt; SqlConnection sConn; 
&lt;span class="kwrd"&gt;private&lt;/span&gt; SqlCommand slSelectSumDClosedCommand; 
slSelectSumDClosedCommand = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlCommand(); 
slSelectSumDClosedCommand.CommandText = &lt;span class="str"&gt;"Select * from table1"&lt;/span&gt;; 
slSelectSumDClosedCommand.Connection = sConn; 
&lt;span class="kwrd"&gt;private&lt;/span&gt; SqlDataReader reader=&lt;span class="kwrd"&gt;null&lt;/span&gt;; 
&lt;span class="kwrd"&gt;private&lt;/span&gt; Hashtable sDClosedValue = &lt;span class="kwrd"&gt;new&lt;/span&gt; Hashtable(); 

reader = slSelectSumDClosedCommand.ExecuteReader(); 
&lt;span class="kwrd"&gt;while&lt;/span&gt;(reader.Read()) 
{ 
&lt;span class="kwrd"&gt;string&lt;/span&gt; acct = reader.GetString(0).Trim(); 
&lt;span class="kwrd"&gt;double&lt;/span&gt; dailyVal = reader.GetDouble(1); 
sDClosedValue.Add(acct, dailyVal); 
} 
reader.Close(); 
&lt;/pre&gt;

&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;The above code is reading values from the table through data reader and putting it in an hashtable. You can carry out whatever function is required.&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;Try using stored procedure everytime. Above code is just an example that is why I have used SQLCommand.CommandText.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-8299274975406393496?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/8299274975406393496/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=8299274975406393496' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/8299274975406393496'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/8299274975406393496'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/to-retrieve-fields-using-sqlreader.html' title='To retrieve fields using SQLReader'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-5320685679588211261</id><published>2007-11-04T17:31:00.000-08:00</published><updated>2008-01-16T08:25:07.871-08:00</updated><title type='text'>How to connect with SQL database?</title><content type='html'>&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;For connecting to SQL Database, you can directly write a connection string in the C# code like&lt;/span&gt;


&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;br/&gt;SQLConnection sConn = new SQLConnection();&lt;/span&gt;


&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;br/&gt;sConn="Data Source=xyz;Initial Catalog=myDtbase;User ID=sl;Password=sa"&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;br/&gt;But the proper way to do it is by adding the connection string in a web.config, for example &lt;/span&gt;&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;in &lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;"&gt;&lt;configuration&gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br/&gt;&amp;lt;configuration&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br/&gt;&amp;lt;appSettings&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br/&gt;&amp;lt;add key="conn1String" value="Data Source=xyz;Initial Catalog=myDtbase;User ID=sl;Password=sa"/&amp;gt; &amp;lt;/appSettings&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;"&gt;&lt;span style="font-size:85%;"&gt;&lt;br/&gt;&amp;lt;/configuration&amp;gt;
&amp;lt;appsettings&amp;gt;&lt;/span&gt;&lt;span style="font-family:trebuchet ms;"&gt;&amp;lt;appsettings&amp;gt;
&lt;br/&gt;&amp;lt;add key="conn1String" value="Data Source=xyz;Initial Catalog=myDtbase;User ID=sl;Password=sa"&amp;gt;&lt;br/&gt;&amp;lt;/appsettings&amp;gt;&lt;br/&gt;&amp;lt;add key="conn1String" value="Data Source=xyz;Initial Catalog=myDtbase;User ID=sl;Password=sa"&amp;gt;&lt;br/&gt;&amp;lt;/configuration&amp;gt;&amp;lt;/appsettings&amp;gt;&amp;lt;/configuration&amp;gt;&lt;/span&gt;&lt;span style="font-family:Trebuchet MS;"&gt;&lt;span style="font-size:85%;"&gt;
&lt;br/&gt;In C# code , just define&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;
&lt;br/&gt;string connString = ConfigurationSettings.AppSettings["conn1String"];&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;
&lt;br/&gt;sConn =connString;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;
&lt;br/&gt;Data Source : has to be the complete machine name\SQLExpress&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;
&lt;br/&gt;Initial Catalog : has to be the database name&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;
&lt;br/&gt;User ID and Password : If you use other than windows authentication&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;
If it is windows authentication, just give Integrated Security=SSPI;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;

&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-5320685679588211261?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/5320685679588211261/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=5320685679588211261' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/5320685679588211261'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/5320685679588211261'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/how-to-connect-with-sql-database.html' title='How to connect with SQL database?'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-1626566910563124556</id><published>2007-11-04T07:22:00.000-08:00</published><updated>2007-11-07T16:29:27.964-08:00</updated><title type='text'>Why to use bracket '[' around table name and column name?</title><content type='html'>&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;The error : Incorrect syntax near the keyword tablename(before the space) will appear if tried to use a tablename with space in between.&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:trebuchet ms;font-size:85%;"&gt;We can use square bracket '[' around table name or column name, for generally specifying a table name with spaces. For e.g. &lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;Select * from my table ---&gt; this statement will not work as tablename 'my table' has a space.&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;Either you can write , Select * from 'my table' OR Select * from [my table]&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;When sometimes we have defined Schema names for database and they contain some '.' , then we can write &lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;Select * from [s.ssd].[my table]&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;For using a particular database, dont forget to type &lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;use databaseName&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;Go&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;&lt;/span&gt;
&lt;span style="font-family:Trebuchet MS;font-size:85%;"&gt;then your statement&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-1626566910563124556?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/1626566910563124556/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=1626566910563124556' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1626566910563124556'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1626566910563124556'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/why-to-use-bracket-around-table-name.html' title='Why to use bracket &apos;[&apos; around table name and column name?'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3726050755669934165.post-1101401670020122313</id><published>2007-11-04T06:22:00.000-08:00</published><updated>2007-12-01T10:52:42.077-08:00</updated><title type='text'>Beginning SQL Statements</title><content type='html'>&lt;span style="font-size:85%;"&gt;Whenever anybody wants to start learning SQL Server , there are few basic commands which needs to be known,&lt;/span&gt;
&lt;ul&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;SQL Select Statement -- Select statement is used for selecting any number of rows from a table. You can specify the 'where' clause and retrieve number of rows selectively.                                                                         Select * from table1 where column1 = 'name' and column2 = 'ID'                                                                                  &lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;SQL Insert Statement -- Insert Statement is used for inserting rows in a table . Here also 'where' clause can be specified as required.                                                                                                                                                  Insert into table1(column1,column2,column3) Values('value1','value2','value3')&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;SQL Delete Statement -- Delete Statement is for deleting any number of rows based on certain clause.  Delete from table1 where column1='value1' and column2='value2'&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:85%;"&gt;SQL Update Statement -- Update Statement , updates a particular row as required.                                   Update from table1 set column1 = 'value1' &lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;span style="font-size:85%;"&gt;These are the 4 important statements to know for any beginner . We will keep on posting blogs regarding different ways of writting these statements.&lt;/span&gt; &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3726050755669934165-1101401670020122313?l=dotnetsavvyblog.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetsavvyblog.blogspot.com/feeds/1101401670020122313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3726050755669934165&amp;postID=1101401670020122313' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1101401670020122313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3726050755669934165/posts/default/1101401670020122313'/><link rel='alternate' type='text/html' href='http://dotnetsavvyblog.blogspot.com/2007/11/beginners-sql-statements.html' title='Beginning SQL Statements'/><author><name>Swati.Saurabh</name><uri>http://www.blogger.com/profile/02822525812799442587</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
