<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Venkat's World</title>
	<atom:link href="http://venkatsworld.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://venkatsworld.wordpress.com</link>
	<description>Quest for Technology..!</description>
	<lastBuildDate>Fri, 28 Nov 2008 12:30:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='venkatsworld.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Venkat's World</title>
		<link>http://venkatsworld.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://venkatsworld.wordpress.com/osd.xml" title="Venkat&#039;s World" />
	<atom:link rel='hub' href='http://venkatsworld.wordpress.com/?pushpress=hub'/>
		<item>
		<title>How To Stop Ajax Post Back when A button contains OnClick() and onclientclick events</title>
		<link>http://venkatsworld.wordpress.com/2008/11/28/how-to-stop-ajax-post-back-when-a-button-contains-onclick-and-onclientclick-events/</link>
		<comments>http://venkatsworld.wordpress.com/2008/11/28/how-to-stop-ajax-post-back-when-a-button-contains-onclick-and-onclientclick-events/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 12:30:26 +0000</pubDate>
		<dc:creator>venkatworld</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://venkatsworld.wordpress.com/?p=23</guid>
		<description><![CDATA[When A button Contains Two event functions ,one on client side and the other on Server side, The Page posts back  event occurs even when the page not pass  the validation.   To Avoid this unwanted postback ,we should  explicitly call the method   Page_ClientValidate() in the javascript event method or function.   Here is the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=23&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>When A button Contains Two event functions ,one on client side and the other on Server side, The Page posts back  event occurs even when the page not pass  the validation.</div>
<div> </div>
<div>To Avoid this unwanted postback ,we should  explicitly call</div>
<div>the method</div>
<div> </div>
<div><span style="font-size:x-small;color:#0000ff;">Page_ClientValidate() in the javascript event method or function.</span></div>
<div> </div>
<div><span style="font-size:x-small;color:#000000;">Here is the Example:</span></div>
<div><span style="font-size:x-small;color:#0000ff;"><font size="2" color="#0000ff">&lt;</p>
<p></font></span><span style="font-size:x-small;color:#800000;">asp</span><span style="font-size:x-small;color:#0000ff;">:</span><span style="font-size:x-small;color:#800000;">ImageButton</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff0000;">ID</span><span style="font-size:x-small;color:#0000ff;">=&#8221;imgBtnSubmit&#8221;</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff0000;">CssClass</span><span style="font-size:x-small;color:#0000ff;">=&#8221;image&#8221;</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff0000;">ValidationGroup</span><span style="font-size:x-small;color:#0000ff;">=&#8221;Submit&#8221;</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff0000;">onclientclick</span><span style="font-size:x-small;color:#0000ff;">=&#8221;javascript:if(Page_ClientValidate())return HaspopUpClosed(); &#8220;</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff0000;">OnClick</span><span style="font-size:x-small;color:#0000ff;">=&#8221;imgBtnSubmit_Clicked&#8221;</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#ff0000;">runat</span><span style="font-size:x-small;color:#0000ff;">=&#8221;server&#8221;</span><span style="font-size:x-small;"> <span style="font-size:x-small;color:#ff0000;">ImageUrl</span><span style="font-size:x-small;color:#0000ff;">=&#8221;~/res/images/img/Updatebtn.jpg&#8221;</span><span style="font-size:x-small;"> </span><span style="font-size:x-small;color:#0000ff;">/&gt;</span></span></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/venkatsworld.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/venkatsworld.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/venkatsworld.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/venkatsworld.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/venkatsworld.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/venkatsworld.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/venkatsworld.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/venkatsworld.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/venkatsworld.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/venkatsworld.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/venkatsworld.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/venkatsworld.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/venkatsworld.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/venkatsworld.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=23&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://venkatsworld.wordpress.com/2008/11/28/how-to-stop-ajax-post-back-when-a-button-contains-onclick-and-onclientclick-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a1af4102295ad6c590f8aad7c9f97ec?s=96&#38;d=identicon" medium="image">
			<media:title type="html">venkatworld</media:title>
		</media:content>
	</item>
		<item>
		<title>Javascript function overloading</title>
		<link>http://venkatsworld.wordpress.com/2008/11/28/javascript-function-overloading/</link>
		<comments>http://venkatsworld.wordpress.com/2008/11/28/javascript-function-overloading/#comments</comments>
		<pubDate>Fri, 28 Nov 2008 09:57:27 +0000</pubDate>
		<dc:creator>venkatworld</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Add new tag]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://venkatsworld.wordpress.com/?p=19</guid>
		<description><![CDATA[JavaScript function overloading..!   &#60;html xmlns=&#8221;http://www.w3.org/1999/xhtml&#8221; &#62; &#60;head &#62;     &#60;title&#62;Javascript Function calls.&#60;/title&#62; &#60;script language=&#8221;javascript&#8221; type=&#8221;text/javascript&#8221; &#62;           function Add()     {       alert(&#8216;Add With No Parameters &#8216;);     }         function Add(val1,val2)     {       alert(&#8216;Add With Two Parameters &#8216;+(val1+val2));     }     function Add(val1)     {       alert(&#8216;Add With one Parameter [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=19&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="MsoNormal" style="line-height:normal;margin:0;"><strong><span style="font-size:14pt;font-family:&quot;">JavaScript function overloading..!</span></strong></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:maroon;font-family:&quot;">html</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:red;">xmlns</span><span style="color:blue;">=&#8221;http://www.w3.org/1999/xhtml&#8221;</span> <span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:maroon;font-family:&quot;">head</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;</span>Javascript Function calls.<span style="color:blue;">&lt;/</span><span style="color:maroon;">title</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:maroon;font-family:&quot;">script</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:red;">language</span><span style="color:blue;">=&#8221;javascript&#8221;</span> <span style="color:red;">type</span><span style="color:blue;">=&#8221;text/javascript&#8221;</span> <span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">function</span> Add()</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>alert(<span style="color:maroon;">&#8216;Add With No Parameters &#8216;</span>);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">function</span> Add(val1,val2)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>alert(<span style="color:maroon;">&#8216;Add With Two Parameters &#8216;</span>+(val1+val2));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">function</span> Add(val1)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>alert(<span style="color:maroon;">&#8216;Add With one Parameter &#8216;</span>+val1);</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">function</span> Add(val1,val2,val3)</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>{</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>      </span>alert(<span style="color:maroon;">&#8216;Add With Three Parameters &#8216;</span>+(val1+val2+val3));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span>}</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:maroon;font-family:&quot;">script</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:maroon;font-family:&quot;">head</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;</span><span style="font-size:10pt;color:maroon;font-family:&quot;">body</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>   </span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">form</span> <span style="color:red;">id</span><span style="color:blue;">=&#8221;form1&#8243;&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">div</span> <span style="color:red;">style</span><span style="color:blue;">=&#8221;width:500px; height:400px; background-color:Gray;&#8221;</span> <span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">input</span> <span style="color:red;">type</span><span style="color:blue;">=&#8221;button&#8221;</span> <span style="color:red;">onclick</span><span style="color:blue;">=&#8221;Add(5,6,7);&#8221;</span> <span style="color:red;">value</span><span style="color:blue;">=&#8221;Add with Three Parameters&#8221;</span> <span style="color:blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">input</span> <span style="color:red;">type</span><span style="color:blue;">=&#8221;button&#8221;</span> <span style="color:red;">onclick</span><span style="color:blue;">=&#8221;Add(5,6);&#8221;</span> <span style="color:red;">value</span><span style="color:blue;">=&#8221;Add with Two Parameters&#8221;</span> <span style="color:blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">input</span> <span style="color:red;">type</span><span style="color:blue;">=&#8221;button&#8221;</span> <span style="color:red;">onclick</span><span style="color:blue;">=&#8221;Add(5);&#8221;</span> <span style="color:red;">value</span><span style="color:blue;">=&#8221;Add with One Parameters&#8221;</span> <span style="color:blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;</span><span style="color:maroon;">input</span> <span style="color:red;">type</span><span style="color:blue;">=&#8221;button&#8221;</span> <span style="color:red;">onclick</span><span style="color:blue;">=&#8221;Add();&#8221;</span> <span style="color:red;">value</span><span style="color:blue;">=&#8221;Add with No Parameters&#8221;</span> <span style="color:blue;">/&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"><span>    </span><span style="color:blue;">&lt;/</span><span style="color:maroon;">form</span><span style="color:blue;">&gt;</span></span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:maroon;font-family:&quot;">body</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;">&lt;/</span><span style="font-size:10pt;color:maroon;font-family:&quot;">html</span><span style="font-size:10pt;color:blue;font-family:&quot;">&gt;</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;color:blue;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">What is the out put of the above code, when we click on the button with value ‘<span style="color:blue;">Add with No Parameters’ </span>or any other button.?</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">If we expect the alert message </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> <span style="color:blue;"><span> </span></span>alert(<span style="color:maroon;">&#8216;Add With No Parameters &#8216;</span>); </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">And if we say whenever we click on a button, its corresponding Add function will be called,we are <span> </span>absolutely wrong.If you have any doubt run this code.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Whatevr the button we click,</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> alert(<span style="color:maroon;">&#8216;Add With Three Parameters &#8216;</span>+(val1+val2+val3));</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"> </p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> will be called irrespective of the javascrpt function signature.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Javascrit won’t suport function overloading.When we define a function with the same name but with different parameters,the function call directly goes to the function which is defined at the last. i.e. the last function in the order.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">If we change the order of the functions,the function which is last in the definitions will be called.</span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;"> </span></p>
<p class="MsoNormal" style="line-height:normal;margin:0;"><span style="font-size:10pt;font-family:&quot;">Here whats happening is, the  function which is defined at the last will overwrite the previously defined functions.</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/venkatsworld.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/venkatsworld.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/venkatsworld.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/venkatsworld.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/venkatsworld.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/venkatsworld.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/venkatsworld.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/venkatsworld.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/venkatsworld.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/venkatsworld.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/venkatsworld.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/venkatsworld.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/venkatsworld.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/venkatsworld.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=19&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://venkatsworld.wordpress.com/2008/11/28/javascript-function-overloading/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a1af4102295ad6c590f8aad7c9f97ec?s=96&#38;d=identicon" medium="image">
			<media:title type="html">venkatworld</media:title>
		</media:content>
	</item>
		<item>
		<title>WPF data templates</title>
		<link>http://venkatsworld.wordpress.com/2008/09/08/wpf-data-templates/</link>
		<comments>http://venkatsworld.wordpress.com/2008/09/08/wpf-data-templates/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 13:57:26 +0000</pubDate>
		<dc:creator>venkatworld</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://venkatsworld.wordpress.com/?p=8</guid>
		<description><![CDATA[WPF Data Templates.   While displaying data in data grid or ListBox, we may need to display various types of data. For example we may need to display dates in ‘MM/DD/YYYY’ format, float or double values in currency format ($560.00) or in some other format and all numeric data should be right aligned. In our [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=8&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1 style="text-align:center;"><span style="font-size:10pt;line-height:115%;font-family:&quot;">WPF Data Templates.</span></h1>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">While displaying data in data grid or ListBox, we may need to display various types of data. For example we may need to display dates in ‘MM/DD/YYYY’ format, float or double values in currency format ($560.00) or in some other format and all numeric data should be right aligned.</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">In our application we used Xceed data grid control. We can bind data by converting all fields in to string format. Initially what I did is, created a data table dynamically from data .All columns of the data table are of data type string. I used this data table as the Item source to the data grid control. It worked properly but the mistake I did was, I converted all numeric and date fields into string so that sorting on the date and numeric fields is not working. As I defined all the columns of the data table as string data type, the Data grid using string comparison instead of date comparison .</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">So my headache started …at last I came up with a beautiful and simple solution for the problem .Using Data Template we can solve this problem. While creating data table, I defined various columns with various data types corresponding to the binding data, so that the data table contains various data types of columns. Then sorting working properly but data is not formatted. With data template I solved this problem. Here is the sample code.</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">[<span style="color:#2b91af;">ValueConversion</span>(<span style="color:#0000ff;">typeof</span>(<span style="color:#0000ff;">double</span>), <span style="color:#0000ff;">typeof</span>(<span style="color:#0000ff;">string</span>))]</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">CurrencyConverter</span> : <span style="color:#2b91af;">IValueConverter</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">object</span> Convert(<span style="color:#0000ff;">object</span> value, <span style="color:#2b91af;">Type</span> targetType,</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> parameter, <span style="color:#2b91af;">CultureInfo</span> culture)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;"> ((value != <span style="color:#0000ff;">null</span>) &amp;&amp; (!<span style="color:#0000ff;">object</span>.Equals(<span style="color:#0000ff;">string</span>.Empty, value)))</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">try</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">// Convert the string value provided by an editor to a double before formatting.</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">double</span><span style="font-size:10pt;font-family:&quot;"> tempDouble = System.<span style="color:#2b91af;">Convert</span>.ToDouble(value, <span style="color:#2b91af;">CultureInfo</span>.CurrentCulture);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">string</span>.Format(<span style="color:#2b91af;">CultureInfo</span>.CurrentCulture, <span style="color:#a31515;">&#8220;{0:C}&#8221;</span>, tempDouble);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">catch</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:#2b91af;">FormatException</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">catch</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:#2b91af;">OverflowException</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">string</span>.Format(<span style="color:#2b91af;">CultureInfo</span>.CurrentCulture, <span style="color:#a31515;">&#8220;{0}&#8221;</span>, value);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">object</span> ConvertBack(<span style="color:#0000ff;">object</span> value, <span style="color:#2b91af;">Type</span> targetType,</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> parameter, <span style="color:#2b91af;">CultureInfo</span> culture)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">double</span>.Parse(value <span style="color:#0000ff;">as</span> <span style="color:#0000ff;">string</span>, <span style="color:#2b91af;">NumberStyles</span>.Currency,</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#2b91af;">CultureInfo</span>.CurrentCulture);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"> </p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">[<span style="color:#2b91af;">ValueConversion</span>(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">DateTime</span>), <span style="color:#0000ff;">typeof</span>(<span style="color:#0000ff;">string</span>))]</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">class</span> <span style="color:#2b91af;">DateConverter</span> : <span style="color:#2b91af;">IValueConverter</span></span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">object</span> Convert(<span style="color:#0000ff;">object</span> value, <span style="color:#2b91af;">Type</span> targetType,</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> parameter, <span style="color:#2b91af;">CultureInfo</span> culture)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;"> ((value != <span style="color:#0000ff;">null</span>) &amp;&amp; (!<span style="color:#0000ff;">object</span>.Equals(<span style="color:#0000ff;">string</span>.Empty, value)))</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">try</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">DateTime</span><span style="font-size:10pt;font-family:&quot;"> dateTime = System.<span style="color:#2b91af;">Convert</span>.ToDateTime(value);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;"> (dateTime == <span style="color:#2b91af;">DateTime</span>.MinValue)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">String</span>.Empty;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> dateTime.ToString(<span style="color:#a31515;">&#8220;MM/dd/yyyy&#8221;</span>);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">catch</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:#2b91af;">FormatException</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">catch</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:#2b91af;">OverflowException</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">string</span>.Format(<span style="color:#2b91af;">CultureInfo</span>.CurrentCulture, <span style="color:#a31515;">&#8220;{0}&#8221;</span>, value);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">object</span> ConvertBack(<span style="color:#0000ff;">object</span> value, <span style="color:#2b91af;">Type</span> targetType,</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;"><span style="color:#0000ff;">object</span> parameter, <span style="color:#2b91af;">CultureInfo</span> culture)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#2b91af;">DateTime</span>.Parse(value <span style="color:#0000ff;">as</span> <span style="color:#0000ff;">string</span>);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-left:1in;"> </p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">The data binding infrastructure of the WPF is extremely flexible. One of the major contributors to that flexibility is the fact that a custom value converter can be injected between two bound objects (i.e. the data source and target). A value converter can be thought of as a black box into which a value is passed, and another value is emitted. </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">A value converter is any object which implements the </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">IValueConverter</span><span style="font-size:10pt;line-height:115%;font-family:&quot;"> interface. That interface exposes two methods: </span><code><span style="font-size:10pt;line-height:115%;font-family:&quot;">Convert</span></code><span style="font-size:10pt;line-height:115%;font-family:&quot;"> and </span><code><span style="font-size:10pt;line-height:115%;font-family:&quot;">ConvertBack</span></code><span style="font-size:10pt;line-height:115%;font-family:&quot;">. </span><code><span style="font-size:10pt;line-height:115%;font-family:&quot;">Convert</span></code><span style="font-size:10pt;line-height:115%;font-family:&quot;"> is called when a bound value is being passed from the data source to the target, and </span><code><span style="font-size:10pt;line-height:115%;font-family:&quot;">ConvertBack</span></code><span style="font-size:10pt;line-height:115%;font-family:&quot;"> is called for the inverse operation. If a value converter decides that it cannot return a meaningful output value based on the input value, it can return </span><code><span style="font-size:10pt;line-height:115%;font-family:&quot;">Binding.DoNothing</span></code><span style="font-size:10pt;line-height:115%;font-family:&quot;">, which will inform the data binding engine to not push the output value to the binding operation’s respective target. </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">Above I defined two Converter classes one for currency and the other for date conversion.</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">public</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">static</span> <span style="color:#0000ff;">void</span> SetDataTemplatesForGridColumns(<span style="color:#2b91af;">DataTable</span> dataTable, <span style="color:#2b91af;">DataGridControl</span> dataGrid)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">Binding</span><span style="font-size:10pt;font-family:&quot;"> itemsBinding;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">FrameworkElementFactory</span><span style="font-size:10pt;font-family:&quot;"> textBlockFactory;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"> </p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">foreach</span><span style="font-size:10pt;font-family:&quot;"> (<span style="color:#2b91af;">DataColumn</span> column <span style="color:#0000ff;">in</span> dataTable.Columns)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;"> (column.DataType == <span style="color:#0000ff;">typeof</span>(<span style="color:#0000ff;">double</span>) || column.DataType == <span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">Int32</span>))</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;"> (column.ColumnName == <span style="color:#a31515;">&#8220;Amount&#8221;</span> || column.ColumnName == <span style="color:#a31515;">&#8220;LocalAmount&#8221;</span>)</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Binding</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">CurrencyConverter</span><span style="font-size:10pt;font-family:&quot;"> converter = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">CurrencyConverter</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding.Converter = converter;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">//itemsBinding.ConverterParameter = c.DisplayFormat;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding.ConverterCulture = <span style="color:#2b91af;">CultureInfo</span>.CreateSpecificCulture(<span style="color:#a31515;">&#8220;en-US&#8221;</span>);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">FrameworkElementFactory</span>(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">TextBlock</span>));</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.Name = <span style="color:#a31515;">&#8220;myTextBlockFactory&#8221;</span> + column.ColumnName;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetBinding(<span style="color:#2b91af;">TextBlock</span>.TextProperty, itemsBinding);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetValue(<span style="color:#2b91af;">TextBlock</span>.HorizontalAlignmentProperty, <span style="color:#2b91af;">HorizontalAlignment</span>.Right);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetValue(<span style="color:#2b91af;">TextBlock</span>.MarginProperty, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Thickness</span>(0, 0, 5, 0));</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">DataTemplate</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate.VisualTree = textBlockFactory;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">else</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Binding</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">FrameworkElementFactory</span>(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">TextBlock</span>));</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.Name = <span style="color:#a31515;">&#8220;myTextBlockFactory&#8221;</span> + column.ColumnName;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetBinding(<span style="color:#2b91af;">TextBlock</span>.TextProperty, itemsBinding);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetValue(<span style="color:#2b91af;">TextBlock</span>.HorizontalAlignmentProperty, <span style="color:#2b91af;">HorizontalAlignment</span>.Right);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetValue(<span style="color:#2b91af;">TextBlock</span>.MarginProperty, <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Thickness</span>(0,0,5,0));</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">DataTemplate</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate.VisualTree = textBlockFactory;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">if</span><span style="font-size:10pt;font-family:&quot;">(column.DataType == <span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">DateTime</span>))</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">{</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Binding</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">DateConverter</span><span style="font-size:10pt;font-family:&quot;"> dateConverter = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">DateConverter</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding.Converter = dateConverter;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding.ConverterCulture = <span style="color:#2b91af;">CultureInfo</span>.CreateSpecificCulture(<span style="color:#a31515;">&#8220;en-US&#8221;</span>);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">FrameworkElementFactory</span>(<span style="color:#0000ff;">typeof</span>(<span style="color:#2b91af;">TextBlock</span>));</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.Name = <span style="color:#a31515;">&#8220;myTextBlockFactory1&#8243;</span> + column.ColumnName; </span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetBinding(<span style="color:#2b91af;">TextBlock</span>.TextProperty, itemsBinding);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">textBlockFactory.SetValue(<span style="color:#2b91af;">TextBlock</span>.HorizontalAlignmentProperty, <span style="color:#2b91af;">HorizontalAlignment</span>.Left);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">DataTemplate</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate.VisualTree = textBlockFactory;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">}</span></p>
<p><span style="font-size:10pt;line-height:115%;font-family:&quot;">}</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Binding</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">CurrencyConverter</span><span style="font-size:10pt;font-family:&quot;"> converter = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">CurrencyConverter</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding.Converter = converter;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">itemsBinding.ConverterCulture = <span style="color:#2b91af;">CultureInfo</span>.CreateSpecificCulture(<span style="color:#a31515;">&#8220;en-US&#8221;</span>);</span></p>
<p class="MsoNormal"> </p>
<p><span>the above lines creates a Binding object and sets its Converter property.Here itemsBinding.ConverterCulture set to ‘en-US’</span><span> (English USA)</span><span> to display data in currency format(245.89378 as $245.89).</span> The .NET format strings are useful if you want to convert one of the standard .NET Framework data types to a string that represents that type in some other format. For example, if you have an integer value of 100 that you want to represent to the user as a currency value, you could easily use the <span>ToString</span> method and the currency-format string (&#8220;C&#8221;) to produce a string of &#8220;$100.00&#8243;. Computers that do not have English (United States) specified as the current culture will display whatever currency notation is used by the current culture. The original value contained in the data type is not converted, but a new string is returned that represents the resulting value. This new string cannot be used for calculation until it is converted back to a .NET base data type. The original value, however, can be calculated at any time.</p>
<p>In the following code example, the <span>ToString</span> method displays the value of 100 as a currency-formatted string in the console&#8217;s output window.</p>
<p><span style="color:#0070c0;">double</span> Amount=100;</p>
<p><span style="color:#0070c0;">string</span> formatedAmount=Amount.ToString(<span style="color:#a31515;">&#8220;C”</span>);</p>
<p>Console.WriteLine(formatedAmount);</p>
<p>This code displays $100.00 to the console on computers that have English (United States) as the current culture.</p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">In<span> </span></span><span style="font-size:10pt;font-family:&quot;">CurrencyConverter </span><span style="font-size:10pt;font-family:&quot;">class, the<span> </span>line</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">return</span><span style="font-size:10pt;font-family:&quot;"> <span style="color:#0000ff;">string</span>.Format(<span style="color:#2b91af;">CultureInfo</span>.CurrentCulture, <span style="color:#a31515;">&#8220;{0:C}&#8221;</span>, tempDouble);</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">will do the same.</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">FrameworkElementFactory</span><span style="font-size:10pt;line-height:115%;font-family:&quot;"> class is a deprecated way to programmatically create templates, which are subclasses of</span><span style="font-size:10pt;line-height:115%;font-family:&quot;"> FrameworkTemplate</span><span style="font-size:10pt;line-height:115%;font-family:&quot;"> such as </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">ControlTemplate</span><span style="font-size:10pt;line-height:115%;font-family:&quot;"> or </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">DataTemplate</span><span style="font-size:10pt;line-height:115%;font-family:&quot;">; </span></p>
<p class="MsoNormal"><span style="font-size:10pt;line-height:115%;font-family:&quot;">I created a </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">FrameworkElementFactory </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">object of type </span><span style="font-size:10pt;line-height:115%;font-family:&quot;">TextBlock.</span><span style="font-size:10pt;line-height:115%;font-family:&quot;">Then set its horizontal alignment and margin properties.</span></p>
<p class="MsoNormal"> </p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">DataTemplate</span>();</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">dataGrid.Columns[column.ColumnName].CellContentTemplate.VisualTree = textBlockFactory;</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"> </p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;"><span style="font-size:10pt;font-family:&quot;">the above two lines creates a DataTemplate for DataGrid CellContentTemplate ,set its VisualTree to the <span style="color:#2b91af;">FrameworkElementFactory </span></span><span style="font-size:10pt;font-family:&quot;">object textBlockFactory</span><span style="font-size:10pt;font-family:&quot;">.<span style="color:#2b91af;"> DateConverter </span>also do the same as <span style="color:#2b91af;">CurrencyConverter </span>but it displays the data in the given date format,here the format given is <span style="color:#a31515;">&#8220;MM/dd/yyyy&#8221;</span>.</span></p>
<p class="MsoNormal" style="margin-bottom:.0001pt;line-height:normal;">Here is the sample output of the resultant grid.</p>
<p><img src="http://venkatsworld.files.wordpress.com/2008/10/exmp.jpg?w=460" alt="" /></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/venkatsworld.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/venkatsworld.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/venkatsworld.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/venkatsworld.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/venkatsworld.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/venkatsworld.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/venkatsworld.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/venkatsworld.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/venkatsworld.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/venkatsworld.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/venkatsworld.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/venkatsworld.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/venkatsworld.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/venkatsworld.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/venkatsworld.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/venkatsworld.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=8&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://venkatsworld.wordpress.com/2008/09/08/wpf-data-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a1af4102295ad6c590f8aad7c9f97ec?s=96&#38;d=identicon" medium="image">
			<media:title type="html">venkatworld</media:title>
		</media:content>

		<media:content url="http://venkatsworld.files.wordpress.com/2008/10/exmp.jpg" medium="image" />
	</item>
		<item>
		<title>Hello world!</title>
		<link>http://venkatsworld.wordpress.com/2008/09/08/hello-world/</link>
		<comments>http://venkatsworld.wordpress.com/2008/09/08/hello-world/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 13:20:53 +0000</pubDate>
		<dc:creator>venkatworld</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Welcome to Venkat&#8217;World&#8230;&#8230;..! I am  here to share my Thoughts&#8230;.and Ideas&#8230;.!..! So&#8230;&#8230;keep browsing&#8230;&#8230;.for updates&#8230;&#8230;!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=1&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to Venkat&#8217;World&#8230;&#8230;..!</p>
<p>I am  here to share my Thoughts&#8230;.and Ideas&#8230;.!..!</p>
<p>So&#8230;&#8230;keep browsing&#8230;&#8230;.for updates&#8230;&#8230;!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/venkatsworld.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/venkatsworld.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/venkatsworld.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/venkatsworld.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/venkatsworld.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/venkatsworld.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/venkatsworld.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/venkatsworld.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/venkatsworld.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/venkatsworld.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/venkatsworld.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/venkatsworld.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/venkatsworld.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/venkatsworld.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/venkatsworld.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/venkatsworld.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=venkatsworld.wordpress.com&amp;blog=4773135&amp;post=1&amp;subd=venkatsworld&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://venkatsworld.wordpress.com/2008/09/08/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/7a1af4102295ad6c590f8aad7c9f97ec?s=96&#38;d=identicon" medium="image">
			<media:title type="html">venkatworld</media:title>
		</media:content>
	</item>
	</channel>
</rss>
