tag:blogger.com,1999:blog-64691788813897012392024-03-12T23:46:18.367-04:00I Love MicrosoftAkkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.comBlogger46125tag:blogger.com,1999:blog-6469178881389701239.post-52667361953176309812016-03-01T21:50:00.001-05:002016-03-01T21:50:10.081-05:00Create a task in Task Scheduler using PowerShell Script<p> <p>We all know how to create a task in Task Scheduler. When we create a task we need to add many settings to run the task periodically as per the settings. But what to do when we want to create the same task in multiple environments in your project. Creating them manually is a tedious task and as usual Microsoft heard you and provided the option to configure the tasks using the mighty powerful “<b>PowerShell script</b>”. But with one exception that this is available for Windows 8.1 and higher and Windows 2012. <p>To demonstrate the powerful PowerShell capability, let’s dive in. <p>I want to create the following task in order to run a testapp.exe periodically. <p>We want to accomplish the following: <p>Create a new task and the task name should be “Test Task” and it should run as “NT Authority”. <p><a href="https://lh3.googleusercontent.com/-jvJdyA_-FDM/VtZUzzkkwrI/AAAAAAAAETQ/7ZStQhuJhC8/s1600-h/clip_image001%25255B3%25255D.png"><img title="clip_image001" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image001" src="https://lh3.googleusercontent.com/-i8FgSDPFbr4/VtZU0X3AFDI/AAAAAAAAETU/QNhrWleGCtY/clip_image001_thumb.png?imgmax=800" width="244" height="185"></a> <p align="center">Figure 1: General properties <p>Trigger tab should be set with the settings as <p>1. It should run daily and start date is 3/1/2016 and at 12:00:00 AM and it should recur for every 1 day. <p>2. Also the task should repeat every one hour and it should run for a duration of 1 hour. <p><a href="https://lh3.googleusercontent.com/-I-LDzLrlgz8/VtZU0puyzSI/AAAAAAAAETY/5AZb4JchgKc/s1600-h/clip_image003%25255B3%25255D.jpg"><img title="clip_image003" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image003" src="https://lh3.googleusercontent.com/-kRsKosGdM2U/VtZU0_5AZVI/AAAAAAAAETc/SHP69gNd4IA/clip_image003_thumb.jpg?imgmax=800" width="244" height="180"></a> <p align="center">Figure 2: Trigger settings <p>The action tab should be configured to run the program “TestApp.exe” which is located in C Drive. <p><a href="https://lh3.googleusercontent.com/-Y1RU4QdRB0k/VtZU1YrWx9I/AAAAAAAAETg/Gj5maWbbhKQ/s1600-h/clip_image005%25255B3%25255D.jpg"><img title="clip_image005" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image005" src="https://lh3.googleusercontent.com/-YzzT1yTUht8/VtZU1j5tT-I/AAAAAAAAETk/HkUvPP8GBkE/clip_image005_thumb.jpg?imgmax=800" width="244" height="193"></a> <p align="center">Figure 3: Action settings <p>Our settings tab should be configured with the following settings: <p>1. Allow task to run on demand <p>2. If the task fails, restart every 1 hour and it should attempt restarting for 3 times <p>3. If the task runs for more than 1 hour then stop it and also force it to be stopped if it’s not stopping <p><a href="https://lh3.googleusercontent.com/-bEEMy0lOStA/VtZU2HGKIfI/AAAAAAAAETo/QifN9_8XGZs/s1600-h/clip_image007%25255B3%25255D.jpg"><img title="clip_image007" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image007" src="https://lh3.googleusercontent.com/-5wBeS0fB2Ro/VtZU2UUjPkI/AAAAAAAAETs/yBgOsfDhktM/clip_image007_thumb.jpg?imgmax=800" width="244" height="185"></a> <p align="center">Figure 4: Setting tab <p>Let us write the PowerShell script to accomplish the above mentioned task in the task scheduler. Here are the steps: <p>Step 1: Name of the task. <p>Create a variable and assign task name. In our case it should be “Test Task”. <table cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td valign="top" width="623"> <p><font color="#008040"># Name of Task to create</font> <p><font color="#ff0000">$taskName = "Test Task"</font> </p></td></tr></tbody></table> <p>Step 2: Set the credentials. <p>Create two more variables and assign it the credentials. <p>In our case, we want the task to run as “NT Authority” and password is not required. But if you want to run with a particular account username and password, create username and password variables and assign them the values. <table cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td valign="top" width="623"> <p><font color="#008080"># UserName to run task as</font> <p><font color="#ff0000">$user = "NT AUTHORITY\SYSTEM"</font> <p><font color="#008080"># Password for above user</font> <p><font color="#008080">#$password = "userPassword" Uncomment this line if you need to set up password</font></p></td></tr></tbody></table> <p>Step 3: Now create the task <p>In our case we do not have any arguments. But if you need to add then uncomment the $argument line and set the $argumentvalue <p>$action defines the action to perform i.e. to execute the exe file and uncomment the argument parameter after the exe if you need to add it. <p>$trigger defines the trigger settings <p>$settings defines the settings settings <table cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td valign="top" width="623"> <p><font color="#008080">#$argument = "-Noninteractive -Noprofile -Command &'" + $argumentvalue + "'"</font> <p><font color="#ff0000">$action = New-ScheduledTaskAction -Execute "C:\MyTestApp.exe"</font> <font color="#008080">#-Argument $argument</font> <p><font color="#ff0000">$trigger = New-ScheduledTaskTrigger -Daily -At 12am</font> <p><font color="#ff0000">$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 60) </font> <p><font color="#ff0000">$settings.RestartCount=3</font> <p><font color="#ff0000">$settings.RestartInterval = 'PT01H'</font> </p></td></tr></tbody></table> <p>Step 4: Get the instance of scheduled task by specifying New-ScheduledTask command and set the action and trigger and register the scheduled task. <table cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td valign="top" width="623"> <p><font color="#ff0000">$inputObject = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings</font> <p><font color="#ff0000">Register-ScheduledTask -TaskName $taskName -InputObject $inputObject -User $user</font> </p></td></tr></tbody></table> <p>Step 5: Now wait for 5 seconds and then set the trigger repetition interval and duration and set the scheduled task. <table cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td valign="top" width="623"> <p><font color="#ff0000">Start-Sleep -Seconds 5</font> <p><font color="#ff0000">$t = get-scheduledtask -TaskName $taskName</font> <p><font color="#ff0000">$t.Triggers.repetition.Duration = 'PT60M'</font> <p><font color="#ff0000">$t.Triggers.repetition.Interval = 'PT01H'</font> <p><font color="#ff0000">$t | Set-ScheduledTask</font> </p></td></tr></tbody></table> <p>The completed script will look as below: <table cellspacing="0" cellpadding="0" border="1"> <tbody> <tr> <td valign="top" width="623"> <p><font color="#008080"># Name of Task to create</font> <p><font color="#ff0000">$taskName = "Test Task"</font> <p><font color="#008080">#$argumentvalue = "first"</font> <p><font color="#008080"># UserName to run the task created as</font> <p><font color="#ff0000">$user = "NT AUTHORITY\SYSTEM"</font> <p><font color="#008080"># Password for above user</font> <p><font color="#008080">#$password = "userPassword"</font> <p><font color="#008080"># Create Task</font> <p><font color="#008080">#$argument = "-Noninteractive -Noprofile -Command &'" + $argumentvalue + "'"</font> <p><font color="#ff0000">$action = New-ScheduledTaskAction -Execute "C:\MyTestApp.exe"</font> <font color="#008080">#-Argument $argument</font> <p><font color="#ff0000">$trigger = New-ScheduledTaskTrigger -Daily -At 12am</font> <p><font color="#ff0000">$settings = New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 60) </font> <p><font color="#ff0000">$settings.RestartCount=3</font> <p><font color="#ff0000">$settings.RestartInterval = 'PT01H'</font> <p><font color="#ff0000">$inputObject = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings</font> <p><font color="#ff0000">Register-ScheduledTask -TaskName $taskName -InputObject $inputObject -User $user</font> <p><font color="#ff0000">Start-Sleep -Seconds 5</font> <p><font color="#ff0000">$t = get-scheduledtask -TaskName $taskName</font> <p><font color="#ff0000">$t.Triggers.repetition.Duration = 'PT60M'</font> <p><font color="#ff0000">$t.Triggers.repetition.Interval = 'PT01H'</font> <p><font color="#ff0000">$t | Set-ScheduledTask</font> </p></td></tr></tbody></table> <p>The above few lines of code will do the job of creating the task with the same settings and you can automate it so that you can run wherever you want. <p>When you run the script you should see following screen: <p><a href="https://lh3.googleusercontent.com/-bIxv8ezedx8/VtZU3Nygp7I/AAAAAAAAETw/lJnA6SKdUlE/s1600-h/clip_image009%25255B3%25255D.jpg"><img title="clip_image009" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image009" src="https://lh3.googleusercontent.com/-nj1_NMKFn48/VtZU3t5cewI/AAAAAAAAET0/fEEV9lNVWa8/clip_image009_thumb.jpg?imgmax=800" width="244" height="66"></a> <p align="center">Figure 5: Script execution <p>A trick if you do not know how to set the parameters for the commands. Go to “Windows PowerShell ISE” and run as administrator if needed and type the command that you want to add to the script by using the command window as below: <p><a href="https://lh3.googleusercontent.com/-mwpGUSMSqv0/VtZU39c4SWI/AAAAAAAAET4/c3H78OsMf2g/s1600-h/clip_image011%25255B3%25255D.jpg"><img title="clip_image011" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image011" src="https://lh3.googleusercontent.com/-JxfIHKxNEdc/VtZU4clu1JI/AAAAAAAAET8/cSvZXUVzRlE/clip_image011_thumb.jpg?imgmax=800" width="97" height="244"></a> <p align="center">Figure 6: Command window <p>You can find more commands in the MSDN and hope this article is useful for creating a basic task in the task scheduler using the PowerShell script. With the growth of automation and agile methodologies everywhere, it would be beneficial for the teams to explore the PowerShell more and more and to replace your manual tasks wherever it is possible. Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com1tag:blogger.com,1999:blog-6469178881389701239.post-66014551358472890472016-02-25T21:30:00.000-05:002016-02-25T21:30:46.133-05:00IaaS, Internal Load Balancing (ILB) in AZURE<p> <p>When we speak of cloud we always think of Platform as a service (PaaS), Infrastructure as a service (IaaS) and Software as a Service (SaaS). <p>In this article we discuss about the IaaS and how to scale websites or applications running in virtual machines that forms a part of IaaS infrastructure. In simple terms, IaaS means we buy a storage from cloud provider and we deploy or create our own machines or provider’s pre-built Images and we control the infrastructure like operating systems, ports and all the software installed on the machines. <p>Common scenarios for opting to IaaS is when a company wants to setup a testing environment for a particular period of time, or a dev team is doing some R&D and needs a machine with particular configuration for temporary purpose and later those machines will be decommissioned. This way, we do not need to invest on the infrastructure that we use only for a particular amount of time. But this may not be correct always. It always depends upon the requirements. <p>Before jumping into the details on how to create ILBs, let us try to understand how ILBs differ from typical load balances (F5s). <p>F5 Load Balancers: <p><a href="https://lh3.googleusercontent.com/-vei7kaCMCrA/Vs-378kRtYI/AAAAAAAAEQ8/cqWUuMuU2xs/s1600-h/Figure1%252520load%252520balancers%252520-second%25255B3%25255D.png"><img title="Figure1 load balancers -second" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Figure1 load balancers -second" src="https://lh3.googleusercontent.com/-WVGh1T6KCZs/Vs-38QUaTtI/AAAAAAAAERA/qRqVvxn5JRo/Figure1%252520load%252520balancers%252520-second_thumb%25255B1%25255D.png?imgmax=800" width="240" height="81"></a> <p align="center">Figure 1: F5 Load balancers (Firewall sitting between is optional) <p>F5 load balancers primarily sit between clients and the hosts that provide the services. <p>F5 load balancers typically are used when we expose our services to the outside of our company network. This does not mean they will not be used within the company network. But when we deploy our services or applications in ON PREMISE and want to expose the services/applications to the outside world. <p>The typical transaction flow will be as follows: <p>Let us make the following assumptions to understand the transaction flow: <p>Load Balancer URL – 192.168.89.1 <p>Web Server 1 – 192.168.77.76 <p>Web server 2 – 192.168.77.77 and the service name - weatherinfo <p><a href="https://lh3.googleusercontent.com/-P8EpavqbmM8/Vs-3815ei-I/AAAAAAAAERE/0FWA2lbCdJk/s1600-h/Figure%2525202%252520Sequence%252520diagram%25255B3%25255D.png"><img title="Figure 2 Sequence diagram" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="Figure 2 Sequence diagram" src="https://lh3.googleusercontent.com/-UmbopYZzEPE/Vs-39TNa8cI/AAAAAAAAERI/Dir_gl8ufZE/Figure%2525202%252520Sequence%252520diagram_thumb%25255B1%25255D.png?imgmax=800" width="240" height="127"></a> <p align="center">Figure 2: Load balancing flow between the clients and the hosts through Load Balancers <p>Load Balancers uses the health monitoring mechanism to periodically check the health of the hosts and accordingly will forward the request to the host. A simple health check mechanism will be PINGING to the server and checking for the response. Next level mechanism is to deploy the health check application that provides the health of the intended service and gives accurate information to the Load balancer if it has to forward a request or not. <p>If health of all the hosts are good then LBs use Round Robin as a simple mechanisms to complex algorithms based on connection counts, host utilization and other important criterion to decide which host needs to be responding to a particular request. <p>Internal Load Balancers (ILBs): <p>ILBs comes into picture when we talk about Cloud services created in AZURE, AWS and so on. Unlike Load balancers, ILBs supports the following types of load balancing: <p>- Load balancing between the virtual machines within a cloud service. <p>- Load balancing between virtual machines between different cloud services that are contained within a virtual network. <p>In this article, we would be going through the first type i.e. load balancing of incoming internet traffic to different virtual machines within a cloud service. This is also called as Network Level type of load balancing. <p><a href="https://lh3.googleusercontent.com/-F_5OQelVqrw/Vs-39uMLIMI/AAAAAAAAERM/FMJwho94Hcs/s1600-h/clip_image006%25255B4%25255D.png"><img title="clip_image006" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image006" src="https://lh3.googleusercontent.com/-aCyfNXuxuwI/Vs-3-E1aKHI/AAAAAAAAERQ/j-LPGj1FWvs/clip_image006_thumb%25255B1%25255D.png?imgmax=800" width="240" height="174"></a> <p align="center">Figure 3: ILB with VMs <p>Let’s go through the steps to create the ILB by creating two virtual machines and creating a load balanced set to load balance the two VMs. There is no direct way to create Load Balanced set in portal and it should be done as a part of creation of VMs. <p>Step 1: Create a cloud service first so that we can add the VMs to the cloud service. (I am not using portal instead I am using manage.windowsazure.com for this article) <p><a href="https://lh3.googleusercontent.com/-Cb_B7pOFRg8/Vs-3-STf2GI/AAAAAAAAERU/zYY9U1TiWO8/s1600-h/clip_image008%25255B4%25255D.jpg"><img title="clip_image008" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image008" src="https://lh3.googleusercontent.com/-YRPb3XFyNLs/Vs-3-oIw5yI/AAAAAAAAERY/36u9_Lrb2HA/clip_image008_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="105"></a> <p><a href="https://lh3.googleusercontent.com/-1h9feP_nyUY/Vs-3_I_FYGI/AAAAAAAAERc/XVYTUeLp5yw/s1600-h/clip_image010%25255B4%25255D.jpg"><img title="clip_image010" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image010" src="https://lh3.googleusercontent.com/-aG22JmYEKws/Vs-3_ToOkaI/AAAAAAAAERg/z5IPWgypMxw/clip_image010_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="55"></a> <p align="center">Figure 4: Creation of cloud service <p>2. Create a Virtual machine. <p><a href="https://lh3.googleusercontent.com/-GYk7OtwXubU/Vs-3_ugvLjI/AAAAAAAAERk/Qm1jwwBeuDQ/s1600-h/clip_image012%25255B4%25255D.jpg"><img title="clip_image012" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image012" src="https://lh3.googleusercontent.com/-bqBAF68W5PY/Vs-3_yRJNLI/AAAAAAAAERo/5rmHCsWzEO0/clip_image012_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="74"></a> <p align="center">Figure 5: Selecting Compute à Virtual Machine <p><a href="https://lh3.googleusercontent.com/-pKp3M2gsotI/Vs-4AVAO-EI/AAAAAAAAERs/dlFJ-G8-qwQ/s1600-h/clip_image014%25255B4%25255D.jpg"><img title="clip_image014" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image014" src="https://lh3.googleusercontent.com/-tfd0WC4GAHY/Vs-4AvoMXRI/AAAAAAAAERw/c4hwb2yAhDc/clip_image014_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="166"></a></p> <p align="center">Figure 6: Choosing the image (Windows server 2012 R2 Datacenter) <p><a href="https://lh3.googleusercontent.com/-g1qfvb3LTo4/Vs-4A70lX6I/AAAAAAAAER0/Br-phuM3inM/s1600-h/clip_image016%25255B4%25255D.jpg"><img title="clip_image016" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image016" src="https://lh3.googleusercontent.com/-t9qBVJgMtYg/Vs-4BKn0LeI/AAAAAAAAER4/jFu45Rev6Kw/clip_image016_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="153"></a></p> <p><a href="https://lh3.googleusercontent.com/-rqw3bbkefVw/Vs-4BsKgM1I/AAAAAAAAER8/GmUkuoBLjo8/s1600-h/clip_image018%25255B4%25255D.jpg"><img title="clip_image018" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image018" src="https://lh3.googleusercontent.com/--xUP08EtLsk/Vs-4B5dNAHI/AAAAAAAAESA/R8lmv1kmdCk/clip_image018_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="152"></a> <p align="center">Figure 7: VM Configuration <p><a href="https://lh3.googleusercontent.com/-FCDelvinzoI/Vs-4CFu9LmI/AAAAAAAAESE/Wzr876I4qpg/s1600-h/clip_image020%25255B4%25255D.jpg"><img title="clip_image020" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image020" src="https://lh3.googleusercontent.com/-dOvwwRA7EgU/Vs-4CjwWKjI/AAAAAAAAESI/ZvwbMabDxM4/clip_image020_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="83"></a></p> <p>Figure 8: Added HTTP and HTTPS endpoints by clicking “Add” button on the bottom of the page <p>Step 3: Now select HTTPS endpoint and click edit icon and create a LOAD-BALANCED SET. I want to load balance the VMs through the port 443. <p><a href="https://lh3.googleusercontent.com/-5eMMQ37AIqQ/Vs-4C6PaDKI/AAAAAAAAESM/uydDiPasko4/s1600-h/clip_image022%25255B4%25255D.jpg"><img title="clip_image022" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image022" src="https://lh3.googleusercontent.com/-VhKONLRyB1g/Vs-4DLh4nhI/AAAAAAAAESQ/NLUhbqvL39s/clip_image022_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="196"></a> <p align="center">Figure 9: Editing the HTTPS endpoint to create a Load Balanced set <p><a href="https://lh3.googleusercontent.com/-hbt0_JbyEx0/Vs-4Dc1NA4I/AAAAAAAAESU/6F3TlM7mK_U/s1600-h/clip_image024%25255B4%25255D.jpg"><img title="clip_image024" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image024" src="https://lh3.googleusercontent.com/-yJvr5gpMhrw/Vs-4D_q2hXI/AAAAAAAAESY/o5LdCp8oI44/clip_image024_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="195"></a></p> <p align="center">Figure 10: Setting the load-balanced set details <p>In the figure 9, Probe Protocol indicates which protocol does the load balancer should use to probe the health of the VM and the port denotes the port to be used, Probe Interval tells the load balancer to attempt a TCP connect to the specified probe port for every 15 seconds. If it did not get TCP ACK back for two times (Number of probes), then it will consider that the node is offline and will stop traffic to that node. <p><a href="https://lh3.googleusercontent.com/-P791G7zHGoc/Vs-4EFFqG9I/AAAAAAAAESc/OjdPQLPY_E8/s1600-h/clip_image026%25255B4%25255D.jpg"><img title="clip_image026" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image026" src="https://lh3.googleusercontent.com/-0kc2pgmBn3U/Vs-4EZbSqDI/AAAAAAAAESg/FgxMO3T8QBc/clip_image026_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="71"></a> <p align="center">Figure 11: Check the load-balanced set is created on HTTPS endpoint 443. <p>Now create another VM by following the above steps and then add a HTTPS endpoint and select option “Add an endpoint to an Existing load balanced set” and proceed. <p><a href="https://lh3.googleusercontent.com/-umVwc2iNjTQ/Vs-4EvFj_OI/AAAAAAAAESk/x4s-IxIrR-s/s1600-h/clip_image028%25255B4%25255D.jpg"><img title="clip_image028" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image028" src="https://lh3.googleusercontent.com/-VCkX4_W3xrQ/Vs-4E9NuC2I/AAAAAAAAESo/EnAE8ZkClEQ/clip_image028_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="98"></a> <p align="center">Figure 12: Adding an endpoint to an existing load balanced set <p>After completing the above steps, create a website in IIS for both the VMs and expose the sites on port 443. I have created a website with a simple html page in both the VMs. For VM1, the html displays the text “This is from WEBMAC1” and for VM2 it displays “This is from WEBMAC2”. <p>Now when I browse <p><a href="https://lh3.googleusercontent.com/-DZxrg9uo3MY/Vs-4FCtuUoI/AAAAAAAAESs/352Uds15ER8/s1600-h/clip_image030%25255B4%25255D.jpg"><img title="clip_image030" style="border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto" border="0" alt="clip_image030" src="https://lh3.googleusercontent.com/-An1t_dP8AHk/Vs-4FQ6ho9I/AAAAAAAAESw/mgyX06D72aI/clip_image030_thumb%25255B1%25255D.jpg?imgmax=800" width="240" height="38"></a> <p align="center">Figure 13: Website page <p>Now browse the cloud service and you should see the web page randomly displaying the messages from the both the boxes. Try to stop the website in one of the box or stop the VM and see if you are still able to browse. It should not be trying to hit the stopped VM or website. <p>Additional points: <p>In the figure 6 while creating VMs, I did not add “Availability Set”. But if you create one and assign it to both the VMs, Windows Azure will make sure that the two VMs are created on separate racks in the data center. This will also help during the host patching by not taking down all the nodes at same time and makes sure that your application will always run. This is most critical in any organization that needs 24/7 availability. <p>Also while configuring load balanced set, I have configured on TCP port. But you can do the same with HTTP port. This will allow you to write your own website or app that informs the health of the application which is more accurate than hitting the TCP port. You can add your custom logic to tell if the application is healthy. For example, if your application is not able to talk to database from the hosted server, you do not want the requests to be forwarded to that server and thus you can eliminate error screens for clients. <p>One more thing is that I have used same port 443 for both application and probing port. In real time situations they need not be or will not be same. Also for HTTP probes make sure that the application on that port does not support any authentication mechanism. It should respond without providing any credentials. <p>In real time scenarios, we will not follow the manual steps mentioned in the article. It will be easier to perform these in automated fashion using Powershell. You can check MSDN for more information on using Powershell scripts.</p>Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-12124049039377825142015-08-01T20:44:00.000-04:002015-08-01T20:46:35.766-04:00Pipes and Filters Pattern <br />
<b>Requirements</b>: To understand the article, a basic knowledge of OOPs and
Visual studio is required along with the C# basic knowledge programming.
<br />
<br />
I tried to explain the article in such a fashion that simulates the typical
software projects environment. The program developed in this article does not
actually publish message to any queue. Just to simulate the message being
encrypted and priority set, added some properties in the Message to support
them. But in actual projects, we might be doing the job in different manner.
<br />
<br />
<b>Existing system:</b>
<br />
Company ABC wants to build a new application called “Messenger” that
publishes the messages to MSMQ. They are expecting two new consumers to this
application as soon as it is developed. One consumer will be publishing
sensitive data and so expects the message to be encrypted while publishing it to
the Queue and also wants to set the priority for message. The other consumer
will be publishing simple text data that does not need any encryption and only
sets the message priority.
<br />
New requests from other consumers are expected in soon and the application
should be built in such a way to incorporate any changes to the existing
architecture in future.
<br />
<br />
So the Application manager approaches the technical team with following
problem statement:
<br />
<i>“<b>I want to publish a message to a queue and it should undergo certain
transformations or perform certain operations before publishing it.</b></i>
<br />
<b><i>I want my code design to support adding new operations or removing the
existing operations.</i></b><i>”</i>
<br />
<i><br /></i>
Then the Architect/Technical lead jumps in and proposes “<b><i>Pipes and
Filters Pattern</i></b>” as the solution to the problem and provides the design
to the development team with the High level details as below:
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj92Wvf4MZqchrj8kmihdOqbFqPJzFzCRoqDDfw7TMM0rVlzMsUprZOfAyAxrIaTOjVQgKl3i6nomXplNWBQBYC8W8IT0V8x2F4w9CLE7vMf6dQZDxYE1V0t_0UnGvf6H9yTSH6-vSQ0IA/s1600/Figure1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="177" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj92Wvf4MZqchrj8kmihdOqbFqPJzFzCRoqDDfw7TMM0rVlzMsUprZOfAyAxrIaTOjVQgKl3i6nomXplNWBQBYC8W8IT0V8x2F4w9CLE7vMf6dQZDxYE1V0t_0UnGvf6H9yTSH6-vSQ0IA/s640/Figure1.PNG" width="640" /></a></div>
<br />
<br />
Figure 1 – Publishing message to the Queue
<br />
<br />
Color depictions used in the diagram: Incoming message is in green color gets
transformed to blue color after the message priority is set and then transformed
to orange color after message is encrypted and sent as an output.
<br />
<br />
<b>High Level Details:
</b><br />
- <b><i>Pipes and Filters</i></b> architectural pattern is one of the
<b><i>Messaging Patterns</i></b> which helps in splitting a large set of
operations on a message into different processes so that each process can work
on the message independently and complete the transformation of the message.
<br />
- Here each process will be called as “<b>Filters</b>” and they are connected
through the channels or connectors called “<b>Pipes</b>”.
<br />
- All the filters implement a common interface so that all will conform to
the contract that they are supposed to work on.
<br />
- Message from the source will be set as input to the process and the output
or result of the process will be sent as an input to another process and so on
until it reaches the sink or destination process. (<b>Note</b>: Here terms
“<b>Process</b>” and “<b>Filters</b>” are used interchangeably.
<br />
- In the above diagram first process sets the message priority by taking the
incoming message through pipe and then sends the output to another process to
encrypt the message.
<br />
- Then the outgoing message is published to the Queue.
<br />
<br />
<b>Advantages and disadvantages of this architectural pattern</b>:
<br />
- All the filters or operations are independent and each can plugged into or
unplugged without affecting the other one. So this is a great feature that can
be specialized for each consumer of the feature.
<br />
- Because the filters are independent of each other, you cannot establish any
communication between the filters and the message can be sent sequentially i.e.
in a linear fashion.
<br />
Then the architect provides the low level design for the implanting the
solution as below:
<br />
<br />
<strong>Class diagram</strong>:
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM-wvQZ71ifvXDdcrqaAo4aE70W2szVQozsoJ57TCFYxTWqMZNhC1ElqQU8bxt9kkmYqckykmB_vEoj3cait6s0-wAdGCQAXTCXM_TCCJQGK4mexyNmnbTwvwUGL9zd4WNgEo3xCZnKWk/s1600/Figure+2.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="354" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgM-wvQZ71ifvXDdcrqaAo4aE70W2szVQozsoJ57TCFYxTWqMZNhC1ElqQU8bxt9kkmYqckykmB_vEoj3cait6s0-wAdGCQAXTCXM_TCCJQGK4mexyNmnbTwvwUGL9zd4WNgEo3xCZnKWk/s640/Figure+2.PNG" width="640" /></a></div>
<br />
<br />
<br />
Figure 2 – Class diagram
<br />
<br />
<b></b>
<b></b>
<b></b>
<b>Class Diagram in Detail</b>:
<br />
<br />
All operations expose one interface so that they comply with the interface
implementation. In our example, <b>Setting</b> <b>Message Priority</b> and
<b>Encrypting the Message</b> are the two operations or filters that needs to be
implemented on the source message before publishing.
<br />
<br />
So we created an interface “<b>IOperation<T></b>” which supports
generic data type so that the implementing classes adhere to the type it should
support and implement the method of the interface “<b>Execute(T input)</b>”
which takes the generic type T as the input and returns the same type. This also
helps in different types to implement the same interface. This interface has
only one method “<b>Execute</b>” which should be implemented by the implementing
classes. This method takes input parameter type, performs operation and returns
the same type.
<br />
<br />
<b>Note</b>: Since we are working with messages, always message will be the
input and output for the filter or operation methods and so our method
<b>Execute </b>supports that.
<br />
<br />
<b>Now coming to the operations</b>: We need to create classes each
performing one operation and which takes the same input type and returns the
same type. As per the requirements, we need to create two classes
“<b>EncryptMessage</b>” and “<b>MessagePriority</b>” which encrypts and sets the
priority for the message.
<br />
<br />
Now there must be some way that tells which operations have to be registered
from the incoming message. This job will be done by the pipeline classes. So we
created an abstract base class “<b>Pipelinebase</b>” for pipeline that supports
generic types and it has methods for registering the operations and performing
the operations. As per our requirement, we need one pipeline that sends a
message from the client to the messaging queue and so we named our pipeline
class as “<b>SendPipeline</b>” which inherits the behavior of the base class
“<b>Pipeline</b>” and also created an interface that defines our message called
“<b>IMessage</b>” and our <b>SendPipeline</b> class supports the classes that
implement the <b>IMessage</b> interface.
<br />
<br />
Also the <b>SendPipeline</b> class should have a constructor that takes
Boolean parameters for each message operation. Since, we have only two
operations, we are creating a constructor that takes two Boolean parameters. If
you have more number of parameters, it is advisable to use the enums with flag
attribute or a type instance that carries all the setting properties.
<br />
<br />
Then the development team comes with the coding implementation as per the
class diagram and specifications provided by the architect as below:
<br />
<br />
<b>Coding in Action</b>:
<br />
<br />
<b>IOperation interface</b>: This interface supports generic type and all the
classes that implement this interface will be implementing the Execute method
that takes and returns the same type.
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">namespace PipesAndFiltersExample<br />
{<br />
/// <summary><br />
///
Operation Interface<br />
/// All operations must implement the
interface<br />
/// </summary><br />
/// <typeparam name="T">Data
type supported in the operation</typeparam><br />
public interface
IOperation<T><br />
{<br />
/// <summary><br />
///
Executes the operation<br />
/// </summary><br />
/// <param
name="input">The Input Parameter</param><br />
///
<returns>Type defined for the operation</returns><br />
T
Execute(T input);<br />
}<br />
}</td></tr>
</tbody></table>
<b><br /></b>
<b>EncryptMessage class</b>: This class encrypts the incoming message and
implements the interface IOperation<IMessage>.
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">namespace PipesAndFiltersExample<br />
{<br />
/// <summary><br />
///
Encrypts the message<br />
/// </summary><br />
class EncryptMessage :
IOperation<IMessage><br />
{<br />
/// <summary><br />
/// Executes the operation on the message<br />
///
</summary><br />
/// <param name="input">The Input
Message</param><br />
/// <returns>Type of
IMessage</returns><br />
public IMessage Execute(IMessage
input)<br />
{<br />
return Encrypt(input);<br />
}
<br />
/// <summary><br />
/// Encrypts the message<br />
/// </summary><br />
/// <param name="input">The Input
Message</param><br />
/// <returns>Type of
IMessage</returns><br />
private IMessage Encrypt(IMessage
input)<br />
{<br />
input.IsEncrypted = true;<br />
//Encryption code<br />
return input;<br />
}<br />
}<br />
}</td></tr>
</tbody></table>
<b><br /></b>
<b>MessagePriority class</b>: This class sets the message priority and
implements the interface IOperation<IMessage>.
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">namespace PipesAndFiltersExample<br />
{<br />
/// <summary><br />
///
Sets Message priority to the incoming message<br />
/// </summary><br />
class MessagePriority:IOperation<IMessage><br />
{<br />
///
<summary><br />
/// Executes the operations<br />
///
</summary><br />
/// <param name="input">The input
message</param><br />
/// <returns>Message with the priority
set</returns><br />
public IMessage Execute(IMessage
input)<br />
{<br />
input.Priority = 1;
<br />
return input;<br />
}<br />
}<br />
}
</td></tr>
</tbody></table>
<b><br /></b>
<b>IMessage interface</b>:
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">namespace PipesAndFiltersExample<br />
{<br />
/// <summary><br />
///
Message Interface<br />
/// </summary><br />
public interface
IMessage<br />
{<br />
/// <summary><br />
/// Priority of the
message<br />
/// </summary><br />
int Priority{get;set;}
<br />
/// <summary><br />
/// Field that needs to be implemented
by the<br />
/// implementing the classes<br />
///
</summary><br />
bool IsEncrypted { get; set; }
<br />
/// <summary><br />
/// Tells if the message is
encrypted<br />
/// </summary><br />
///
<returns></returns><br />
bool IsMessageEncrypted();
<br />
/// <summary><br />
/// Tells if the priority is
set<br />
/// </summary><br />
///
<returns></returns><br />
bool IsMessagePrioritySet();
<br />
/// <summary><br />
/// Message Id of the
message<br />
/// </summary><br />
string MessageId {get;}
<br />
/// <summary><br />
/// Body of the message<br />
///
</summary><br />
string Body { get; }
<br />
/// <summary><br />
/// Header of the message<br />
/// </summary><br />
string Header { get; }
<br />
/// <summary><br />
/// Subject of the message<br />
/// </summary><br />
string Subject { get; }<br />
}<br />
}</td></tr>
</tbody></table>
<b><br /></b>
<b><br /></b>
<b>Message</b> <b>class</b>: This class implements the interface IMessage.
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">namespace PipesAndFiltersExample<br />
{<br />
/// <summary><br />
///
Message class<br />
/// </summary><br />
public class
Message:IMessage<br />
{<br />
/// <summary><br />
/// boolean
variables<br />
/// </summary><br />
private string
messageId;<br />
private string body;<br />
private string
header;<br />
private string subject;
<br />
/// <summary><br />
/// Properties to be set<br />
/// </summary><br />
public int Priority { get; set; }
<br />
public bool IsEncrypted { get; set; }
<br />
/// <summary><br />
/// Property that returns
MessageId<br />
/// </summary><br />
public string
MessageId<br />
{<br />
get { return messageId; }<br />
}
<br />
/// <summary><br />
/// Property that returns body of the
message<br />
/// </summary><br />
public string Body<br />
{<br />
get { return body; }<br />
}
<br />
/// <summary><br />
/// Property that returns the header
of the message<br />
/// </summary><br />
public string
Header<br />
{<br />
get { return header; }<br />
}
<br />
/// <summary><br />
/// Property that returns subject of
the message<br />
/// </summary><br />
public string
Subject<br />
{<br />
get { return subject; }<br />
}
<br />
/// <summary><br />
/// Constructor for the class
Message<br />
/// </summary><br />
/// <param
name="messageId">The MessageId</param><br />
/// <param
name="body">The Body</param><br />
/// <param
name="header">The Header</param><br />
/// <param
name="subject">The Subject</param><br />
public Message(string
messageId, string body, string header, string subject)<br />
{<br />
this.messageId = messageId;<br />
this.body =
body;<br />
this.header = header;<br />
this.subject =
subject;<br />
}
<br />
/// <summary><br />
/// Informs if the message is
encrypted<br />
/// </summary><br />
/// <returns>The
value true/false</returns><br />
public bool
IsMessageEncrypted()<br />
{<br />
return IsEncrypted;<br />
}
<br />
/// <summary><br />
/// Informs if the message priority
set<br />
/// </summary><br />
/// <returns>The value
true/falses</returns><br />
public bool
IsMessagePrioritySet()<br />
{<br />
return (Priority !=
0);<br />
}
<br />
}<br />
}</td></tr>
</tbody></table>
<b><br /></b>
<b><br /></b>
<b>Pipelinebase abstract class</b>: This class has two methods
<b>Register</b> and <b>PerformOperation</b>. Register method takes an
<b>IOperation<T></b> as an input and adds it to the list type operations
in the class. So, based on the choice of the clients, all the required
operations will be added to the list through Register method and then
<b>PerformOperation</b> method loops through all the operations and executes the
method “<b>Execute</b>” of the each operation. Each operation takes an input
message and performs the operation and then the resultant message will be sent
to another operation and likewise till all the operations are completed.
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">using System.Collections.Generic;<br />
using System.Linq;<br />
namespace
PipesAndFiltersExample<br />
{<br />
/// <summary><br />
/// Base class for
the pipeline classes<br />
/// </summary><br />
/// <typeparam
name="T">Type supported by the Pipeline base</typeparam><br />
public
abstract class Pipelinebase<T><br />
{<br />
private readonly
List<IOperation<T>> operations = new
List<IOperation<T>>();
<br />
/// <summary><br />
/// Registers the operation<br />
/// </summary><br />
/// <param name="operation">The
operation</param><br />
/// <returns>The instance of the
class</returns><br />
public Pipelinebase<T>
Register(IOperation<T> operation)<br />
{<br />
this.operations.Add(operation);<br />
return this;<br />
}
<br />
/// <summary><br />
/// Perform the operation<br />
/// </summary><br />
/// <param name="input">The input
message</param><br />
/// <returns>The instance of the
class</returns><br />
public T PerformOperation(T input)<br />
{<br />
return this.operations.Aggregate(input, (current, operation)
=> operation.Execute(current));<br />
}<br />
}<br />
}</td></tr>
</tbody></table>
<b><br /></b>
<b><br /></b>
<b>SendPipeline</b> <b>class</b>: This class has a constructor that takes two
parameters bool setPriority, bool encryptMessage and registers the operation
classes based on the parameter values.
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">namespace PipesAndFiltersExample<br />
{<br />
/// <summary><br />
///
Pipeline that sends message to the destination by performing operations<br />
/// on the incoming message<br />
/// </summary><br />
public class
SendPipeline : Pipelinebase<IMessage><br />
{<br />
///
<summary><br />
/// Constructor for the class where the operations
are registered<br />
/// for the messages<br />
///
</summary><br />
/// <param name="setPriority">The Set Priority
parameter</param><br />
/// <param name="encryptMessage">The
Encrypt Message parameter</param><br />
public SendPipeline(bool
setPriority, bool encryptMessage)<br />
{<br />
if
(setPriority)<br />
{<br />
Register(new
MessagePriority());<br />
}
<br />
if (encryptMessage)<br />
{<br />
Register(new EncryptMessage());<br />
}<br />
}<br />
}<br />
}
</td></tr>
</tbody></table>
<br />
Created two console applications to demonstrate the two clients. One client
wants to encrypt and set the message priority and the other just wants the
message priority to be set.
<br />
<br />
Client 1 program:
<br />
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">using PipesAndFiltersExample;<br />
using System;
<br />
namespace Client1<br />
{<br />
class Program<br />
{<br />
static void
Main(string[] args)<br />
{<br />
IMessage message = new
Message(messageId:"1", <br />
body:"This is the message
body",<br />
header:"Header Information",<br />
subject:"Please set priority and encrypt the message");<br />
//sending
code to the pipeline and the message is encrypted and published into the
queue<br />
SendPipeline sendPipeline = new
SendPipeline(true,true);<br />
var publishedMessage =
sendPipeline.PerformOperation(message);<br />
Console.WriteLine("I am
client1 and my messages should be prioritized and encrypted!!!");<br />
Console.WriteLine("My message Priority Set? {0}",
publishedMessage.IsMessagePrioritySet());<br />
Console.WriteLine("My
message Encrypted? {0}", publishedMessage.IsMessageEncrypted());<br />
Console.WriteLine();<br />
Console.Read();<br />
}<br />
}<br />
}
</td></tr>
</tbody></table>
<br />
Client 2 program:
<br />
<br />
<table border="1" cellpadding="0" cellspacing="0" unselectable="on">
<tbody>
<tr>
<td valign="top" width="623">using PipesAndFiltersExample;<br />
using System;
<br />
namespace Client2<br />
{<br />
class Program<br />
{<br />
static void
Main(string[] args)<br />
{<br />
IMessage message = new
Message(messageId: "1",<br />
body: "This is the message
body",<br />
header: "Header Information",<br />
subject: "Please set priority and encrypt the message");<br />
//sending code to the pipeline and the message is encrypted and published into
the queue<br />
SendPipeline sendPipeline = new SendPipeline(true,
false);<br />
var publishedMessage =
sendPipeline.PerformOperation(message);<br />
Console.WriteLine("I am
client2 and my messages should only be prioritized and not
encrypted!!!");<br />
Console.WriteLine("My message Priority Set? {0}",
publishedMessage.IsMessagePrioritySet());<br />
Console.WriteLine("My
message Encrypted? {0}", publishedMessage.IsMessageEncrypted());<br />
Console.WriteLine();<br />
Console.Read();<br />
}<br />
}<br />
}</td></tr>
</tbody></table>
<br />
When you run the code, you should see the following:
<br />
<br />
Client 1 program:
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFSrSzJmdNbOZekRZ4noab7Yw2oXq6JDqjAFeuX0QQyOkc3mVclSfL2riCWZV4DgaAodIhO29R9huYzlu8dJiAMN-bvITePhG63RIIMKagj1s1ZgKPx7yiJZCzG6hQEDZQ1_9GzO32Mcc/s1600/Figure3.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="144" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFSrSzJmdNbOZekRZ4noab7Yw2oXq6JDqjAFeuX0QQyOkc3mVclSfL2riCWZV4DgaAodIhO29R9huYzlu8dJiAMN-bvITePhG63RIIMKagj1s1ZgKPx7yiJZCzG6hQEDZQ1_9GzO32Mcc/s640/Figure3.PNG" width="640" /></a></div>
Figure 3 – Client 1 Program output shows that the message is encrypted and
the priority is set<br />
<br />
Client 2 program:
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdTt9v6AzffxwUWC1vEE-ULu4bWd6BOQTHkDH-6kEi3idia7hyphenhyphenyrhVOmRkusR_K-W4e4lc6HYmWUOuC1REcdCGiipR_xJXIDx_XsB-7w0vooT6vftkf3mG_hP5RAeD1WykZRIMYoSyaIc/s1600/Figure4.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="134" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdTt9v6AzffxwUWC1vEE-ULu4bWd6BOQTHkDH-6kEi3idia7hyphenhyphenyrhVOmRkusR_K-W4e4lc6HYmWUOuC1REcdCGiipR_xJXIDx_XsB-7w0vooT6vftkf3mG_hP5RAeD1WykZRIMYoSyaIc/s640/Figure4.PNG" width="640" /></a></div>
Figure 4 – Client 2 Program output shows that the message priority is set but
not encrypted<br />
<br />
<br />
You can start two projects by right clicking the solution and select “Set
StartUp Projects…” and select “Start” for the two projects in the “Action”
column and you should be good to run two console applications at one shot as
below:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggNt5X0cuo828rDeS8u-MvNLbtsgIh8PoRzYdd3BGoRiaYpDEM4JEdhTU5WJH-GbFwjw_i-ysMuLd7b9ls9OmbZNrOColiQCpOMA1FroCDMmmlHvVzKHsgNgSLtsA34gdGbjcAoX2qiIw/s1600/Figure5.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="354" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggNt5X0cuo828rDeS8u-MvNLbtsgIh8PoRzYdd3BGoRiaYpDEM4JEdhTU5WJH-GbFwjw_i-ysMuLd7b9ls9OmbZNrOColiQCpOMA1FroCDMmmlHvVzKHsgNgSLtsA34gdGbjcAoX2qiIw/s640/Figure5.PNG" width="640" /></a></div>
Figure 5 – Starting two projects at one shotAkkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-22056902034805248482014-08-17T11:40:00.001-04:002014-08-17T22:26:28.234-04:00Asynchronous Programming in C# – Part 2: Tasks<br />
As discussed in the previous <a href="http://ilovemicrosoft.blogspot.com/2014/06/asynchronous-programming-in-c-part.html">article</a>, though Thread pool helps us up to certain extent of reusing and managing the threads, still it lacks the built in mechanism to know when the operation has finished and what did the thread return back.<br />
<br />
So to help programmers to concentrate on the job Microsoft has introduced <strong><em>Task</em></strong>, which is an object that represents some work that should be done. Also <strong><em>Task</em></strong> has the capability to let you know if the work is completed and if a operation returns a result, <strong><em>Task</em></strong> returns you a result.<br />
<br />
A Task Scheduler is responsible for starting the Task and managing it. By default the Task Scheduler uses threads from the thread pool to execute the Task.<br />
<br />
Basic usage of Task is to make your application being responsive all the time. We make the main thread or thread running the UI free from any background time consuming jobs by creating a Task which internally will be using another thread from the Thread pool to complete the operation. But, note that it helps only in making the application responsive or parallelize your work in order to use the multiple processors available in the computer but does not scale the application.<br />
<br />
Task is a part of System.Threading.Tasks name space and it has two forms. One which returns a parameter and another that returns nothing or void.<br />
<ul>
<li>Task<T> which returns a value </li>
<li>Task which does not return any value</li>
</ul>
You can create instances of Task object using a new Task(Action) or using Factory class that creates a instance of Task.<br />
<br />
Here is the program for a task (Developed using .NET 4.0) that shows <br />
1) Creation of Task objects<br />
2) Task that returns no value and a Task that returns a value:<br />
<br />
using System;<br />
using System.Threading;<br />
using System.Threading.Tasks; <br />
namespace TaskTest<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
Console.WriteLine("Main Thread {0}", Thread.CurrentThread.ManagedThreadId); <br />
//Create a task using new keyword<br />
Task t = new Task(() =><br />
{<br />
Console.WriteLine("Task created using instantiation of Task class and passing Action as a parameter");<br />
}); <br />
<blockquote>
t.Start();</blockquote>
//Create a task using Factory<br />
//Task.Factory gives access to Factory methods to create instances of Task and Task<T><br />
Task taskFactory = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("Task created using Task.Factory");<br />
}); <br />
Console.WriteLine("**********************TASK WITH NO RETURN VALUE***********************");<br />
Console.WriteLine("Before creating a new task that does not return a value");<br />
Task taskWithNoReturnValue = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("TASK WITH NO RETURN VALUE RUNNING ON THREAD {0}", Thread.CurrentThread.ManagedThreadId);<br />
});<br />
Console.WriteLine("After creating a task that does not return a value"); <br />
Console.WriteLine("**********************TASK WITH RETURN VALUE***********************");<br />
Console.WriteLine("Before creating a new task that returns a value");<br />
Task<int> taskWithReturnValue = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("TASK WITH NO RETURN VALUE RUNNING ON THREAD {0}", Thread.CurrentThread.ManagedThreadId);<br />
return 6;<br />
});<br />
//Console.WriteLine("The return value from the task is {0}", taskWithReturnValue.Result);<br />
Console.WriteLine("After creating a task that returns a value"); <br />
Console.Read();<br />
} <br />
}<br />
} <br />
Output:<br />
<a href="http://lh6.ggpht.com/-25VIAAsj6B0/U_DMxcXkK5I/AAAAAAAAD90/vkliZ2jfggc/s1600-h/image9.png"><img alt="image" border="0" src="http://lh4.ggpht.com/-mXLR2sdNj54/U_DMx1egPkI/AAAAAAAAD94/2zIjA28Yxj4/image_thumb5.png?imgmax=800" height="159" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="584" /></a> <br />
<strong><em><br /></em></strong>
<strong><em>new Task(Action action) / Task.Factory.StartNew(Action action) </em></strong>queues the specified work to run on the thread pool and returns a task handle for that work.<br />
<br />
Observe from the output of the program that Main Thread Id is 10 and the tasks are running on 12 and 14. Also notice that the messages “Before…” and “after..” are printed first than the operation performed by the Task. This tells that UI thread or Main thread is running in parallel to the Tasks. Also notice that we are not reading the Task return value in the program. We cannot control the flow of Tasks execution as they each run in a parallel mode on a new thread.<br />
<br />
Let us see what happens if we read the value 6 from the Task. Uncomment the commented line that reads and displays the Task’s return value. You can get the result of the Task by property “Result”. Check the output now:<br />
<br />
<a href="http://lh6.ggpht.com/-jhy5Dg7ZpwE/U_DMyvJrubI/AAAAAAAAD-A/VD-9wfC6qGY/s1600-h/image15.png"><img alt="image" border="0" src="http://lh5.ggpht.com/-gvzPBmbzT8Y/U_DMzITw42I/AAAAAAAAD-I/Z2PfvRu4vhY/image_thumb9.png?imgmax=800" height="161" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="511" /></a> <br />
<br />
The main thread has to wait till the Task’s operation is completed and so you find that first, Task return value is displayed and after that “After..” message is displayed. If the Task is not finished, this call will block the current thread. <br />
<br />
So, Task.Result will block the thread that is trying to read the result to wait until the task completes its operation and then the next line of code execution takes place.<br />
There is one more method that makes the current thread to wait and this is similar to Thread.Join(). The method is Task.Wait().<br />
<br />
Continuation operation to the Task’s operation:<br />
System.Threading.Tasks class has another method called <strong><em>ContinueWith </em></strong>which creates a continuation task that runs another operation to execute as soon as the Task finishes. There are couple of overloads available for the ContinueWith method that you can configure when the continuation operation will run. It works both with the Task and Task<T> in which the prior case it takes Action as a parameter and in the later case the method accepts Func<<Task<T>,T> as a parameter. For example, in the above program if you want to continue with another operation once the Task<int> is finished, you can add the continuation task as below:<br />
<br />
Task<int> taskWithReturnValue = Task.Factory.StartNew(() =><br />
{<br />
Console.WriteLine("TASK WITH NO RETURN VALUE RUNNING ON THREAD {0}", Thread.CurrentThread.ManagedThreadId);<br />
return 6;<br />
}).ContinueWith((i) => {return i.Result*5;}); <br />
<br />
In this case, once the Task<int> completes the operation, then it continues with another operation that takes the result of Task<int> and multiplies the result with 5. So, the return value will be 30 instead of 6 as in the above program. Here is the output:<br />
<br />
<a href="http://lh4.ggpht.com/-XfqzIDPMDyU/U_DMzUjaHtI/AAAAAAAAD-Q/5BYKfujnLsU/s1600-h/image20.png"><img alt="image" border="0" src="http://lh5.ggpht.com/-UPkv3ETBrTY/U_DMz3Gd-2I/AAAAAAAAD-Y/joV6h9ypI50/image_thumb12.png?imgmax=800" height="152" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="520" /></a> <br />
<br />
You can use the continuation method for different scenarios like:<br />
<ul>
<li>When the Task is cancelled, if a certain operation is to be performed. </li>
<li>If you want to perform some operation if a Task is faulted. </li>
<li>If you want to perform some operation if a Task is finished its operation.</li>
</ul>
Here is a sample program to demonstrate the continuation operations:<br /><br />
static void Main(string[] args)<br /> {<br /> Task<string> task = Task.Factory.StartNew(() =><br /> {<br /> return "Hello EveryOne"; <br /> }); <br /> task.ContinueWith((s) =><br /> {<br /> Console.WriteLine(" I am completed!!!");<br /> },TaskContinuationOptions.OnlyOnRanToCompletion); <br /> task.ContinueWith((s) =><br /> {<br /> Console.WriteLine(" I am cancelled!!!");<br /> }, TaskContinuationOptions.OnlyOnCanceled); <br /> task.ContinueWith((s) =><br /> {<br /> Console.WriteLine(" I am faulted!!!");<br /> }, TaskContinuationOptions.OnlyOnFaulted); <br /> Console.WriteLine(task.Result); <br /> Console.Read();<br /> } <br /><br />
Output: <br /><br />
<a href="http://lh4.ggpht.com/-hGc4iE4IOrE/U_DM0zBs-1I/AAAAAAAAD-g/7OYVg8-Zv_k/s1600-h/image23.png"><img alt="image" border="0" src="http://lh4.ggpht.com/-1IRqxPdytgw/U_DM1RRmIII/AAAAAAAAD-o/Ta39DF85C40/image_thumb14%25255B1%25255D.png?imgmax=800" height="55" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="193" /></a> <br /><br />
Since in the program, the Task successfully completed its operation, only continuation option when Task is completed is executed. Had the Task got cancelled or faulted then the other operations would have been displayed.<br /><br />
The option OnlyOnFaulted executes only if the antecedent throws an unhandled exception. Change the above program code as below:<br /><br />
class Program<br /> { <br /> static void Main(string[] args)<br /> {<br /> <strong>Task<string> task = Task.Factory.StartNew(() =><br /> {<br /> throw new AggregateException("This task cannot execute!!!");<br /> return "Hello EveryOne"; </strong><br /><strong> }); </strong><br /> task.ContinueWith((s) =><br /> {<br /> Console.WriteLine(" I am completed!!!");<br /> },TaskContinuationOptions.OnlyOnRanToCompletion); <br /> task.ContinueWith((s) =><br /> {<br /> Console.WriteLine(" I am cancelled!!!");<br /> }, TaskContinuationOptions.OnlyOnCanceled); <br /> task.ContinueWith((s) =><br /> {<br /> Console.WriteLine(" I am faulted!!!");<br /> }, TaskContinuationOptions.OnlyOnFaulted); <br /> <strong>//Console.WriteLine(task.Result); </strong><br /> Console.Read();<br /> } <br /><br />
Note that I have commented out the line to display the result as it goes to exception and you cannot display the result. Also observe that in this program antecedent is the task created in the below line: <br /><strong><br /></strong><br />
<strong>Task<string> task = Task.Factory.StartNew(() =><br /> {<br /> throw new AggregateException("This task cannot execute!!!");<br /> return "Hello EveryOne"; </strong><br /><strong> }); </strong><br /><br />
With ContinueWith is going to take the result of task and then creates a new Task to perform another operation. If an exception occurs in task operation, then it will propagated to the ContinueWith task’s operation and displays the message “I am faulted”.<br /><br />
task.ContinueWith((s) =><br /> task.ContinueWith((s) =><br /> {<br /> Console.WriteLine(" I am faulted!!!");<br /> }, TaskContinuationOptions.OnlyOnFaulted); Output: <br /><a href="http://lh5.ggpht.com/-gmcP5i0UNcA/U_DM2evDhDI/AAAAAAAAD-0/olPGiSGU7hI/s1600-h/image31.png"><img alt="image" border="0" src="http://lh4.ggpht.com/-6g1aiq129AE/U_DM3V9KSYI/AAAAAAAAD-8/SyYmNVNOu7A/image_thumb18.png?imgmax=800" height="111" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="478" /></a> <br /><br />
Press continue and you will see the message below: <br /><a href="http://lh5.ggpht.com/-ZhfDTrD4its/U_DM3oS6R7I/AAAAAAAAD_A/fz7VL9SFUnA/s1600-h/image32%25255B1%25255D.png"><img alt="image" border="0" src="http://lh6.ggpht.com/-wTTb5wDAPTU/U_DM4aN4UmI/AAAAAAAAD_I/lC0pWW8bEd8/image_thumb19.png?imgmax=800" height="67" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="196" /></a> <br /><br />
Task Cancellation: <br /><br />
Here is a simple program to demonstrate the task cancellation: <br /><br />
class Program<br /> {<br /> /// <summary><br /> /// Method that runs time consuming task.<br /> /// This method accepts CancellationToken as a parameter.<br /> /// This program loops through 1 to 2000 and before the count reaches 2000<br /> /// if user hits any of the key then the tokensource is set to cancel and the token<br /> /// gets the cancellation request and the loop will get break and control returns to the<br /> /// Main program.<br /> /// </summary><br /> /// <param name="ct"></param><br /> static void RunTimeConsumingTask(CancellationToken ct)<br /> {<br /> if (ct.IsCancellationRequested)<br /> {<br /> Console.WriteLine("Cancellation request is sent and the operation is still in the execution");<br /> return;<br /> } <br /> for (int i=1;i<=2000;i++)<br /> {<br /> Console.WriteLine("Operation code {0} is completed", i);<br /> Thread.Sleep(1000); <br /> if (ct.IsCancellationRequested)<br /> {<br /> Console.WriteLine("Cancelled before completing operation code 2000");<br /> break;<br /> }<br /> } <br /> } <br /> static void Main(string[] args)<br /> {<br /> var tokenSource = new CancellationTokenSource();<br /> var token = tokenSource.Token;<br /> Console.WriteLine("Press enter or any key to cancel");<br /> Task<string> task = Task.Factory.StartNew(() =><br /> {<br /> RunTimeConsumingTask(token);<br /> return "Hello EveryOne"; <br /> });<br /> Console.ReadLine();<br /> tokenSource.Cancel();<br /> task.Wait(); <br /> Console.Read();<br /> } <br />Output:<br /><a href="http://lh5.ggpht.com/-5tRPmnYIIos/U_DM4_mlv7I/AAAAAAAAD_U/1ST3KwKGdyw/s1600-h/image37.png"><img alt="image" border="0" src="http://lh5.ggpht.com/-0xknWm9B1Is/U_DM5iha6xI/AAAAAAAAD_Y/cYQH27sGvDI/image_thumb22.png?imgmax=800" height="109" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="394" /></a> <br /><br />
Here when the loop is reached to 4, if any key is hit then the task is cancelled.<br />
<br />
Another program to demonstrate the “TaskContinuation.OnlyOnCanceled”:<br />
<br />
In the below program task is the instance of Task class that always looks for the CancellationToken. The CancellationToken propagates the notification that operations should be cancelled. The CancellationTokenSource is used to signal that the Task should cancel itself.<br />
Another statement to note is below:<br />
token.ThrowIfCancellationRequested();<br />
<br />
This statement throws System.OperationCanceledException if token has cancellation requested and this lets the outside the Task code to let the program know that task is getting cancelled. The “ContinueWith” is added to display the message when task is cancelled by creating another task and adding TaskContinuation.OnlyOnCanceled.<br />
<br />
static void Main(string[] args)<br /> {<br /> var cancellationTokenSource = new CancellationTokenSource();<br /> CancellationToken token = cancellationTokenSource.Token; <br />
Task task = Task.Factory.StartNew(() =><br /> {<br /> while (!token.IsCancellationRequested)<br /> {<br /> Console.WriteLine("Executing tasks");<br /> Thread.Sleep(1000);<br /> }<br /> token.ThrowIfCancellationRequested();<br /> }, token).ContinueWith((t) =><br /> {<br /> Console.WriteLine("Task is cancelled");<br /> }, TaskContinuationOptions.OnlyOnCanceled); <br />
Console.WriteLine("Press any key to end the task");<br /> Console.ReadLine(); <br />
cancellationTokenSource.Cancel();<br /> task.Wait();<br /> Console.WriteLine("Press enter to end the application");<br /> Console.ReadLine();<br /> } <br />
Output:<br />
<a href="http://lh5.ggpht.com/-3ZXf2rhUPso/U_FjFB87KSI/AAAAAAAAEAs/yMf-7RQbivY/s1600-h/image%25255B5%25255D.png"><img alt="image" border="0" src="http://lh4.ggpht.com/-YA8AgNpW9y0/U_FjF4t3FDI/AAAAAAAAEA0/GZoi04Kcq18/image_thumb%25255B2%25255D.png?imgmax=800" height="150" style="border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline;" title="image" width="418" /></a> <br />
When enter key is pressed the task is cancelled and the message “Task is cancelled” is displayed.<br />
<br /><strong>Nested Tasks:</strong><br />One task can encapsulate another task or a number of tasks. Nested tasks does not necessarily ensure that outer task waits for the inner tasks to complete.<br />A simple program to demonstrate the nested tasks:<br />/// <summary><br /> /// Program to show dependencies between Parent<br /> /// and child tasks<br /> /// </summary><br /> /// <param name="args"></param><br /> static void Main(string[] args)<br /> {<br /> //parent task created with Task.Factory.StartNew<br /> //This task is the outer task which is going to encapsulate<br /> //inner tasks or child tasks<br /> var parent = Task.Factory.StartNew(() =><br /> {<br /> Console.WriteLine("Parent Task statement1"); <br /> //Create a TaskFactory. Once you create a TaskFactory instance, you can create as many tasks<br /> //as needed. <br /> TaskFactory tf = new TaskFactory(TaskCreationOptions.None, TaskContinuationOptions.ExecuteSynchronously); <br /> //Create Child1<br /> tf.StartNew(() =><br /> {<br /> Console.WriteLine("Child1 statement1");<br /> Thread.Sleep(5000);<br /> Console.WriteLine("Child1 statement2");<br /> }); <br /> //Create Child2<br /> tf.StartNew(() =><br /> {<br /> Console.WriteLine("Child2 statement1");<br /> Thread.Sleep(5000);<br /> Console.WriteLine("Child2 statement2");<br /> }); <br /> Console.WriteLine("Parent Task statement2");<br /> });<br /> //Here final task is going to wait for parent task <br /> var finalTask = parent.ContinueWith(parentTask =><br /> {<br /> Console.WriteLine("Final statement");<br /> });<br /> Console.ReadLine();<br /> } <br /><a href="http://lh6.ggpht.com/-iumU__1UkWs/U_DM6KS5XlI/AAAAAAAAD_g/SavJkHYDuhQ/s1600-h/image24.png"><img alt="image" border="0" src="http://lh4.ggpht.com/-p0Fmpyis4WY/U_DM6gE9oWI/AAAAAAAAD_o/xh1C1hqe9jw/image_thumb14.png?imgmax=800" height="116" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="211" /></a> <br /><br />
In this program, we have:<br />1. One task “parent” is encapsulating two child tasks.<br />2. Then created a task which is going to execute when the parent task is completed.<br />3. We cannot control the flow of execution here in the case of child tasks. In the output, you can find that parent task statements are executed first then child’s statements are executed. By the time another statement is executed, final task statement is displayed.<br /><br />
If you want parent to wait till the child tasks to complete, System.Threading provides enum <strong><em>TaskContinuationOptions</em></strong> with value “AttachedToParent”. This will bind the child tasks to the parent task which makes the parent task to wait till the child tasks are completed.<br /><br />
<a href="http://lh5.ggpht.com/-mtCmh3yhPrU/U_DM7AeIJ_I/AAAAAAAAD_w/BDwl786W0vU/s1600-h/image32.png"><img alt="image" border="0" src="http://lh5.ggpht.com/-x-x3941lEd0/U_DM72CdclI/AAAAAAAAD_4/Jjs1OPknenw/image_thumb20.png?imgmax=800" height="83" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="401" /></a> <br /><br />Now modify the statement in your program as below:<br /><br />
TaskFactory tf = new TaskFactory(<strong>TaskCreationOptions.AttachedToParent</strong>, TaskContinuationOptions.ExecuteSynchronously);<br /><br />
After this code change you will observe that parent task is going to wait for the child tasks to complete.<br />
<br />
Check the following output:<br /><a href="http://lh6.ggpht.com/-6Cq8vkCiuX0/U_DM8YN0j-I/AAAAAAAAEAE/kCjKW2s6uo0/s1600-h/image37%25255B1%25255D.png"><img alt="image" border="0" src="http://lh3.ggpht.com/-cb3snGtnW8Q/U_DM80K3vbI/AAAAAAAAEAM/qIpmrllSNFE/image_thumb23.png?imgmax=800" height="125" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="285" /></a> <br /><br />
Now you observe that final task waits till parent task is completed execution and parent task is going to wait till child tasks are completed.<br /><br />
Now if you see the output, you will get a question as I got when I learnt the basics “<em><strong>From the output it seems all the statements in the parent task are displayed first and then child task statements were displayed. Then how can you support your statement that parent task is going to wait for child tasks to complete?</strong></em>”<br /><br />
Here is my answer for the question:<br /><br />
Because the output displays statements with “Parent Task…” are displayed first and then followed by statements with “Child…” does not mean parent has completed the execution and is not waiting for the child to complete. Here is the confirmation with the change highlighted to support:<br /><br />
/// <summary><br /> /// Program to show dependencies between Parent<br /> /// and child tasks<br /> /// </summary><br /> /// <param name="args"></param><br /> static void Main(string[] args)<br /> {<br /> //parent task created with Task.Factory.StartNew<br /> //This task is the outer task which is going to encapsulate<br /> //inner tasks or child tasks<br /> var parent = Task.Factory.StartNew(() =><br /> {<br /> Console.WriteLine("Parent Task statement1"); <br /> //Create a TaskFactory. Once you create a TaskFactory instance, you can create as many tasks<br /> //as needed. <br /> TaskFactory tf = new TaskFactory(TaskCreationOptions.AttachedToParent, TaskContinuationOptions.ExecuteSynchronously); <br /> //Create Child1<br /> tf.StartNew(() =><br /> {<br /> Console.WriteLine("Child1 statement1");<br /> Thread.Sleep(5000);<br /> Console.WriteLine("Child1 statement2");<br /> }).ContinueWith((t) =><br /> {<br /> Console.WriteLine("Child1 task is completed");<br /> }<strong>, TaskContinuationOptions.OnlyOnRanToCompletion</strong>); <br /> //Create Child2<br /> tf.StartNew(() =><br /> {<br /> Console.WriteLine("Child2 statement1");<br /> Thread.Sleep(5000);<br /> Console.WriteLine("Child2 statement2");<br /> }).ContinueWith((t) =><br /> {<br /> Console.WriteLine("Child2 task is completed");<br /> }, <strong>TaskContinuationOptions.OnlyOnRanToCompletion</strong>); <br /> Console.WriteLine("Parent Task statement2");<br /> }).ContinueWith((t)=><br /> {<br /> Console.WriteLine("Parent task is completed");<br /> }, <strong>TaskContinuationOptions.OnlyOnRanToCompletion</strong>);<br /> //Here final task is going to wait for parent task <br /> var finalTask = parent.ContinueWith(parentTask =><br /> {<br /> Console.WriteLine("Final statement");<br /> });<br /> Console.ReadLine();<br /> } <br /><br />
Now we have added continue tasks once the task has completed the execution with “<strong>TaskContinuationOptions.OnlyOnRanToCompletion</strong>”. With this addition of confirmation statements, now check the output that confirms that parent task has completed only after child tasks are completed. <br /><a href="http://lh3.ggpht.com/-ry_YPIfLEA8/U_DM9tWkTcI/AAAAAAAAEAQ/AQeNnoOjiEE/s1600-h/image%25255B4%25255D.png"><img alt="image" border="0" src="http://lh3.ggpht.com/-VR0aPGk9jjU/U_DM-dJx4pI/AAAAAAAAEAc/5rwrQ7a79pk/image_thumb%25255B2%25255D.png?imgmax=800" height="179" style="border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline;" title="image" width="306" /></a> <br /><br />
Additional methods: <br />- <strong><em>WaitAll()</em></strong> method can be used to wait for all multiple tasks to finish before continuation. <br />- <strong><em>WhenAll()</em></strong> method can be used to schedule a continuation method after all Tasks have completed. <br />- <strong><em>WaitAny()</em> </strong>method can be used to wait until one of the Tasks is finished. <br /><br />
Hope you like this article. The programs are coded in C# 4.0. In the next article I will touch the same programs rewritten in C# 5.0 and then we will discuss the new features added in C# 5.0.<br />
<div class="blogger-post-footer">
<br /></div>
<br />
<br />
<br />
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-84690731989728448832014-06-29T22:53:00.001-04:002014-08-17T22:28:31.432-04:00Asynchronous Programming in C# – Part 1:Basics of Thread programming<br>In these series of articles we are going to discuss on the following items:<br> <ul> <li>Single Thread programming <li>Multi-Threading programming <li>Synchronous Programming <li>Asynchronous Programming <li>Advantages/Disadvantages of writing programming using Thread class <li>Advantages/Disadvantages of using Task Parallel Library classes <li>Deep dive into Asynchronous Programming using <em>async</em> and <em>await</em> modifiers</li></ul> <p>This article uses Visual Studio 2013 and .NET 4.5 version and C# programming language in order to explain the concepts. If you have .NET 3.5, you can still use the examples illustrated with System.Threading classes. If you have .NET 4 version, you should be good in using the examples illustrated with System.Threading classes and System.Threading.Tasks classes. If you have latest version of .NET (.NET 4.5+), you can also follow async and await modifiers examples illustrated in addition to the Threading and Tasks classes.<br><br><b>Convention followed in these articles: </b>Since I am going to use mostly console applications to demonstrate the concepts, I would refer the "<b>Foreground thread</b>" as <b>"Main Thread" </b>for convenience as it will be running in the main method of the program.</p> <p> </p> <h2><span style="font-size: medium">Windows OS and Threads:</span></h2>Threads are the basic unit to which an operating system allocates processor time, and more than one thread can be executing code inside that process. You can find more from the MSDN <a title="http://msdn.microsoft.com/en-us/library/aa720724(v=vs.71).aspx" href="http://msdn.microsoft.com/en-us/library/aa720724(v=vs.71).aspx">http://msdn.microsoft.com/en-us/library/aa720724(v=vs.71).aspx</a>.<br><br><em>System.Threading</em> is a low level API for starting, stopping and joining threads.<br><br>Windows allows each thread to execute for a certain period. After the period ends, the thread is paused and Windows switches to another thread. This is called <strong><em>Context Switching</em></strong>.<br><br>There are two types of threads: Foreground Threads or Main Thread or UI thread which keeps application alive and Background Threads or Worker Threads which processes background work or long-time consuming tasks and reports back to the Foreground Threads.<br> <p><br><br><u><span style="color: green">Single Thread Programming</span></u> - All the code in your program is going to be executed on a single thread also called as Main thread or UI thread in case of UI programming.</p> <p><a href="http://lh5.ggpht.com/-CF_6IaCQhPM/U7YwA6_37yI/AAAAAAAAD4k/Bn_ziEWvcKQ/s1600-h/image%25255B6%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; float: none; margin-left: auto; display: block; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://lh6.ggpht.com/-v1zMwC1sTBE/U7YwBRhmi8I/AAAAAAAAD4s/qgg9tja_FZs/image_thumb%25255B3%25255D.png?imgmax=800" width="449" height="395"></a></p> <ol> <li>When you run your application, Windows operating system creates a Thread and it is given control to execute the entry method “Main”. <li>All lines of code in the Main method gets executed on this thread. <li>If there are any method calls, then the control goes to the called method and the code in those methods are still executed on the same thread. In the picture above, the main thread is “Thread1” and the called methods are “Method1() and Method2()”. <li>Once the method execution is completed, then the control comes back to the Main method. <li>Once all the code is executed in the Main method, then Thread is no more used. <li>Then thread will be killed or destroyed by the operation system.</li></ol> <p>Here the all methods are executed on same thread and in sequential flow. </p> <p>If your code is supposed to be intended to run in sequential and there are no I/O tasks involved or any heavy computational tasks involved, then this approach works fine. If there are any time consuming tasks are to be executed, then it will block your application and leaves it in an unusable state.</p> <p>Simple program to demonstrate Single Threading:</p> <p>using System;<br>using System.Threading; <p>namespace ThreadingTest<br>{<br> class Program<br> {<br> /// <summary><br> /// Entry method<br> /// </summary><br> /// <param name="args">Arguments to the method</param><br> static void Main(string[] args)<br> {<br> Console.WriteLine("Main thread {0}", Thread.CurrentThread.ManagedThreadId);<br> ExecuteMethod1();<br> Console.WriteLine("Main Method logic-1 executing....");<br> ExecuteMethod2();<br> Console.WriteLine("Main Method logic-2 executing....");<br> Console.WriteLine("All code execution completed");<br> Console.ReadLine();<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod1()<br> { <p> Console.WriteLine("Method name: ExecuteMethod1 and executing on Thread: {0}", <br> Thread.CurrentThread.ManagedThreadId);<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod2()<br> { <p> Console.WriteLine("Method name: ExecuteMethod2 and executing on Thread: {0}",<br> Thread.CurrentThread.ManagedThreadId);<br> }<br> }<br>} <p>Output:</p> <p><a href="http://lh4.ggpht.com/-2bHERF35j3s/U7bCGKGJO9I/AAAAAAAAEBA/DLcztK-k9x0/s1600-h/image14%25255B1%25255D.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; float: none; margin-left: auto; border-left: 0px; display: block; margin-right: auto" border="0" alt="image" src="http://lh3.ggpht.com/-Ba3HzS0uam4/U7bCGj9WUpI/AAAAAAAAEBI/-1O9TnPtxyM/image14_thumb.png?imgmax=800" width="305" height="66"></a></p> <p>All code is executed on Thread 8. And also observe that all the lines of code are executed in a sequential order. <br><br><u><span style="color: green">Multi-Thread Programming</span></u> – Code in your program is distributed among multiple threads for execution. Here multiple thread may execute code in synchronous manner or asynchronous based on your programming model.</p> <p> </p> <p> <p align="center"><a href="http://lh4.ggpht.com/-2jIgN5-1OVM/U7Yw6DIZpNI/AAAAAAAAD6k/t1-yHJiw5Tw/s1600-h/image%25255B32%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://lh6.ggpht.com/-FATnrxx68rM/U7Yw7P4LNMI/AAAAAAAAD6s/lt_RiXWwl98/image_thumb%25255B23%25255D.png?imgmax=800" width="337" height="313"></a> </p> <ol> <li>Windows OS creates a Thread (Main thread) to execute the Main method. <li>Main thread executes the lines of code in the Main method. <li>Main method creates a new Thread to execute method Method1(). <li>Main thread then executes other lines of code in the Main method. <li>Main method creates another new Thread to execute method Method2(). <li>Main thread completes its execution and it does not wait for other two threads to complete their code execution.</li></ol> <p>Simple program to demonstrate Multi-threading:</p> <p>using System;<br>using System.Threading; <p>namespace ThreadingTest<br>{<br> class Program<br> {<br> /// <summary><br> /// Entry method<br> /// </summary><br> /// <param name="args">Arguments to the method</param><br> static void Main(string[] args)<br> {<br> Console.WriteLine("Main thread {0}", Thread.CurrentThread.ManagedThreadId); <p> //Create Thread to execute ExecuteMethod1<br> Thread thread1 = new Thread(ExecuteMethod1);<br> thread1.Start(); <p> Console.WriteLine("Main Method logic-1 executing...."); <p> //Create Thread to execute ExecuteMethod1<br> Thread thread2 = new Thread(ExecuteMethod2);<br> thread2.Start(); <p> Console.WriteLine("Main Method logic-2 executing....");<br> Console.WriteLine("All code execution completed");<br> Console.ReadLine();<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod1()<br> { <p> Console.WriteLine("Method name: ExecuteMethod1 and executing on Thread: {0}", <br> Thread.CurrentThread.ManagedThreadId);<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod2()<br> { <p> Console.WriteLine("Method name: ExecuteMethod2 and executing on Thread: {0}",<br> Thread.CurrentThread.ManagedThreadId);<br> }<br> }<br>} <p>Output:</p> <p><a href="http://lh3.ggpht.com/-j0qP622f8YI/U7bCHbrvEbI/AAAAAAAAEBQ/6PzbnkIkh7g/s1600-h/image18%25255B1%25255D.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; float: none; margin-left: auto; border-left: 0px; display: block; margin-right: auto" border="0" alt="image" src="http://lh4.ggpht.com/-2DCCFTDpI4Q/U7bCHx0y8dI/AAAAAAAAEBY/5hx-awVYNhA/image18_thumb.png?imgmax=800" width="331" height="81"></a></p> <p>Notice that Main method is running on Thread 8, ExecuteMethod1() is running on Thread 9 and ExecuteMethod2() is running on Thread 10. Also observe that Thread 8 is not waiting for Thread 9 and 10 to complete their execution. This is because, all these threads are running in independent fashion and there is no way to communicate for Thread 9 and 10 with Thread 8. This is one of the drawback if you are writing multi-threading code by directly creating Thread objects.<br><br><u><span style="color: green">Synchronous Programming</span></u> – All blocks of code are executed in sequential manner. If you have 4 blocks of code say A, B, C and D then the execution order will be A—>B—>C—>D to complete the execution. Imagine if multiple threads are given the job of executing each block then the other threads must wait for the current thread to complete its task. In this case, UI gets freeze as UI thread will be waiting for other threads to complete their tasks.<br></p> <p><a href="http://lh4.ggpht.com/-4EOISlPpiPU/U7ayjBxtz6I/AAAAAAAAD68/b5EdtuJCLWQ/s1600-h/image%25255B7%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; float: none; margin-left: auto; display: block; border-top-width: 0px; margin-right: auto" border="0" alt="image" src="http://lh4.ggpht.com/-eCuhc_mkzwo/U7ayjlYjFkI/AAAAAAAAD7E/WG6wrUI3KzQ/image_thumb%25255B4%25255D.png?imgmax=800" width="348" height="351"></a> </p> <ol> <li>Windows creates a Thread (Main Thread) to execute Main method. <li>Main thread executes the lines of code in the Main method. <li>Main method creates a new thread to execute Method1(). <li>Then Main thread is blocked to wait for the completion of execution of Method1(). <li>Control transfers to the next line of code in the Main method. <li>Main method again creates another thread to execute method Method2() and waits for the thread to complete its execution. <li>After the thread has completed its execution, then the control is transferred back to the next line of code and then Main thread completes execution.</li></ol> <p>Simple example to demonstrate the Multiple threads running in Synchronous manner:</p> <p>using System;<br>using System.Threading; <p>namespace ThreadingTest<br>{<br> class Program<br> {<br> /// <summary><br> /// Entry method<br> /// </summary><br> /// <param name="args">Arguments to the method</param><br> static void Main(string[] args)<br> {<br> Console.WriteLine("Main thread {0}", Thread.CurrentThread.ManagedThreadId); <p> //Create Thread to execute ExecuteMethod1<br> Thread thread1 = new Thread(ExecuteMethod1);<br> thread1.Start();<br> thread1.Join(); <p> Console.WriteLine("Main Method logic-1 executing...."); <p> //Create Thread to execute ExecuteMethod1<br> Thread thread2 = new Thread(ExecuteMethod2);<br> thread2.Start();<br> thread2.Join(); <p> Console.WriteLine("Main Method logic-2 executing....");<br> Console.WriteLine("All code execution completed");<br> Console.ReadLine();<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod1()<br> { <p> Console.WriteLine("Method name: ExecuteMethod1 and executing on Thread: {0}", <br> Thread.CurrentThread.ManagedThreadId);<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod2()<br> { <p> Console.WriteLine("Method name: ExecuteMethod2 and executing on Thread: {0}",<br> Thread.CurrentThread.ManagedThreadId);<br> }<br> }<br>} <p> </p> <p>Output:</p> <p><a href="http://lh5.ggpht.com/-NkNVv7lyttg/U7bCINkGAWI/AAAAAAAAEBg/wO7Nd-u5ijc/s1600-h/image23%25255B1%25255D.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; float: none; margin-left: auto; border-left: 0px; display: block; margin-right: auto" border="0" alt="image" src="http://lh5.ggpht.com/-KaKq9MY0C50/U7bCI_crsnI/AAAAAAAAEBo/Qr4ZclpgDLE/image23_thumb.png?imgmax=800" width="323" height="79"></a> </p> <p>Notice that Main method is running on thread 8. When the thread Thread 9 is created to execute the method ExecuteMethod1(), it blocked the Thread 8 to run and so first the ExecuteMethod1() code is executed. The the control is transferred to the next line of code in Main method. The Thread 10 is created to execute the method ExecuteMethod2() and the Thread 10 blocks the Thread 8. Once it is completed its execution, the the control goes to the next line of code. So, thread 8 has to wait for other threads to complete their execution so that all the code is executed in sequential order though the code is executed on multiple threads.</p> <p><br><u><span style="color: green">Asynchronous Programming</span></u> – Each block of code will be running in parallel and reports to the Main thread or UI thread once they have completed their execution. UI thread or Main thread do not need to wait for all the threads to complete execution. This is especially useful when user wants to perform some other action on UI while some tasks are running behind the scenes.<br></p> <p align="center"><a href="http://lh6.ggpht.com/-L0qj7-wNIxI/U7aykXPOkAI/AAAAAAAAD7M/inTx1u9EGm4/s1600-h/image%25255B13%25255D.png"><img title="image" style="border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; display: inline; border-top-width: 0px" border="0" alt="image" src="http://lh4.ggpht.com/-qYkSROrCpV4/U7ayk47GKtI/AAAAAAAAD7U/UOdmmfz2NU8/image_thumb%25255B8%25255D.png?imgmax=800" width="357" height="361"></a> </p> <ol> <li>Windows creates a thread (Main Thread) to execute Main method. <li>Main Thread executes the lines of code in the method Main(). <li>Main method creates a new Thread to execute Method1() and another one for executing method Method2(). <li>Main thread completes its code execution and then waits for the other two threads to complete their execution.<br></li></ol> <p></p> <p>Simple program to demonstrate the Asynchronous programming using multiple threads:</p> <p>using System;<br>using System.Threading; <p>namespace ThreadingTest<br>{<br> class Program<br> {<br> /// <summary><br> /// Entry method<br> /// </summary><br> /// <param name="args">Arguments to the method</param><br> static void Main(string[] args)<br> {<br> Console.WriteLine("Main thread {0}", Thread.CurrentThread.ManagedThreadId); <p> //Create Thread to execute ExecuteMethod1<br> Thread thread1 = new Thread(ExecuteMethod1);<br> thread1.Start(); <p> Console.WriteLine("Main Method logic-1 executing...."); <p> //Create Thread to execute ExecuteMethod1<br> Thread thread2 = new Thread(ExecuteMethod2);<br> thread2.Start(); <p> Console.WriteLine("Main Method logic-2 executing...."); <p> thread1.Join();<br> thread2.Join();<br> Console.WriteLine("All code execution completed");<br> Console.ReadLine();<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod1()<br> { <p> Console.WriteLine("Method name: ExecuteMethod1 and executing on Thread: {0}", <br> Thread.CurrentThread.ManagedThreadId);<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod2()<br> { <p> Console.WriteLine("Method name: ExecuteMethod2 and executing on Thread: {0}",<br> Thread.CurrentThread.ManagedThreadId);<br> }<br> }<br>} <p>Output:</p> <p><a href="http://lh3.ggpht.com/-n1BFN9Pitq0/U7bCJmJmsUI/AAAAAAAAEBw/61SMdFVl7cY/s1600-h/image28%25255B1%25255D.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; float: none; margin-left: auto; border-left: 0px; display: block; margin-right: auto" border="0" alt="image" src="http://lh5.ggpht.com/-LPbCRiDEROQ/U7bCKMUSrgI/AAAAAAAAEB4/AKH36AypZvg/image28_thumb.png?imgmax=800" width="353" height="69"></a> <br><strong></strong><br>In this program we have added Thread.Join() methods for both the threads 11 and 12 at the end of the Main method before the last Console.WriteLine() method is executed. These two methods blocks the main thread 10 to wait for the completion of their execution and then the control is returned back to the next line of code in Main method.</p> <p><br>So, we have discussed single thread and multiple thread programming. We often encounter situations where we need to run code in different threads in order to complete the tasks in parallel and still make UI available to do other things. Creating few threads programmatically is beneficial but if we create more number of threads it will be a costly affair.<br><br><br><span style="font-size: medium">Passing value from a thread to the executing method:</span></p> <p><br>If you want to pass a value to an executing method from a thread, you need to declare the parameter type as “<em>object</em>” in the method and pass the value as a parameter of the <em>start</em> method of the thread. And in the method you need to cast the object to the desired type while using it. In the following example we are passing the loop counter value as a parameter to the method ExecuteMethod() and casting the object to string type while appending in the message text.<br> </p> <p>using System;<br>using System.Threading; <p>namespace ThreadingTest<br>{<br> class Program<br> {<br> /// <summary><br> /// Entry method<br> /// </summary><br> /// <param name="args">Arguments to the method</param><br> static void Main(string[] args)<br> {<br> Console.WriteLine("Main thread {0}", Thread.CurrentThread.ManagedThreadId); <p> //Create Thread to execute ExecuteMethod and pass a value<br> Thread thread1 = new Thread(ExecuteMethod);<br> thread1.Start("I love Microsoft");<br> Console.WriteLine("All code execution completed");<br> Console.ReadLine();<br> } <p> /// <summary><br> /// Method to be executed <br> /// </summary><br> static void ExecuteMethod(object message)<br> { <p> Console.WriteLine("Method name: ExecuteMethod1 and executing on Thread: {0} \nand the message is '{1}'", <br> Thread.CurrentThread.ManagedThreadId,<br> message.ToString());<br> } <p> }<br>} <p><br>Output:</p> <p><a href="http://lh3.ggpht.com/-vbdXMWXFjwM/U7bDaXBLL6I/AAAAAAAAECA/Zi1kSau3IrI/s1600-h/image32%25255B1%25255D%25255B1%25255D.png"><img title="image" style="border-top: 0px; border-right: 0px; border-bottom: 0px; float: none; margin-left: auto; border-left: 0px; display: block; margin-right: auto" border="0" alt="image" src="http://lh5.ggpht.com/-4pwUDHT7Aow/U7bDbKsqkDI/AAAAAAAAECI/Utc2q2Bjc_I/image32%25255B1%25255D_thumb.png?imgmax=800" width="351" height="62"></a> </p> <h2><span style="font-size: medium"></span> </h2> <h2><span style="font-size: medium">Points to ponder:</span></h2> <div><span style="font-size: medium"><br></span></div>A thread is relatively a heavy weight thing. It at least takes some mega bytes of stack space by default. So imagine the cost if we create more number of threads. Definitely it is not advisable. So, create a Thread in your program only if it is necessary.<br><br>You can use Thread Pool class provided by .NET Framework to reuse the threads similar to the database connection pool works. So whenever you are using a thread for the execution of part of code, instead of getting the thread killed we can send it back to the pool so that it can be used again. But there is no mechanism where we can know when the operation is finished and what is the return value of the thread. You can achieve the mechanism by using BackgroundWorker class provided by System.ComponentModel where it has capabilities like to report back the progress of the work, completion of the work. But there is no direct way to do this using Thread class. <br><br>One more point to note is that if there are few set of operations that do not consume much time out of the whole operations, creation of Thread for executing those operations is a unnecessary burden to the operating system. All these light operations can be handled by a single thread. It is not advisable to programmatically handle these situations in the code through the creation of Threads. Microsoft has been continuously improving the built in classes for Asynchronous operations in each of the new version it is releasing. <br><br>In the next article we will discuss on <em>System.Threading.Tasks</em> provided in .NET version 4.0. It is a high level API for concurrent and asynchronous programming. <br><br> <div class="blogger-post-footer"></div> <div class="blogger-post-footer"> </div> Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-65334064511004507822014-03-25T23:42:00.001-04:002014-03-25T23:46:58.878-04:00Why is my code not covered by a Unit Test?In this article, I am going to speak about a simple method that is not covered in code coverage even though the method is called by the parent method. This surprises many programmers at first instance.<br />
<u><span style="color: #333333;">A brief history of “yield” keyword in C# language:</span></u><br />
As per MSDN, When you use the yield keyword in a statement, you indicate that the method, operator or get accessor in which it appears is an iterator. <br />“yield” returns one element at a time.<br />
<u><span style="color: #333333;">Iterator Pattern:</span></u><br />
Added advantage with the “yield” keyword in your code is making you follow a design pattern by implicit. Yes. By using “yield” keyword you are following Iterator Pattern.<br />
Iterator provides a way to access the elements inside an aggregate object.<br />
Now coming to the main topic of why my method is not covered by Unit Test method.<br />
To explain this I am going to create a class library and add two classes: Country.cs and Data.cs.<br />
The class library name is “DataRepository” and the intention of the library is provide the Country names with Ids. To perform that we need to define the type for “Country” and another type that provides the methods to return the Country names and Ids.<br />
Here is the type “Country”:<br />
<a href="http://lh5.ggpht.com/-sYVjcZ_L4Tw/UzJMkdqp96I/AAAAAAAADzM/udrQnoHay6U/s1600-h/image%25255B7%25255D.png"><img alt="image" border="0" src="http://lh3.ggpht.com/-8FUDInASK78/UzJMk7WNHVI/AAAAAAAADzU/OcFFYtSu2k8/image_thumb%25255B3%25255D.png?imgmax=800" height="479" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="463" /></a><br />
<br />
Here is the class for the provider methods: This class has a public method that is exposed to the clients and one private method that actually reads the data and returns the countries to the public method.<br />
<a href="http://lh5.ggpht.com/-S3bCZuz2a24/UzJMloF4zrI/AAAAAAAADzY/mJKjrvYzbtE/s1600-h/image%25255B14%25255D.png"><img alt="image" border="0" src="http://lh6.ggpht.com/-XxK-umWomCc/UzJMmOfP5UI/AAAAAAAADzg/0PK0HCvboh8/image_thumb%25255B8%25255D.png?imgmax=800" height="595" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="475" /></a><br />
Now, let us add a test project and a unit test for the “Data” class public method. The intention of the test method is make sure that the public method of the class “Data” does not return null. This is a simple test.<br />
<a href="http://lh4.ggpht.com/-24BjCOhn02A/UzJMmV18_KI/AAAAAAAADzo/BDLFISIns4w/s1600-h/image%25255B24%25255D.png"><img alt="image" border="0" src="http://lh3.ggpht.com/--ZICigBMTQQ/UzJMm-jRyhI/AAAAAAAADz0/CnmMzYWAzjY/image_thumb%25255B14%25255D.png?imgmax=800" height="343" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="482" /></a><br />
Now execute the unit test and make sure that test is passed and then observe the code coverage details. I am using DOTCOVER (trial version) for code coverage. If you observe the overall Code coverage is 33% and the method “GetCountriesCore” was not covered. Try to put a break point and debug the unit test method, but still debugger will not step into the method “GetCountriesCore”. <br />
<a href="http://lh6.ggpht.com/-vC_-3f7BgeE/UzJMoZLilkI/AAAAAAAAD0s/ZrQHgBi6ySo/s1600-h/image%25255B53%25255D.png"><img alt="image" border="0" src="http://lh6.ggpht.com/-m9S-3DwTFW8/UzJMo2LoM_I/AAAAAAAAD00/63b8Ws-dSbE/image_thumb%25255B37%25255D.png?imgmax=800" height="271" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="498" /></a><br />
Also because the type “Country” is called by the method “GetCountriesCore”, it is also not covered.<br />
Now back to the question “Why is my code is not covered even though it is invoked?”<br />
The answer lies in the implementation of the method. The method has “yield” keyword which makes the method to be an iterator and your enumerable method will only execute when you actually try to access the members. This is also called “<span style="color: #333333;">Deferred Execution</span>”. There is an interesting article in MSDN on the deferred execution: <a href="http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx" title="http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx">http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-execution.aspx</a><br />
So, now change the unit test method to iterate through the members of the returned type of the method as below:<br />
<a href="http://lh5.ggpht.com/-W92Yyh5ZZ68/UzJMpRRZYxI/AAAAAAAAD0I/gbOa92tvJgQ/s1600-h/image%25255B40%25255D.png"><img alt="image" border="0" src="http://lh6.ggpht.com/-zS8u2cW4zuA/UzJMp3M0q9I/AAAAAAAAD0U/FaQq-QNSvP8/image_thumb%25255B26%25255D.png?imgmax=800" height="276" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="468" /></a><br />
Now run the tests again and if we put a break point, you can step into the private method too. We should see all green now and coverage percentage should be 100%. Also if you observe, the code for class “Country” is now covered and overall coverage is good now.<br />
<a href="http://lh3.ggpht.com/-OSWDFNJSK84/UzJMqvyapTI/AAAAAAAAD08/KEtVhMm4RA4/s1600-h/image%25255B56%25255D.png"><img alt="image" border="0" src="http://lh5.ggpht.com/-QlGmBtMARCM/UzJMrhgcZlI/AAAAAAAAD1E/kdPmP51YI28/image_thumb%25255B40%25255D.png?imgmax=800" height="296" style="background-image: none; border-bottom: 0px; border-left: 0px; border-right: 0px; border-top: 0px; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="image" width="495" /></a><br />
Hope you find this article useful. Happy Coding!!!Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-89717860067051744902014-01-06T20:57:00.001-05:002014-01-06T22:16:19.980-05:00How to pass Professional Scrum Developer I?Professional Scrum Developer I (PSD I) exam is comprised of theory and concepts from SCRUM Development methodologies and so the prerequisite for this exam is that we need to have knowledge of SCRUM along with the development methodologies. This exam is not so easy as the PSM I and you need to have very good development experience.<br />
Here are the things to be taken care of while preparing the exam:<br />
1. Read SCRUM guide available in scrum.org<br />
2. You should understand the TFS if you are a Microsoft Developer and have knowledge about branching and merging in TFS. You should know when/how to merge and branch the source code.<br />
3. You should understand the Test Driven Development concepts and Acceptance Test Driven concepts. It is advisable to have practical knowledge on the same. In case if you have concepts try to implement a simple example to understand the concepts better.<br />
4. You should know the Build Server and how it works.<br />
5. Most of the times the questions are related to your development experience and often needs judgment in selection of answers.<br />
6. Also you should know about Code Coverage and Unit Testing. Also Code Analysis and Code Metrics. If you do not use these very often in your projects, it is advisable to check the same using Visual Studio.<br />
7. Finally take practice exam (Open Assessment) available in scrum.org. But do not assume you will get more questions from the same. Most of the questions are related to real time experience.<br />
If you are new to everything it is advisable to take a preparation session or course before attempting the exam.Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com1tag:blogger.com,1999:blog-6469178881389701239.post-80158601845172758102013-12-25T18:45:00.002-05:002013-12-25T18:45:51.519-05:00How to pass "Professional Scrum Master I" in one shotI have completed Professional Scrum Master I this December and here is what my experience about the preparation for the exam:<br />
- Read the Scrum Guide from scrum.org. It is just 16 pages document that is available in multiple languages. Note that there is minor difference between Scrum Alliance and Scrum.org in some of the numbers. So, it is advised not to mix the both for your exam.<br />
- It is advised that working in a Scrum team gives more insight than just reading about the Scrum.<br />
- Once you feel comfortable about the Scrum literature, go for open assessments for PSM I in scrum.org.<br />
- If you get 100% pass marks every time you attempt the open assessment then you are halfway in the battle as you may get some of the questions from these assessments.<br />
- Even though the document does not speak about the Burn down chart you may get a question or two from that and so familiarize yourself with that.<br />
- Follow the forums in the scrum.org by registering yourself.<br />
<br />
If you are new to Scrum then it is better that you take a session on that. Otherwise, the training is not mandatory. Finally, get password and appear for the exam.<br />
<br />
<br />Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-62084220262204047482013-10-21T22:34:00.001-04:002013-10-21T22:34:49.762-04:00Use and Misuse of Design Patterns<p> </p> <p>In this article, Rockford Lhotka discusses about the use and misuse of Design Patterns. We often get enthused with the implementation of Design Patterns when we learn one. But, some of the technologists opine that using the design pattern without actual need indeed will result into negative consequences rather than positive consequences. Unless the positive consequences overweigh the negative consequences of using a particular pattern, do not use it. A simple programming construct is just enough. There is no hard-core rule that we need to implement Design Pattern in programming for sure.</p> <p>I liked this article by Rockford and hope you would like this too…</p> <p><a href="http://www.lhotka.net/weblog/OnTheUseAndMisuseOfPatterns.aspx">http://www.lhotka.net/weblog/OnTheUseAndMisuseOfPatterns.aspx</a></p> Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-39020682047950295622013-09-28T19:37:00.001-04:002013-09-28T19:37:14.383-04:00Remove a named instance in SQL Server 2008/2012<p>If you have two instances of SQL Server installed in your desktop and want to remove one of the instances then follow these steps:</p> <p>1. Go to “Control Panel” and select “Add/Remove Programs” or “Uninstall Programs”.</p> <p>2. Select “SQL Server Management Studio” in the installed products.</p> <p>3. Do not get scared when you click “Remove” button it will not install all the instances. When it asks for the instance name to select from the list of instances, select the instance to be deleted.</p> <p>4. Click “Next” till all the steps are completed.</p> Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-8524065967410197652013-08-12T15:08:00.001-04:002013-08-12T15:08:56.472-04:00The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.<p>I have installed Web Matrix on my Laptop and tried to run a sample code by creating a new site and a new folder and added a cshtml file in it. But when I tried to browse the file, I got the above error.</p> <p>This error went off when my root folder has a Default.cshtml file created.</p> Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-142124157917491412013-07-06T15:43:00.001-04:002013-07-06T15:45:19.175-04:00How to get installed programs in Windows 8I often do experiments on my laptop with different software installations that might create challenges which would need me to re-install my Windows 8 software back. When I install Windows 8 often I find myself lost with the option to view the installed programs. So, I am writing this article for people like me who often forget how they could view the installed programs in Windows 8. <strong>I normally create a new tool bar and provide the path “C:\ProgramData\Microsoft\Windows\Start Menu” and select “Programs” folder and this gives me list of programs installed in my computer</strong>.Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-58573865289484066682013-06-17T23:17:00.001-04:002013-06-18T20:38:06.251-04:00Asynchronous programming in ASP.NET 4.5Two days back I was going through the Scott Hanselman’s video on ASP.NET 4.5 and thought to share the same with everyone. The sample program taken here is from his video and I just modified some parts to demonstrate it in a better way. <br />
<br />
This example uses Visual studio 2012 and MVC 4 Web API and ASP.NET 4.5. Also in the example we are going to consume the Web API using WebClient class. WebClient class provides common methods for sending data and receiving data from a resource identified by URI. <br />
In ASP.NET 4.5 Microsoft has added more methods and properties that support consuming resources using both synchronous and asynchronous manner. You can go through the WebClient supported methods and properties in MSDN <a href="http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx">http://msdn.microsoft.com/en-us/library/system.net.webclient(v=vs.110).aspx</a>. <br />
<br />
I have created a MVC Web API project with 3 different controller classes Contacts, Temperature and Location which will be consumed by the client application (ASP.NET 4.5 Web application). To do that I have created a blank ASP.NET MVC 4 Web application as below: <br />
<br />
<a href="http://lh5.ggpht.com/-9WNkpCcTnGk/Ub_RLmhzdhI/AAAAAAAADq4/EsDr8Ks76sY/s1600-h/clip_image002%25255B3%25255D.jpg"><img alt="clip_image002" border="0" height="128" src="http://lh4.ggpht.com/-rl7xuPsUrHo/Ub_RMI0A4SI/AAAAAAAADq8/suqHYLsx8xY/clip_image002_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image002" width="244" /></a> <br />
Figure 1: Create a MVC 4 project with name “WebAPITest” <br />
<br />
<a href="http://lh3.ggpht.com/-ITItbnCIhqM/Ub_RMZ027jI/AAAAAAAADrE/W1UwMvs44rY/s1600-h/clip_image004%25255B3%25255D.jpg"><img alt="clip_image004" border="0" height="219" src="http://lh4.ggpht.com/-umd7uQauUSw/Ub_RMh-Kb8I/AAAAAAAADrQ/s0QKsXZ0WRY/clip_image004_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image004" width="244" /></a> <br />
Figure 2: Select Web API project <br />
<br />
<a href="http://lh3.ggpht.com/-Z15H2Xr0hvk/Ub_RNFtvn9I/AAAAAAAADrY/ie72_Y2lVxA/s1600-h/clip_image006%25255B3%25255D.jpg"><img alt="clip_image006" border="0" height="131" src="http://lh6.ggpht.com/-EHwye9TdLhc/Ub_RNVQNFdI/AAAAAAAADrg/0XDl0aeZOwk/clip_image006_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image006" width="244" /></a> <br />
Figure 3: Create new controller by right-clicking the “Controllers” folder <br />
<br />
<a href="http://lh4.ggpht.com/-gpD9fc96Vd8/Ub_RNhiaUSI/AAAAAAAADro/oEVG8qmMcSo/s1600-h/clip_image007%25255B3%25255D.png"><img alt="clip_image007" border="0" height="161" src="http://lh3.ggpht.com/-nutZBFz9ZKE/Ub_RN9y4-vI/AAAAAAAADrs/8GGAZB9asAY/clip_image007_thumb.png?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image007" width="244" /></a> <br />
Figure 4: Modifying the name of the Controller class and select the template as “Empty API Controller”. <br />
<br />
Follow the above steps in creating Controller classes for Contacts, Location and Temperature. You can search for creating Web API for more information in the C# corner site <a href="http://www.c-sharpcorner.com/">www.c-sharpcorner.com</a>. I would be just providing high level view on the Web API that will be used in this article. <br />
Here are my Controller classes created for the article: <br />
<br />
using System.Collections.Generic; <br />
using System.Web.Http; <br />
using WebAPITest.Models; <br />
namespace WebAPITest.Controllers <br />
{ <br />
public class ContactsController : ApiController <br />
{ <br />
Contact[] contacts = new Contact[] <br />
{ <br />
new Contact {Name="John", ContactNumber="444-978-0678"}, <br />
new Contact {Name="Mary", ContactNumber="424-968-8678"}, <br />
new Contact {Name="Raj", ContactNumber="449-968-9678"}, <br />
new Contact {Name="Ram", ContactNumber="440-938-8678"} <br />
}; <br />
public IEnumerable<Contact> GetAllContacts() <br />
{ <br />
System.Threading.Thread.Sleep(1000); <br />
return contacts; <br />
} <br />
} <br />
}<br />
<pre>using System.Web.Http;</pre>
<pre> </pre>
<pre>namespace WebAPITest.Controllers</pre>
<pre>{</pre>
<pre> public class LocationController : ApiController</pre>
<pre> {</pre>
<pre> public string GetCurrentLocation()</pre>
<pre> {</pre>
<pre> System.Threading.Thread.Sleep(1000);</pre>
<pre> return "San Jose, CA";</pre>
<pre> }</pre>
<pre> }</pre>
<pre>}</pre>
<pre>using System.Web.Http;</pre>
<pre> </pre>
<pre>namespace WebAPITest.Controllers</pre>
<pre>{</pre>
<pre> public class TemperatureController : ApiController</pre>
<pre> {</pre>
<pre> public string GetCurrentTemperature()</pre>
<pre> {</pre>
<pre> System.Threading.Thread.Sleep(1000);</pre>
<pre> return "54F";</pre>
<pre> }</pre>
<pre> }</pre>
<pre>}</pre>
<br />
Observe that I have intentionally added Thread.Sleep in all the methods so that the thread consuming the API has to wait for some time. This would help us to understand the asynchronous programming.<br />
Now you can test your web application by clicking CTRL+5 and you should see the home page immediately as below:<br />
<br />
<a href="http://lh6.ggpht.com/-aTd_Zo0CWKI/Ub_ROOnyWwI/AAAAAAAADr4/0RcrmrqFRLM/s1600-h/clip_image009%25255B3%25255D.jpg"><img alt="clip_image009" border="0" height="104" src="http://lh4.ggpht.com/-7LbJ1XxOIH8/Ub_ROryiotI/AAAAAAAADr8/j-Bnf1dsNrk/clip_image009_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image009" width="244" /></a><br />
Figure 5: Home page<br />
<br />
Now you can test your API by calling controller names as below:<br />
<br />
<a href="http://lh3.ggpht.com/-OHUHEyXGD5Y/Ub_ROwI8_ZI/AAAAAAAADsI/DlOMTF0PznQ/s1600-h/clip_image011%25255B3%25255D.jpg"><img alt="clip_image011" border="0" height="76" src="http://lh4.ggpht.com/-n9cL-EK21tw/Ub_RPBWsqRI/AAAAAAAADsQ/BlKgRgBu-f0/clip_image011_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image011" width="244" /></a><br />
Figure 6: Append “api/{Controller Name}” <br />
<br />
You should see at the bottom of the browser a popup that gets the response in JSON format:<br />
<br />
<a href="http://lh4.ggpht.com/-c3xX608J-84/Ub_RPX9LcMI/AAAAAAAADsU/0vvQqrwznb8/s1600-h/clip_image013%25255B3%25255D.jpg"><img alt="clip_image013" border="0" height="27" src="http://lh5.ggpht.com/-0l8I8NZafnA/Ub_RPkzTiEI/AAAAAAAADsg/0yc4yjTY6CA/clip_image013_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image013" width="244" /></a><br />
Figure 7: JSON response<br />
<br />
Click on open and you should see the response in JSON format and this confirms that your program is correct.<br />
<br />
<a href="http://lh3.ggpht.com/-GziBeO6exyY/Ub_RPyRgI9I/AAAAAAAADso/FkGZp6ogzCI/s1600-h/clip_image015%25255B3%25255D.jpg"><img alt="clip_image015" border="0" height="24" src="http://lh4.ggpht.com/-SAJuI9QyM78/Ub_RQYS7hMI/AAAAAAAADsw/xRbXAS-6W5I/clip_image015_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image015" width="244" /></a><br />
Figure 8: Opening response in notepad<br />
<br />
<pre>You will find that this has executed the method public IEnumerable<Contact> GetAllContacts()in the controller class and we got the List<Contacts> as a response in JSON format. </pre>
<br />
Similarly we can check for Location and Temperature APIs by appending api/Location, api/Temperature at the end of the home page URL. <br />
<br />
Now create one more project of type web application and consume the APIs using WebClient class as below:<br />
<br />
Default.aspx page:<br />
<br />
<pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Details.aspx.cs" Inherits="ClientApplication.Details" %></pre>
<pre> </pre>
<pre><!DOCTYPE html></pre>
<pre> </pre>
<pre><html xmlns="http://www.w3.org/1999/xhtml"></pre>
<pre><head runat="server"></pre>
<pre> <title></title></pre>
<pre></head></pre>
<pre><body></pre>
<pre> <form id="form1" runat="server"></pre>
<pre> <div></pre>
<pre> Contacts:<br /></pre>
<pre> <asp:ListView ID ="listContacts" runat="server"></pre>
<pre> <LayoutTemplate></pre>
<pre> <table runat="server" id="table1" ></pre>
<pre> <tr runat="server" id="itemPlaceholder" ></tr></pre>
<pre> </table></pre>
<pre> </LayoutTemplate></pre>
<pre> <ItemTemplate></pre>
<pre> <tr id="Tr1" runat="server"></pre>
<pre> <td id="Td1" runat="server"></pre>
<pre> <%-- Data-bound content. --%></pre>
<pre> <asp:Label ID="NameLabel" runat="server" </pre>
<pre> Text='<%#Eval("Name") %>' /></pre>
<pre> </td></pre>
<pre> </tr></pre>
<pre> </ItemTemplate></pre>
<pre> </pre>
<pre> </asp:ListView><br /></pre>
<pre> Temperature:<br /></pre>
<pre> <asp:Label ID ="lbltemperature" runat="server"></asp:Label><br /></pre>
<pre> Location:<br /></pre>
<pre> <asp:Label ID="lblLocation" runat="server"></asp:Label><br /></pre>
<pre> Elapsed Time:<br /></pre>
<pre> <asp:Label ID="lblElapsed" runat="server"></asp:Label><br /></pre>
<pre> </div></pre>
<pre> </form></pre>
<pre></body></pre>
<pre></html></pre>
<br />
Code behind:<br />
<pre>using System;</pre>
<pre>using System.Collections.Generic;</pre>
<pre>using System.Net;</pre>
<pre> </pre>
<pre>namespace ClientApplication</pre>
<pre>{</pre>
<pre> public class Contact</pre>
<pre> {</pre>
<pre> public string Name { get; set; }</pre>
<pre> public string ContactNumber { get; set; }</pre>
<pre> }</pre>
<pre> public partial class Details : System.Web.UI.Page</pre>
<pre> {</pre>
<pre> </pre>
<pre> protected void Page_Load(object sender, EventArgs e)</pre>
<pre> {</pre>
<pre> </pre>
<pre> string time = DateTime.Now.ToString();</pre>
<pre> </pre>
<pre> var clientcontacts = new WebClient().DownloadString("http://localhost:8687/api/Contacts");</pre>
<pre> var clientTemperature = new WebClient().DownloadString("http://localhost:8687/api/Temperature");</pre>
<pre> var clientLocation = new WebClient().DownloadString("http://localhost:8687/api/Location");</pre>
<pre> </pre>
<pre> </pre>
<pre> time = time + DateTime.Now.ToString();</pre>
<pre> </pre>
<pre> </pre>
<pre> var contacts = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Contact>>(clientcontacts);</pre>
<pre> var temperature = Newtonsoft.Json.JsonConvert.DeserializeObject(clientTemperature);</pre>
<pre> var location = Newtonsoft.Json.JsonConvert.DeserializeObject(clientLocation);</pre>
<pre> </pre>
<pre> listContacts.DataSource = contacts;</pre>
<pre> listContacts.DataBind();</pre>
<pre> </pre>
<pre> lblLocation.Text = location.ToString();</pre>
<pre> lbltemperature.Text = temperature.ToString();</pre>
<pre> lblElapsed.Text = time;</pre>
<pre> }</pre>
<pre> }</pre>
<pre>}</pre>
<br />
In this client web application program we are trying to consume the 3 APIs synchronously using WebClient instance. To get the time taken to complete the response for 3 API calls we have recorded the start and end time of the total request/response. Then we bind the response data to the controls in the ASPX page.<br />
<br />
Make sure that your Web API is running first and now start your web application and you should see the UI page as below.<br />
<br />
<a href="http://lh4.ggpht.com/-FeU7kzzyRDY/Ub_RQkFWh8I/AAAAAAAADs4/AUOKULxRo9M/s1600-h/clip_image017%25255B3%25255D.jpg"><img alt="clip_image017" border="0" height="132" src="http://lh4.ggpht.com/-Tfgi5MxX-_k/Ub_RQ-uB3hI/AAAAAAAADtA/63HaM1-4-d8/clip_image017_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image017" width="244" /></a><br />
Figure 9: Client UI page<br />
<br />
You observe that the request started at 6/17/2013 10:15:09 and ended at 10:51:12 PM. So overall time it took is 3 seconds to complete the request. In a real time projects we may need to call multiple services for performing certain business logic functionality and if the request is more I/O specific or database specific then it would be time consuming task for waiting till all the requests are completed in order.<br />
<br />
ASP.NET 4.5 came up with support for asynchronous execution of the same so that we can consume multiple resources at one time and thus saving the response time to the user.<br />
<br />
To do this we need to perform some changes to the client application:<br />
<pre>- Make your ASPX page to support Async operations by adding Async = “True”. </pre>
<pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Details.aspx.cs" Inherits="ClientApplication.Details" Async="true" %></pre>
<br />
- Now make your page_load method to behave Async by adding “async” to the method.<br />
<pre>protected async void Page_Load(object sender, EventArgs e)</pre>
<pre>- Now instead of getting response as a string using the WebClient method: new WebClient().DownloadString("http://localhost:8687/api/Contacts");</pre>
<br />
Modify it to behave asynchronously by modifying the method DownloadStringTaskAsync(string address). DownloadStringTaskAsync downloads the resource as a <a href="http://msdn.microsoft.com/en-us/library/system.string.aspx">String</a> from the URI specified as an asynchronous operation using a task object.<br />
<br />
<a href="http://lh3.ggpht.com/-LgMJ9VgZtUs/Ub_RRDZzWkI/AAAAAAAADtI/yNBm7_I-Yeo/s1600-h/clip_image019%25255B3%25255D.jpg"><img alt="clip_image019" border="0" height="42" src="http://lh6.ggpht.com/-ye9dmaZq0Uw/Ub_RRuU0zyI/AAAAAAAADtM/u68XK-Gi4Cw/clip_image019_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image019" width="244" /></a><br />
<pre> var clientcontacts = new WebClient().DownloadStringTaskAsync("http://localhost:8687/api/Contacts");</pre>
<pre> var clientTemperature = new WebClient().DownloadStringTaskAsync("http://localhost:8687/api/Temperature");</pre>
<pre> var clientLocation = new WebClient().DownloadStringTaskAsync("http://localhost:8687/api/Location");</pre>
<br />
- Next step is to add code to ask the program to wait till all the above tasks are completed. In .NET 4.5 there is a keyword introduced called “await” which instructs the executing thread to wait till some specific Task method is completed. Here is the total code:<br />
<br />
<pre>await Task.WhenAll(clientcontacts, clientTemperature, clientLocation);</pre>
<pre> </pre>
<pre>The purpose of the above code is to wait till all the tasks have been completed.</pre>
<pre><a href="http://lh6.ggpht.com/-aorn-2-ytIY/Ub_RRx7L4UI/AAAAAAAADtY/GkJDQOsjYcE/s1600-h/clip_image020%25255B3%25255D.png"><img alt="clip_image020" border="0" height="77" src="http://lh6.ggpht.com/-I7-Kk44T5pU/Ub_RSHV6VWI/AAAAAAAADtc/l6-2yEHSZFM/clip_image020_thumb.png?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image020" width="244" /></a></pre>
<pre> </pre>
<pre>You can go through MSDN to learn more about “Task” and the methods it supports.</pre>
<br />
- Immediately you would see red lines below the code for these 3 lines. This is because we are not executing the code synchronously and asking Task object to get back to us once the task is completed. So you cannot read the response directly instead you need now to specify .result to get the result of the task execution.<br />
<a href="http://lh4.ggpht.com/-euMZF0T00F4/Ub_RSYlHNtI/AAAAAAAADtk/zb6YSvnIxYk/s1600-h/clip_image022%25255B3%25255D.jpg"><img alt="clip_image022" border="0" height="27" src="http://lh6.ggpht.com/-fmLgvw66C3k/Ub_RSnFQJ8I/AAAAAAAADtw/N2SGX6sYtzA/clip_image022_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; margin: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image022" width="244" /></a><br />
Modify the above code to as below:<br />
<pre> var contacts = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Contact>>(clientcontacts.Result);</pre>
<pre> var temperature = Newtonsoft.Json.JsonConvert.DeserializeObject(clientTemperature.Result);</pre>
<pre> var location = Newtonsoft.Json.JsonConvert.DeserializeObject(clientLocation.Result);</pre>
<br />
Now we are done with the code changes for consuming the API asynchronously using the ASP.NET 4.5 feature. Now let us run the program again.<br />
<a href="http://lh5.ggpht.com/-J1pumwJ6id8/Ub_RSyY-8vI/AAAAAAAADt0/vAXi7nwoIjw/s1600-h/clip_image024%25255B3%25255D.jpg"><img alt="clip_image024" border="0" height="131" src="http://lh4.ggpht.com/-eKi-_dkBcS8/Ub_RTDUgQJI/AAAAAAAADt8/CC7Mdvbejm8/clip_image024_thumb.jpg?imgmax=800" style="background-image: none; border: 0px currentColor; display: inline; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="clip_image024" width="244" /></a><br />
Figure 10: Details page <br />
<br />
Now you can find that the total time taken is 1 second for all the requests as all the requests have been executed in asynchronous manner and the time taken is less compared to the synchronous way of consuming the Web API.<br />
<br />
Here is the total code for the client application:<br />
<br />
<pre><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Details.aspx.cs" Inherits="ClientApplication.Details" Async="true" %></pre>
<pre> </pre>
<pre><!DOCTYPE html></pre>
<pre> </pre>
<pre><html xmlns="http://www.w3.org/1999/xhtml"></pre>
<pre><head runat="server"></pre>
<pre> <title></title></pre>
<pre></head></pre>
<pre><body></pre>
<pre> <form id="form1" runat="server"></pre>
<pre> <div></pre>
<pre> Contacts:<br /></pre>
<pre> <asp:ListView ID ="listContacts" runat="server"></pre>
<pre> <LayoutTemplate></pre>
<pre> <table runat="server" id="table1" ></pre>
<pre> <tr runat="server" id="itemPlaceholder" ></tr></pre>
<pre> </table></pre>
<pre> </LayoutTemplate></pre>
<pre> <ItemTemplate></pre>
<pre> <tr id="Tr1" runat="server"></pre>
<pre> <td id="Td1" runat="server"></pre>
<pre> <%-- Data-bound content. --%></pre>
<pre> <asp:Label ID="NameLabel" runat="server" </pre>
<pre> Text='<%#Eval("Name") %>' /></pre>
<pre> </td></pre>
<pre> </tr></pre>
<pre> </ItemTemplate></pre>
<pre> </pre>
<pre> </asp:ListView><br /></pre>
<pre> Temperature:<br /></pre>
<pre> <asp:Label ID ="lbltemperature" runat="server"></asp:Label><br /></pre>
<pre> Location:<br /></pre>
<pre> <asp:Label ID="lblLocation" runat="server"></asp:Label><br /></pre>
<pre> Elapsed Time:<br /></pre>
<pre> <asp:Label ID="lblElapsed" runat="server"></asp:Label><br /></pre>
<pre> </div></pre>
<pre> </form></pre>
<pre></body></pre>
<pre></html></pre>
<pre>using System;</pre>
<pre>using System.Collections.Generic;</pre>
<pre>using System.Net;</pre>
<pre>using System.Threading.Tasks;</pre>
<pre> </pre>
<pre>namespace ClientApplication</pre>
<pre>{</pre>
<pre> public class Contact</pre>
<pre> {</pre>
<pre> public string Name { get; set; }</pre>
<pre> public string ContactNumber { get; set; }</pre>
<pre> }</pre>
<pre> public partial class Details : System.Web.UI.Page</pre>
<pre> {</pre>
<pre> </pre>
<pre> protected async void Page_Load(object sender, EventArgs e)</pre>
<pre> {</pre>
<pre> </pre>
<pre> string time = DateTime.Now.ToString();</pre>
<pre> </pre>
<pre> var clientcontacts = new WebClient().DownloadStringTaskAsync("http://localhost:8687/api/Contacts");</pre>
<pre> var clientTemperature = new WebClient().DownloadStringTaskAsync("http://localhost:8687/api/Temperature");</pre>
<pre> var clientLocation = new WebClient().DownloadStringTaskAsync("http://localhost:8687/api/Location");</pre>
<pre> </pre>
<pre> await Task.WhenAll(clientcontacts, clientTemperature, clientLocation);</pre>
<pre> </pre>
<pre> time = time + DateTime.Now.ToString();</pre>
<pre> </pre>
<pre> </pre>
<pre> var contacts = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Contact>>(clientcontacts.Result);</pre>
<pre> var temperature = Newtonsoft.Json.JsonConvert.DeserializeObject(clientTemperature.Result);</pre>
<pre> var location = Newtonsoft.Json.JsonConvert.DeserializeObject(clientLocation.Result);</pre>
<pre> </pre>
<pre> listContacts.DataSource = contacts;</pre>
<pre> listContacts.DataBind();</pre>
<pre> </pre>
<pre> lblLocation.Text = location.ToString();</pre>
<pre> lbltemperature.Text = temperature.ToString();</pre>
<pre> lblElapsed.Text = time;</pre>
<pre> }</pre>
<pre> }</pre>
<pre>}</pre>
<pre> </pre>
Hope you liked this article!!!Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-31588936608226328112013-06-16T14:51:00.001-04:002013-06-16T14:51:18.315-04:00Useful technical sites, podcast URLs<p><strong><font color="#ff0000">Sites:</font></strong></p> <p><a href="http://www.micrsoft.com/bizspark">www.micrsoft.com/bizspark</a> This is for startup companies from Microsoft…</p> <p><a href="http://www.teamsystemcafe.net">www.teamsystemcafe.net</a></p> <p><a href="http://www.hanselman.com/blog">www.hanselman.com/blog</a></p> <p><a href="http://www.channel9.msdn.com">www.channel9.msdn.com</a></p> <p><a href="http://www.blogs.msdn.com/bharry">www.blogs.msdn.com/bharry</a></p> <p><a href="http://www.communitymegaphone.com">www.communitymegaphone.com</a> – You can find the User groups, events in your local and neighborhood areas.</p> <p><strong><font color="#ff0000">Podcasts:</font></strong></p> <p><a href="http://www.deepfriedbytes.com">www.deepfriedbytes.com</a></p> <p><a href="http://www.benkotips.com">www.benkotips.com</a></p> <p><a href="http://www.ted.com">www.ted.com</a></p> <p><a href="http://www.dotnetrocks.com">www.dotnetrocks.com</a></p> <p><a href="http://www.jeffreyhunsaker.com">www.jeffreyhunsaker.com</a></p> Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-80327203813788990882013-06-09T21:30:00.001-04:002013-06-09T21:44:29.904-04:00Strongly Typed Data Controls in ASP.NET 4.5 with Visual Studio 2012<span style="font-family: Calibri;">Before the introduction of ASP.NET 4.5, we used to bind the
data to the ASP.NET controls using DataSource property and bind the data using
the <i style="mso-bidi-font-style: normal;">Eval(expression)</i> function. <i style="mso-bidi-font-style: normal;">Eval</i> evaluates the expression and
displays the data in the display controls. ASP.NET 4.5 came up with new feature
called strongly typed data controls. The benefit of this feature is we can bind
the data to the display controls with strong types and we can avoid the
exceptions caused by the function Eval(expression) if the expression is not
evaluated to a proper value.<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">This article discusses with the sample code on how the
databinding was programmed before ASP.NET 4.5 and in ASP.NET 4.5. This example
uses Visual Studio 2012 and the project type created is a simple web site
project (Empty web site project). Add a default.aspx webform with code behind
if you do not see it in the project.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Before ASP.NET 4.5:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">ASPX page:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">We used Eval(expression) for binding the data to the
individual controls in the list view control below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">p</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">u</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Normal ASP.NET Binding</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">u</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">p</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">asp</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">:</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ListView</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ID</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="displayData"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">LayoutTemplate</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">table</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">id</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="Table1"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">tr</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">id</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="Tr1"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">id</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="Td1"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item ID</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">id</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="Td2"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item Name</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">tr</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">tr</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">id</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="ItemPlaceholder"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">tr</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">table</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">LayoutTemplate</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ItemTemplate</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">tr</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">asp</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">:</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Label</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ID</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="Label1"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Text</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">='</span><span style="background: yellow; color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><%</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">#</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> Eval(</span><span style="color: #a31515; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">"ID"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">)<span style="background: yellow;">%></span></span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">'></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">asp</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">:</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Label</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">asp</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">:</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Label</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ID</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="Label2"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">runat</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">="server"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: red; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Text</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">='</span><span style="background: yellow; color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><%</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">#</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> Eval(</span><span style="color: #a31515; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">"ItemName"</span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">)<span style="background: yellow;">%></span></span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">'></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">asp</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">:</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Label</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">td</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">tr</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ItemTemplate</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><span style="mso-spacerun: yes;"> </span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="background: white; line-height: normal; margin: 0in 0in 0pt; tab-stops: 45.8pt 91.6pt 137.4pt 183.2pt 229.0pt 274.8pt 320.6pt 366.4pt 412.2pt 458.0pt 503.8pt 549.6pt 595.4pt 641.2pt 687.0pt 732.8pt;">
<span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"> </span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"></</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">asp</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">:</span><span style="color: maroon; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ListView</span><span style="color: blue; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">></span><span style="color: black; font-family: Consolas; font-size: 10pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Code behind for populating the data:<o:p></o:p></span></div>
<br />
<pre style="background: white;"><span style="font-family: "Calibri","sans-serif"; font-size: 11pt; mso-ascii-theme-font: minor-latin; mso-bidi-font-family: "Times New Roman"; mso-bidi-theme-font: minor-bidi; mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin;">Create a class file called “Product” in a separate file and it will be added in “App_code” folder in the project. This type will be used in the code behind for populating the data of the type “Product”.<o:p></o:p></span></pre>
<pre style="background: white;"><span style="color: blue; font-family: Consolas;"><o:p><span style="font-size: x-small;"> </span></o:p></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><o:p><span style="font-size: x-small;"> </span></o:p></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> Summary description for Product</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"></summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: blue; font-family: Consolas;">public</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">class</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;">{<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">public</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">int</span><span style="color: black; font-family: Consolas;"> ID { </span><span style="color: blue; font-family: Consolas;">get</span><span style="color: black; font-family: Consolas;">; </span><span style="color: blue; font-family: Consolas;">set</span><span style="color: black; font-family: Consolas;">; }<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">public</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">string</span><span style="color: black; font-family: Consolas;"> ItemName { </span><span style="color: blue; font-family: Consolas;">get</span><span style="color: black; font-family: Consolas;">; </span><span style="color: blue; font-family: Consolas;">set</span><span style="color: black; font-family: Consolas;">; }<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;">}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: blue; font-family: Consolas;"><o:p><span style="font-size: x-small;"> </span></o:p></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> Page Load Method</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"></summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><param name="sender"></param></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><param name="e"></param></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">protected</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">void</span><span style="color: black; font-family: Consolas;"> Page_Load(</span><span style="color: blue; font-family: Consolas;">object</span><span style="color: black; font-family: Consolas;"> sender, </span><span style="color: #2b91af; font-family: Consolas;">EventArgs</span><span style="color: black; font-family: Consolas;"> e)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> {<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: green; font-family: Consolas;">//bind the data to the list view by calling the method PopulateProducts.</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> displayData.DataSource = PopulateProducts();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> displayData.DataBind();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> }<o:p></o:p></span></span></pre>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> Method to create new product</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"></summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><returns></returns></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">public</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">IList</span><span style="color: black; font-family: Consolas;"><</span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;">> PopulateProducts()<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> {<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">return</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">new</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">List</span><span style="color: black; font-family: Consolas;"><</span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;">><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> {<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">new</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;">{ID=1,ItemName=</span><span style="color: #a31515; font-family: Consolas;">"Item1"</span><span style="color: black; font-family: Consolas;">},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">new</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;">{ID=2,ItemName=</span><span style="color: #a31515; font-family: Consolas;">"Item2"</span><span style="color: black; font-family: Consolas;">},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">new</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;">{ID=3,ItemName=</span><span style="color: #a31515; font-family: Consolas;">"Item3"</span><span style="color: black; font-family: Consolas;">},<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">new</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;">{ID=4,ItemName=</span><span style="color: #a31515; font-family: Consolas;">"Item4"</span><span style="color: black; font-family: Consolas;">}<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> };<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> }<o:p></o:p></span></span></pre>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><o:p><span style="font-family: Calibri;"> </span></o:p></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Code Execution: <o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Your output should like below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 8pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Normal ASP.NET Binding</span></u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<table border="0" cellpadding="0" class="MsoNormalTable" style="mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item ID<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item Name<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item1 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item2 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item3 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item4 <o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Re-writing the code
with ASP.NET 4.5:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In the ASP.NET 4.5 there is a new property available called
“ItemType” where you can define the type of the Item that is bound in the
control. Note, in some of the blogs/articles you see “ModelType” property
mentioned instead of “ItemType” as it was available in older versions.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now add the following code to ASPX page:<o:p></o:p></span></div>
<br />
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">br</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">/></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">p</span><span style="color: blue; font-family: Consolas;">><</span><span style="color: maroon; font-family: Consolas;">u</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;">ASP.NET 4.5 Strong Binding</span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">u</span><span style="color: blue; font-family: Consolas;">></</span><span style="color: maroon; font-family: Consolas;">p</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">ListView</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">ID</span><span style="color: blue; font-family: Consolas;">="displayData2"</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 12pt;"> </span></b><b style="mso-bidi-font-weight: normal;"><span style="color: red; font-family: Consolas; font-size: 12pt;">ItemType</span></b><b style="mso-bidi-font-weight: normal;"><span style="color: blue; font-family: Consolas; font-size: 12pt;">="Product"></span></b><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></b></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">LayoutTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">table</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Table1"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Tr1"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Td1"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;">Item ID</span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Td2"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;">Item Name</span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="ItemPlaceholder"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">table</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">LayoutTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">ItemTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">ID</span><span style="color: blue; font-family: Consolas;">="Label1"</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">Text</span><span style="color: blue; font-family: Consolas;">='</span><span style="background: yellow; color: black; font-family: Consolas;"><%</span><span style="color: blue; font-family: Consolas;">#</span><span style="color: black; font-family: Consolas;"> </span></span><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 11pt;">Item.ID</span></b><span style="font-size: x-small;"><span style="background: yellow; color: black; font-family: Consolas;">%></span><span style="color: blue; font-family: Consolas;">'></span><span style="color: black; font-family: Consolas;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white; margin-left: 137.4pt;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">ID</span><span style="color: blue; font-family: Consolas;">="Label2"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">Text</span><span style="color: blue; font-family: Consolas;">='</span><span style="background: yellow; color: black; font-family: Consolas;"><%</span><span style="color: blue; font-family: Consolas;">#</span><span style="color: black; font-family: Consolas;"> </span></span><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 11pt;">Item.ItemName</span></b><span style="font-size: x-small;"><span style="background: yellow; color: black; font-family: Consolas;">%></span><span style="color: blue; font-family: Consolas;">'></span><span style="color: black; font-family: Consolas;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">ItemTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">ListView</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In the above code you can observe that the control has a
property called “ItemType” which is assigned with the Type that we are going to
use to bind the data. In our case it is “Product”. Also, to access the
properties of the Type, you need to use “Item.” and the property name will be
automatically displayed by the Intellisense. This makes the programmer to bind
the strong types to the controls.<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwIe5rJ26NMKfYalavooPOwNFfHLz9Jd-33UqOnjT8McGb_HNZe9UfyAlY7Oy6QXWZX4I6Rdyrlgdr8TDDUngEF7sB6iAi5gLeFVDGGwUaxstrietGGNILvPhtq4bieYmECkNSOW4Tasg/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="80" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwIe5rJ26NMKfYalavooPOwNFfHLz9Jd-33UqOnjT8McGb_HNZe9UfyAlY7Oy6QXWZX4I6Rdyrlgdr8TDDUngEF7sB6iAi5gLeFVDGGwUaxstrietGGNILvPhtq4bieYmECkNSOW4Tasg/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1025" type="#_x0000_t75"
style='width:467.25pt;height:117pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Figure: Showing the properties of Type using the
Intellisense<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now modify the Page_Load method to bind the data to the
second control as below:<o:p></o:p></span></div>
<br />
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> Page Load Method</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"></summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><param name="sender"></param></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><param name="e"></param></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">protected</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">void</span><span style="color: black; font-family: Consolas;"> Page_Load(</span><span style="color: blue; font-family: Consolas;">object</span><span style="color: black; font-family: Consolas;"> sender, </span><span style="color: #2b91af; font-family: Consolas;">EventArgs</span><span style="color: black; font-family: Consolas;"> e)<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> {<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: green; font-family: Consolas;">//bind the data to the list view by calling the method PopulateProducts.</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> displayData.DataSource = PopulateProducts();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> displayData.DataBind();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas;"> </span></b><b style="mso-bidi-font-weight: normal;"><span style="color: green; font-family: Consolas;">//bind the data to the list view by calling the method PopulateProducts.</span></b><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas;"><o:p></o:p></span></b></span></pre>
<pre style="background: white;"><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> displayData2.DataSource = PopulateProducts();<o:p></o:p></span></span></b></pre>
<pre style="background: white;"><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> displayData2.DataBind();<o:p></o:p></span></span></b></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> }<o:p></o:p></span></span></pre>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Code Execution: <o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Your output should like below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 8pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ASP.NET 4.5 Strong Binding</span></u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<table border="0" cellpadding="0" class="MsoNormalTable" style="mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item ID<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item Name<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item1 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item2 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item3 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item4 <o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Select Method:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In the above code, we set the data to the controls using
DataSource property of the control. We can also bind the data using the Select
method of the ASP.NET control instead of setting the DataSource property. Let
us see how we can do that now.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Modify your ASPX file to include another control as below:<o:p></o:p></span></div>
<br />
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">br</span><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">/></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">p</span><span style="color: blue; font-family: Consolas;">><</span><span style="color: maroon; font-family: Consolas;">u</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;">ASP.NET 4.5 Strong Binding with Select Method</span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">u</span><span style="color: blue; font-family: Consolas;">></</span><span style="color: maroon; font-family: Consolas;">p</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">ListView</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">ID</span><span style="color: blue; font-family: Consolas;">="displayData3"</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">ItemType</span><span style="color: blue; font-family: Consolas;">="Product"</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 11pt;"> </span></b><b style="mso-bidi-font-weight: normal;"><span style="color: red; font-family: Consolas; font-size: 11pt;">SelectMethod</span></b><b style="mso-bidi-font-weight: normal;"><span style="color: blue; font-family: Consolas; font-size: 11pt;">="GetValidProducts"></span></b><b style="mso-bidi-font-weight: normal;"><span style="color: black; font-family: Consolas; font-size: 11pt;"><o:p></o:p></span></b></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">LayoutTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">table</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Table1"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Tr1"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Td1"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;">Item ID</span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="Td2"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;">Item Name</span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">id</span><span style="color: blue; font-family: Consolas;">="ItemPlaceholder"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">table</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">LayoutTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">ItemTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">ID</span><span style="color: blue; font-family: Consolas;">="Label1"</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">Text</span><span style="color: blue; font-family: Consolas;">='</span><span style="background: yellow; color: black; font-family: Consolas;"><%</span><span style="color: blue; font-family: Consolas;">#</span><span style="color: black; font-family: Consolas;"> Item.ID<span style="background: yellow;">%></span></span><span style="color: blue; font-family: Consolas;">'></span><span style="color: black; font-family: Consolas;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"><</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">ID</span><span style="color: blue; font-family: Consolas;">="Label2"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">runat</span><span style="color: blue; font-family: Consolas;">="server"</span><span style="color: black; font-family: Consolas;"> </span><span style="color: red; font-family: Consolas;">Text</span><span style="color: blue; font-family: Consolas;">='</span><span style="background: yellow; color: black; font-family: Consolas;"><%</span><span style="color: blue; font-family: Consolas;">#</span><span style="color: black; font-family: Consolas;"> Item.ItemName<span style="background: yellow;">%></span></span><span style="color: blue; font-family: Consolas;">'></span><span style="color: black; font-family: Consolas;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">Label</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">td</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">tr</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> <o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">ItemTemplate</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;"></</span><span style="color: maroon; font-family: Consolas;">asp</span><span style="color: blue; font-family: Consolas;">:</span><span style="color: maroon; font-family: Consolas;">ListView</span><span style="color: blue; font-family: Consolas;">></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Note in the above code we have set the value for
SelectMethod<span style="mso-spacerun: yes;"> </span>propery with a Code behind
method called “GetValidProducts”. The method “GetValidProducts” has
responsibility to get the data to be populated in the ListView control. The
method used here should either support IEnumerable or IQueryable type to be
able to populate the Type data.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now let us define a method in the code behind for the same:<o:p></o:p></span></div>
<br />
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> Method to get the products using IEnumerable</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"></summary></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;">///</span><span style="color: green; font-family: Consolas;"> </span><span style="color: grey; font-family: Consolas;"><returns></returns></span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">public</span><span style="color: black; font-family: Consolas;"> </span><span style="color: #2b91af; font-family: Consolas;">IEnumerable</span><span style="color: black; font-family: Consolas;"><</span><span style="color: #2b91af; font-family: Consolas;">Product</span><span style="color: black; font-family: Consolas;">> GetValidProducts()<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> {<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: green; font-family: Consolas;">//You can add additional criteria for displaying the products by</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: green; font-family: Consolas;">//modifying the code in this method</span><span style="color: black; font-family: Consolas;"><o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="font-size: x-small;"><span style="color: black; font-family: Consolas;"> </span><span style="color: blue; font-family: Consolas;">return</span><span style="color: black; font-family: Consolas;"> PopulateProducts().AsQueryable();<o:p></o:p></span></span></pre>
<pre style="background: white;"><span style="color: black; font-family: Consolas;"><span style="font-size: x-small;"> }<o:p></o:p></span></span></pre>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">As mentioned in the commented code, you can modify the
method to include the criteria to check some business logic and refine the data
to be returned by the method.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Code Execution:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now, if you execute the code you should see the data getting
populated as below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 8pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ASP.NET 4.5 Strong Binding with Select Method</span></u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<table border="0" cellpadding="0" class="MsoNormalTable" style="mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item ID<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item Name<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item1 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item2 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item3 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item4 <o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Note:<span style="mso-spacerun: yes;"> </span>Similar to
SelectMethod, you can also write methods for Update, Insert and Delete
operations.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Final output should look like below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 8pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Normal ASP.NET Binding</span></u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<table border="0" cellpadding="0" class="MsoNormalTable" style="mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item ID<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item Name<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item1 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item2 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item3 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item4 <o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><br style="mso-special-character: line-break;" />
<!--[if !supportLineBreakNewLine]--><br style="mso-special-character: line-break;" />
<!--[endif]--><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 8pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ASP.NET 4.5 Strong Binding</span></u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<table border="0" cellpadding="0" class="MsoNormalTable" style="mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item ID<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item Name<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item1 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item2 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item3 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item4 <o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><br style="mso-special-character: line-break;" />
<!--[if !supportLineBreakNewLine]--><br style="mso-special-character: line-break;" />
<!--[endif]--><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 8pt; mso-margin-bottom-alt: auto; mso-margin-top-alt: auto;">
<u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">ASP.NET 4.5 Strong Binding with Select Method</span></u><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><o:p></o:p></span></div>
<br />
<table border="0" cellpadding="0" class="MsoNormalTable" style="mso-cellspacing: 1.5pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item ID<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item Name<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item1 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item2 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item3 <o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4 <o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Item4 <o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:p><span style="font-family: Calibri;"> </span></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Hope you liked this article!!! Happy coding!!!<o:p></o:p></span></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-73563768258145500372013-05-12T00:01:00.004-04:002013-05-12T00:02:45.021-04:00Factory Design Pattern vs. Factory Method Design Pattern<br />
<div class="MsoNormal">
This article discusses straight to the point the difference
between Factory Design Pattern and Factory Method Pattern. We all have used
Factory Pattern in our projects and so the intention is not to explain the same
again but to clarify the basic difference between Factory Pattern and Factory
Method pattern which most of the people often gets confused.<o:p></o:p></div>
<div class="MsoNormal">
This pattern is a Creational Pattern i.e. this pattern
concentrates on creating instances of an object.<o:p></o:p></div>
<div class="MsoNormal">
In simple terms here is the gist of both the patterns:<o:p></o:p></div>
<div class="MsoNormal">
<b>Factory Pattern:<o:p></o:p></b></div>
<div class="MsoNormal">
<b>Client</b> uses <b>Factory Class</b> to get <b>instances</b> of classes that are
implementing the same interface or derived from same base class.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl6INrOJ53ID-Lt8zraJd1vgwnZm1OBKikcFGll2lAGY-Xm5lk_OIfYSsMlxYZ4ahEmo8Y24BApQA4n4uGtUnpOdrV_LGws_XIm2XniRPQirOzQFCjUiaMkkn2ov7E8SU9qe8z3vt_uP8/s1600/C-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="70" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhl6INrOJ53ID-Lt8zraJd1vgwnZm1OBKikcFGll2lAGY-Xm5lk_OIfYSsMlxYZ4ahEmo8Y24BApQA4n4uGtUnpOdrV_LGws_XIm2XniRPQirOzQFCjUiaMkkn2ov7E8SU9qe8z3vt_uP8/s320/C-2.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_2" o:spid="_x0000_i1030" type="#_x0000_t75"
style='width:467.25pt;height:102.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
<b>Factory Method
Pattern:<o:p></o:p></b></div>
<div class="MsoNormal">
<b>Client </b>maintains
reference to the <b>abstract creator class</b>
but instantiates with one of the sub classes. Responsibility of creating the instance is
delegated to the sub class methods. So the name Factory Method pattern.<b><!--[if gte vml 1]><v:shape
id="Picture_x0020_4" o:spid="_x0000_i1029" type="#_x0000_t75" style='width:467.25pt;
height:99.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggrUkZSOnqMzKBUKWoxAiLqWdcSak-LeJX1gRra6RzHbMq4sg_HzPjeTkMidaTRtqk_6pRnXkJKnLr7zuSvrkZ3fDKuD_CPsh1nOY4W5mhszxkLuwd_vZPlx0Ww_4u9fyYVXECvFh6Bbg/s1600/C-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="68" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggrUkZSOnqMzKBUKWoxAiLqWdcSak-LeJX1gRra6RzHbMq4sg_HzPjeTkMidaTRtqk_6pRnXkJKnLr7zuSvrkZ3fDKuD_CPsh1nOY4W5mhszxkLuwd_vZPlx0Ww_4u9fyYVXECvFh6Bbg/s320/C-3.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Client refers to the abstract creator class but uses one of
the sub classes to get the actual instance. In the above, abstract method M()
takes care of creating the actual instance and returning the referencing to the
client.<o:p></o:p></div>
<div class="MsoNormal">
Now let us check the program to understand the both.<o:p></o:p></div>
<div class="MsoNormal">
<b>Factory Design
Pattern:<o:p></o:p></b></div>
<div class="MsoNormal">
Class diagram for the example:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7nHPRrSPNxj1QW_U_0vJ3metaO7rAsySlPyf9Pd6IfL9IeJmkuWSAN4MGu6mWR8PZZXvyT4tz7554GvC9X1ALHnAFkaX-YOUROHHkCkEbPwOAZGZlM0ZRwKybpnTw9UJfoLmZN40J1jA/s1600/C-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="185" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7nHPRrSPNxj1QW_U_0vJ3metaO7rAsySlPyf9Pd6IfL9IeJmkuWSAN4MGu6mWR8PZZXvyT4tz7554GvC9X1ALHnAFkaX-YOUROHHkCkEbPwOAZGZlM0ZRwKybpnTw9UJfoLmZN40J1jA/s320/C-4.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_1" o:spid="_x0000_i1028" type="#_x0000_t75" style='width:468pt;
height:271.5pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
Figure 1: Factory Pattern Class diagram<o:p></o:p></div>
<div class="MsoNormal">
“MyFactory” is the static class that takes the
responsibility of creating actual instance of the concrete class and sends the
reference to the Client class. “Subject” is the abstract base class from which
the two classes “Physics” and “Mathematics” inherit. So, client uses the class “MyFactory”
to get the actual instances.<o:p></o:p></div>
<div class="MsoNormal">
Here is the code:<o:p></o:p></div>
<div class="MsoNormal">
This example uses the C# Console Application project to demonstrate
the Factory Pattern.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Base class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">abstract</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">abstract</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> SubjectName { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Class Physics inherit the class Subject and </span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> overrides the property SubjectName </span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Physics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">override</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> SubjectName<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">"Physics"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Class Mathematics inherit the class Subject and </span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> overrides the property SubjectName</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Mathematics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">override</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> SubjectName<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">"Mathematics"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Factory Class that takes the responsibility</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> of creating the instances.</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">static</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">MyFactory</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">static</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> GetName(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> id)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">if</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> (id == 0)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Mathematics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">else</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Physics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Program class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Program</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">static</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Main(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">[] args)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">//Call the factory class method to
get the instance</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> subject = </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">MyFactory</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.GetName(0);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">//display the instance's property
value</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(subject.SubjectName);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">//now invoke the other method by
passing another value</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> subject
= </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">MyFactory</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.GetName(1);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">//display the subject name property
value</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(subject.SubjectName);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.Read();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Here is the output:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh516Ic66OGF3LFrV_yPn3Iu6GG8R2GaCj_8-4OcGhfyPVbc3TBDnU3VR_VriO1B2J2K4JcJXj_SrgvkCuNUvf0dOyEZZyLLWbBi7bsWKM3a_4HNOjiMD-gLOebAeEtbknKlrKiQxWxUuM/s1600/C-5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="46" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh516Ic66OGF3LFrV_yPn3Iu6GG8R2GaCj_8-4OcGhfyPVbc3TBDnU3VR_VriO1B2J2K4JcJXj_SrgvkCuNUvf0dOyEZZyLLWbBi7bsWKM3a_4HNOjiMD-gLOebAeEtbknKlrKiQxWxUuM/s320/C-5.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_5" o:spid="_x0000_i1027" type="#_x0000_t75" style='width:468pt;
height:68.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
In this example, we saw how the Factory class takes care of
creating instances and how client program uses the Factory class to create the
instances.<o:p></o:p></div>
<div class="MsoNormal">
<b>Note:</b> Whenever
you have requirement to create instances of different <b>types</b> or <b>kinds</b> of
classes then we would be using Factory design pattern.<o:p></o:p></div>
<div class="MsoNormal">
Now we will take the same example above and see how we can
implement it in the Factory Method pattern.<o:p></o:p></div>
<div class="MsoNormal">
<b>Factory Method
Pattern:<o:p></o:p></b></div>
<div class="MsoNormal">
Class Diagram:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIYZdXd_ATW32TzCq1DkK4ihAUBTectLkIDB9HWGboSv2FrD_oo9Vx7P4qZbJPqg_e5aeYmI8p8ltqejckGLpTg1HF0b_zfFqgnBKUek6MDj1fWFzrgEUSgefQyIsQf_knI9LV0WZvp1c/s1600/C-6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIYZdXd_ATW32TzCq1DkK4ihAUBTectLkIDB9HWGboSv2FrD_oo9Vx7P4qZbJPqg_e5aeYmI8p8ltqejckGLpTg1HF0b_zfFqgnBKUek6MDj1fWFzrgEUSgefQyIsQf_knI9LV0WZvp1c/s320/C-6.png" width="282" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_6" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:392.25pt;
height:444.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image008.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
Figure 2: Factory Method Pattern<o:p></o:p></div>
<div class="MsoNormal">
In this example, instead of a Factory class to create the
instances the sub classes of the Factory class decides which instance of class
is to be created. The Factory class can now be called as Creator class and it
has one abstract method of return type of the concrete base class. All the sub
classes of this creator class are supposed to override the abstract method and returns
the instance of the concrete class.<o:p></o:p></div>
<div class="MsoNormal">
Here class SubjectCreator is the abstract class that has an
abstract method of type Subject and there are two instances of the
SubjectCreator: PhysicsCreator class which overrides the base class’s abstract
method and returns the type “Physics”. MathematicsCreator class overrides the
base class’s abstract method and returns the type “Mathematics”. Now client
program instead of creating instance of the Creator class now creates the
instances of sub classes to get the actual instances.<o:p></o:p></div>
<div class="MsoNormal">
Here is the code:<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethodPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Base class for concrete classes</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">abstract</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">abstract</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> SubjectName { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethodPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Physics class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Physics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">override</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> SubjectName<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">"Physics"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethodPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Mathematics class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Mathematics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">override</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> SubjectName<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">get</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> { </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">"Mathematics"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">; }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethodPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Base class that has abstract method of type subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">abstract</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">SubjectCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">abstract</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethod();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethodPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Class that creates instance of Physics class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">PhysicsCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">SubjectCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">override</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethod()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Physics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethodPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"><summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> Class to cretae the instance of Mathematics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">///</span><span style="background: white; color: green; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"> </span><span style="background: white; color: grey; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;"></summary></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">MathematicsCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">SubjectCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">override</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Subject</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethod()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Mathematics</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">namespace</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> FactoryMethodPattern<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Program</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">static</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> Main(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">[] args)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">SubjectCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> objectCreator = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">MathematicsCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(objectCreator.FactoryMethod().SubjectName);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">
objectCreator = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">PhysicsCreator</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.WriteLine(objectCreator.FactoryMethod().SubjectName);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-font-kerning: 0pt; mso-highlight: white;">Console</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">.Read();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now let us check the output:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSgZUWaVQfC2bFchtS0Jd0ipJ4AG_4s1pGJVH874Xt75wYtHV5t4eAK0S2R2lrZ6UJSMAVWR67eZ7tiZjBptskTMocXFgUrYJex85GgXJ3Yk7_O5rNlVlb8jnq8BGl3Mmen-h39V_b3-0/s1600/C-7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="46" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSgZUWaVQfC2bFchtS0Jd0ipJ4AG_4s1pGJVH874Xt75wYtHV5t4eAK0S2R2lrZ6UJSMAVWR67eZ7tiZjBptskTMocXFgUrYJex85GgXJ3Yk7_O5rNlVlb8jnq8BGl3Mmen-h39V_b3-0/s320/C-7.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_7" o:spid="_x0000_i1025" type="#_x0000_t75" style='width:468pt;
height:68.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
In this case, instead of creating instances through Factory
class, client program delegates the responsibility of creating the instances
using one of the sub classes of the Factory class and the abstract method is overridden
to return the actual instances.<o:p></o:p></div>
<div class="MsoNormal">
Hope you like this article. Happy coding!!!<o:p></o:p></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-80110962106666768612013-01-22T22:46:00.000-05:002013-01-22T22:46:20.198-05:00Cool features in Visual Studio 2012<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
<div class="MsoNormal">
Microsoft has gifted developer community many cool features
with the introduction of the Visual Studio 2012. This article speaks about some
of the cool features in Visual Studio 2012.<o:p></o:p></div>
<div class="MsoNormal">
You need to have Visual Studio installed in your computer to
check these cool features. If you do not have it installed and if you do not
have license for the same you can download the trial version and can test the
new version.<o:p></o:p></div>
<div class="MsoNormal">
<b>Feature 1: Preview
Images<o:p></o:p></b></div>
<div class="MsoNormal">
We will first discuss the ability to see preview of the
image. To do this I have added a JPG file to my existing project as below:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKCVh_c2-ec1nNzaFSmdBkAiz5NJyidKwD68eEHV4X1eCpKkRlvuJNCp1F_7C3lXUaUhNurl_nHKHG2VM8IHxcu7DA62y-evgMe4tt0KO8c-Dg3Ov0_eeUkxVb0vn4zgPf4myOOSfyE70/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKCVh_c2-ec1nNzaFSmdBkAiz5NJyidKwD68eEHV4X1eCpKkRlvuJNCp1F_7C3lXUaUhNurl_nHKHG2VM8IHxcu7DA62y-evgMe4tt0KO8c-Dg3Ov0_eeUkxVb0vn4zgPf4myOOSfyE70/s320/Pic1.png" width="298" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1040" type="#_x0000_t75"
style='width:259.5pt;height:278.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now place your mouse on the jpg file added in the project
and observe. It shows preview of the image.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1J4AQvCLfvVavQXScqrLacg_GTP_1dvFW1SwxU-oEfWNo5oQl6MRMdQwWGriMbMR5CqFAg_wRIqyFzL6kXfTcRCDRDD0VIV4gtiZXGaqTul4ngtaijyom1L7GXtO0oLvs6dYeJlH7Qi4/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1J4AQvCLfvVavQXScqrLacg_GTP_1dvFW1SwxU-oEfWNo5oQl6MRMdQwWGriMbMR5CqFAg_wRIqyFzL6kXfTcRCDRDD0VIV4gtiZXGaqTul4ngtaijyom1L7GXtO0oLvs6dYeJlH7Qi4/s320/Pic1.png" width="290" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_2" o:spid="_x0000_i1039" type="#_x0000_t75" style='width:252pt;
height:277.5pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
Pretty cool feature right!!!<o:p></o:p></div>
<div class="MsoNormal">
<b>Feature 2: View Multiple
Solution Explorers (Copy of Solution Explorer in multiple windows)<o:p></o:p></b></div>
<div class="MsoNormal">
Will it not be good if we can have two solution explorers
where you can select the project from any one of them and drag the explorers
anywhere in the screen? It is a fantastic feature provided by Microsoft to the
developers.<o:p></o:p></div>
<div class="MsoNormal">
Let us see how we can view multiple solution explorers. If
you observe we already have one solution explorer opened in the Visual Studio
and now if you select another one, it will open a copy of the same explorer in
another window.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAGIyDqXrUzCzABJmEIDe37cHcDZ7u3gRu1TPAO93KJg5M5nsOMmlo1lTbmPD1-1nRUxua_TRDGbFHT-7jrzrBn_xPJqCcQ07n8RIXbzspKSGfpfmmk_TYn0kIlL6Wu_4QzzXCWnPQHWo/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAGIyDqXrUzCzABJmEIDe37cHcDZ7u3gRu1TPAO93KJg5M5nsOMmlo1lTbmPD1-1nRUxua_TRDGbFHT-7jrzrBn_xPJqCcQ07n8RIXbzspKSGfpfmmk_TYn0kIlL6Wu_4QzzXCWnPQHWo/s320/Pic1.png" width="288" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now right click on the Solution and you will come up with
the following options:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD1z0JKsaVHazpiH_3JTMw3lMmz-rEXHl8Rb8ympCPhjJzNvltysFGhtR_flqz-atFxhmD9o4dsaIa1OJm0gmP8dD96ofaf8X0euzIDCpLib4btG0amIKnGCgnMsWThj3pTYY8ub4Eh3Y/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="273" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD1z0JKsaVHazpiH_3JTMw3lMmz-rEXHl8Rb8ympCPhjJzNvltysFGhtR_flqz-atFxhmD9o4dsaIa1OJm0gmP8dD96ofaf8X0euzIDCpLib4btG0amIKnGCgnMsWThj3pTYY8ub4Eh3Y/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_5" o:spid="_x0000_i1037" type="#_x0000_t75" style='width:467.25pt;
height:399.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
You can now expand the one project in one explorer and work
on the files.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLgCUbz0Rn66CkgsrJ5aztks1O2mN0n21dBU0_xqb9n1-zOXzy_jaLC4vDZm6s8m5je2mZ9u5ei9W5e9Rz61MjuNy20uXa0Jtsu5DmIwNjWe_47DbRTPutVd3QjigYQMPJeYH5Ms36ii4/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="118" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhLgCUbz0Rn66CkgsrJ5aztks1O2mN0n21dBU0_xqb9n1-zOXzy_jaLC4vDZm6s8m5je2mZ9u5ei9W5e9Rz61MjuNy20uXa0Jtsu5DmIwNjWe_47DbRTPutVd3QjigYQMPJeYH5Ms36ii4/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_8" o:spid="_x0000_i1036" type="#_x0000_t75" style='width:467.25pt;
height:172.5pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
You can drag the windows anywhere in the Visual Studio
editor. This will be helpful when you are working on complex solutions. You can
use the features like <b>Scoping</b> and <b>Filtering</b> with the <b>New Solution Explorer feature</b> that we discussed now.<o:p></o:p></div>
<div class="MsoNormal">
<b>Feature 3: Filters in
the Solution Explorer<o:p></o:p></b></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIDAoH1f3je-jvWrTQJVByX3pc__JiyZbbL3P7LLsmrWKjbrp6XAtrnMzlv6c4ac7n-h6rRtaykCAJ6Pe1qKpWxnx9LRnYSi87vyEu08W8TgEBMrEvPEqbCitTeHlt-kG2Y6p3Hct6dIo/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="228" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIDAoH1f3je-jvWrTQJVByX3pc__JiyZbbL3P7LLsmrWKjbrp6XAtrnMzlv6c4ac7n-h6rRtaykCAJ6Pe1qKpWxnx9LRnYSi87vyEu08W8TgEBMrEvPEqbCitTeHlt-kG2Y6p3Hct6dIo/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<b><br /></b></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_10" o:spid="_x0000_i1035" type="#_x0000_t75" style='width:260.25pt;
height:186pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image008.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
In the solution Explorer you will find an icon for filtering
the files listed in the solution explorer. There are two features available for
filtering.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM9Bg1vCpEKSOd-bOszTT-CYXSP1AdgJ9z-x54E0uCSK2XWulYlnOr0Z-LfykjFqRUtc61giuu15pV9HkZX8CnBDBwzozxrEowD9Bo8UesIAHb1xSab24RIMIEEIMN732uUC133mQ0Cbg/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="217" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM9Bg1vCpEKSOd-bOszTT-CYXSP1AdgJ9z-x54E0uCSK2XWulYlnOr0Z-LfykjFqRUtc61giuu15pV9HkZX8CnBDBwzozxrEowD9Bo8UesIAHb1xSab24RIMIEEIMN732uUC133mQ0Cbg/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_11" o:spid="_x0000_i1034" type="#_x0000_t75" style='width:243pt;
height:165pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image009.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
Filtering options:<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->1.<span style="font-size: 7pt;">
</span><!--[endif]-->Pending Changes Filter<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l0 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->2.<span style="font-size: 7pt;">
</span><!--[endif]-->Open Files Filter<o:p></o:p></div>
<div class="MsoNormal">
Before going to test the filter options we need to add our
solution to Team Foundation Server so that we can check-in and check-out the
files. Pending Changes Filter is used to list only the files that are newly
added or modified and are pending for check-in. I have added a JPG file to the
project in the solution explorer. So, when I select the option 1 it should show
me only the JPG file.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmINnr06oq-NuyqfAkjTnZDy1pp9uV4h5kYTbov2KD6aJoFqthFdmlI8fEfiapdiWqOCGpXppP7GHi1z2jiPMx89TgN0nvAGNph_wH5Tt7TvUWptm6lYo3KKqwfkFvJPdIdWgXtcHHom4/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="168" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmINnr06oq-NuyqfAkjTnZDy1pp9uV4h5kYTbov2KD6aJoFqthFdmlI8fEfiapdiWqOCGpXppP7GHi1z2jiPMx89TgN0nvAGNph_wH5Tt7TvUWptm6lYo3KKqwfkFvJPdIdWgXtcHHom4/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_12" o:spid="_x0000_i1033" type="#_x0000_t75" style='width:248.25pt;
height:130.5pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image010.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
You see that only one project is selected and only the image
file is listed.<o:p></o:p></div>
<div class="MsoNormal">
Open Files Filter is to show only the files opened in the
editor and want to get rid of unopened files in the solution explorer.<o:p></o:p></div>
<div class="MsoNormal">
In my editor I have opened only 3 files and so when I select
the second option it should show only the 3 files that were opened.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6gTf92WSXu3RcwaI4gmGVRUXJcIwXCQKeFq45SE-3TEyaUfbysw-bv6MyHjjdsn-CQAzEfM-NHRf631-KGv__PSdilx21fwTZ4nTXzHbUmD4NYGKRAfa_3m-2l-2zv2u-O_T7INnJsf4/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="66" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6gTf92WSXu3RcwaI4gmGVRUXJcIwXCQKeFq45SE-3TEyaUfbysw-bv6MyHjjdsn-CQAzEfM-NHRf631-KGv__PSdilx21fwTZ4nTXzHbUmD4NYGKRAfa_3m-2l-2zv2u-O_T7INnJsf4/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_14" o:spid="_x0000_i1032" type="#_x0000_t75" style='width:431.25pt;
height:90pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image011.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now check the files listed in the Solution Explorer:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVKY3MlsnK1J6bd5lf5PlRzVUnOeeNw0IxCelQiMbM5Khf9iT2UDHWYHJcHE3hG6DD9Px-uP2_MbKgWvyxiiMIWPTucq84RXupcAxaOa3jf-SR5Nh8I7GbZmtKVIqwa61IQwvKQ8rtiz4/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="203" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVKY3MlsnK1J6bd5lf5PlRzVUnOeeNw0IxCelQiMbM5Khf9iT2UDHWYHJcHE3hG6DD9Px-uP2_MbKgWvyxiiMIWPTucq84RXupcAxaOa3jf-SR5Nh8I7GbZmtKVIqwa61IQwvKQ8rtiz4/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_15" o:spid="_x0000_i1031" type="#_x0000_t75" style='width:244.5pt;
height:155.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image012.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
Now let us see how multiple explorer features helps in
regarding to filtering. I have opened a new solution explorer. In the first
explorer I have selected Pending Changes Filter and in the second one I have
selected the Open Files filter.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW9DOi5kIJsGQeNFSlY7ASyqe0F2gmqXiVgwYv0Cy7Cme7PDsubZ39KDzVrPNNwAFmOgAei4wnJqeguYYAmscmhE04W-GrEHFfKT3hipHbibiP4VzUHoeydGs8-BmCrC_0gdembZS8sbI/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="121" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW9DOi5kIJsGQeNFSlY7ASyqe0F2gmqXiVgwYv0Cy7Cme7PDsubZ39KDzVrPNNwAFmOgAei4wnJqeguYYAmscmhE04W-GrEHFfKT3hipHbibiP4VzUHoeydGs8-BmCrC_0gdembZS8sbI/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_16" o:spid="_x0000_i1030" type="#_x0000_t75" style='width:468pt;
height:177.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image013.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
<b>Feature 4: Scoping<o:p></o:p></b></div>
<div class="MsoNormal">
Let say if you have a solution explorer with multiple
projects with many number of files. If you are working on one of the project,
you may not like to see all the projects listed out. In that case, the only
option available before Visual Studio 2012 is minimize the Projects tree view.
But you cannot get rid of them. <o:p></o:p></div>
<div class="MsoNormal">
Visual Studio 2012 came up with a feature called Scoping.
This feature helps you to scope your solution explorer to show only the project
that you are working up on.<o:p></o:p></div>
<div class="MsoNormal">
In my solution explorer I have two projects listed out as
below:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmIV1d99gXtAh-xPmSiWu7kiAF7f9HpMoim_fj9jqKVUWz8gXBJCvAZ2UE12_XDbC02pMqQ3A9dYeHMoXUgoF8CIqhyxNsSdd36jiCJcwuxk7ZhwJnO7tnV39p9jz2KjSQTJRSawKVOBs/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmIV1d99gXtAh-xPmSiWu7kiAF7f9HpMoim_fj9jqKVUWz8gXBJCvAZ2UE12_XDbC02pMqQ3A9dYeHMoXUgoF8CIqhyxNsSdd36jiCJcwuxk7ZhwJnO7tnV39p9jz2KjSQTJRSawKVOBs/s320/Pic1.png" width="288" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_17" o:spid="_x0000_i1029" type="#_x0000_t75" style='width:243.75pt;
height:270.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image015.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
Imagine I am working on the project called “AnotherConsole”
and so I would like to scope it to this project.<o:p></o:p></div>
<div class="MsoNormal">
Right click on the project to scope the solution explorer.<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxwtQlFDm2-pP-gnSp4AZ99GtyrIt85kSgZH59Vzpl6MIghgkaf_dxn1pwBBpNG5aAltOyWP_0B3CrRLC3xoTvgkQ4Xy9GyHAA9_ti9XyDo8fcj75CToRkimLrRoVy536zpwPm2J_XGCw/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="295" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxwtQlFDm2-pP-gnSp4AZ99GtyrIt85kSgZH59Vzpl6MIghgkaf_dxn1pwBBpNG5aAltOyWP_0B3CrRLC3xoTvgkQ4Xy9GyHAA9_ti9XyDo8fcj75CToRkimLrRoVy536zpwPm2J_XGCw/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_18" o:spid="_x0000_i1028" type="#_x0000_t75" style='width:468pt;
height:6in;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image016.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
Now you see that only one project is listed out in the
solution explorer as below:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl94lRE91mck9vvMSSbVglgcBBAB788Vzrw-3Z5OnHjUbGD33rULJ58E1O763IbZ6FenUfwW5VMFaYquo4A36ndeISepO54jKuUAM9ovUdc4XB3mTrfqyvwLp-903SCVR11BEGwejDxpk/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgl94lRE91mck9vvMSSbVglgcBBAB788Vzrw-3Z5OnHjUbGD33rULJ58E1O763IbZ6FenUfwW5VMFaYquo4A36ndeISepO54jKuUAM9ovUdc4XB3mTrfqyvwLp-903SCVR11BEGwejDxpk/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_19" o:spid="_x0000_i1027" type="#_x0000_t75" style='width:248.25pt;
height:153.75pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image018.png"
o:title="" croptop="4369f" cropbottom="5188f"/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
You can use multiple solution explorers for one window
having scoping enabled and other one filtering enabled as below:<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYlhh1yrRmZWCsk8BcXteDC-nS00ZL9xiEPGdBOYGfbacEWdgTYyajxJCaOaSbBHdnmNWZG-unnyNPbdCnfL3Rw8NO7ozFB2s5mRUe01HFGLusbgJJzHmNhAp-49B-1-hAlz6u5v6GCA4/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="275" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYlhh1yrRmZWCsk8BcXteDC-nS00ZL9xiEPGdBOYGfbacEWdgTYyajxJCaOaSbBHdnmNWZG-unnyNPbdCnfL3Rw8NO7ozFB2s5mRUe01HFGLusbgJJzHmNhAp-49B-1-hAlz6u5v6GCA4/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_20" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:468pt;
height:403.5pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image020.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
If you want to reset the scope option in the solution
explorer select “Home” icon on the top. <o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVKotaNHSrjDtBX8KLE-MVZtKyb1X1Frot7_KeHs0SShk38uK2gJjg7_fLhbpSGQbuz70h8sgn3DrPRVVXs_PaJU7035OLYxXhaBmhlzdmuWSU3vBp_FoTr9gspC7D3_gigboPz-feLoI/s1600/Pic1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="166" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVKotaNHSrjDtBX8KLE-MVZtKyb1X1Frot7_KeHs0SShk38uK2gJjg7_fLhbpSGQbuz70h8sgn3DrPRVVXs_PaJU7035OLYxXhaBmhlzdmuWSU3vBp_FoTr9gspC7D3_gigboPz-feLoI/s320/Pic1.png" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><v:shape
id="Picture_x0020_21" o:spid="_x0000_i1025" type="#_x0000_t75" style='width:254.25pt;
height:132pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image022.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
We will discuss other cool features in the next article.
Hope you all have enjoyed this article. Try using these features for your
benefit. Happy coding guys!!!!<o:p></o:p></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-64884330945193872302013-01-14T22:28:00.000-05:002013-01-22T22:47:13.821-05:00Calling JavaScript function from Link Button in ASP.NET<br />
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
</div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">This is a simple article which demonstrates how to use Link
Button control of ASP.NET in the web applications. This article explains on how
to execute client side functions when the link button is clicked. <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Example projects are created using Visual Studio 2008 and
the project type created is Web Application.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">Purpose:</b> Calling
JavaScript function and passing the property value.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Here is my UI code:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">I have added a Grid View control of ASP.NET to display a
list of products. The columns displayed are Product Name and Description.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">To display the Product Name, I have added a Link Button
control which has got text value as the Product Name. I have added one custom
property called “myCustomID” and setting the property with a value of the
Product ID. <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Note: You can add as many custom properties in controls and
can access them wherever is needed though you will not see when using the
Intellisense while defining them.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="background: yellow; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-highlight: yellow; mso-no-proof: yes;"><%</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #a31515;">Page</span> <span style="color: red;">Language</span><span style="color: blue;">="C#"</span>
<span style="color: red;">AutoEventWireup</span><span style="color: blue;">="true"</span>
<span style="color: red;">CodeBehind</span><span style="color: blue;">="Default.aspx.cs"</span>
<span style="color: red;">Inherits</span><span style="color: blue;">="HyperLinkExample._Default"</span>
<span style="background: yellow; mso-highlight: yellow;">%><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><!</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DOCTYPE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">html</span> <span style="color: red;">PUBLIC</span>
<span style="color: blue;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span>
<span style="color: blue;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">xmlns</span><span style="color: blue;">="http://www.w3.org/1999/xhtml"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">title</span><span style="color: blue;">></span>Untitled
Page<span style="color: blue;"></</span><span style="color: #a31515;">title</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">script</span> <span style="color: red;">type</span><span style="color: blue;">="text/javascript"</span> <span style="color: red;">src</span><span style="color: blue;">="JS/jquery.js"></</span><span style="color: #a31515;">script</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">script</span> <span style="color: red;">type</span><span style="color: blue;">="text/javascript"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">$(document).ready(<span style="color: blue;">function</span>() {<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>jQuery(<span style="color: #a31515;">'[id$="LinkProducts"]'</span>).click(<span style="color: blue;">function</span>() {<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span> customID
= $(<span style="color: blue;">this</span>).attr(<span style="color: #a31515;">'myCustomID'</span>);;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>alert(customID);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}); <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>});<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">script</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">form</span> <span style="color: red;">id</span><span style="color: blue;">="form1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">asp</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">:</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">GridView</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">ID</span><span style="color: blue;">="ShowProducts"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">AutoGenerateColumns</span><span style="color: blue;">="false"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">Columns</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TemplateField</span> <span style="color: red;">HeaderText</span><span style="color: blue;">="Product Name"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">ItemTemplate</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 2in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">asp</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">:</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">LinkButton</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">ID</span><span style="color: blue;">="LinkProducts"</span>
<span style="color: red;">runat</span><span style="color: blue;">="server"</span>
<span style="color: red;">myCustomID</span><span style="color: blue;">='</span><span style="background: yellow; mso-highlight: yellow;"><%</span>#
Eval("ID")<span style="background: yellow; mso-highlight: yellow;">%></span><span style="color: blue;">'</span> <span style="color: red;">Text</span><span style="color: blue;">='</span><span style="background: yellow; mso-highlight: yellow;"><%</span>#
Eval("Name")<span style="background: yellow; mso-highlight: yellow;">%></span><span style="color: blue;">'></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">LinkButton</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">ItemTemplate</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TemplateField</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">asp</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">:</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">BoundField</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">DataField</span><span style="color: blue;">="Description"</span>
<span style="color: red;">HeaderText</span><span style="color: blue;">="Description"</span>
<span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">Columns</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In the code behind file, I have added a class called
“Product” which has got 3 public properties: ID, Name, and Description.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>public</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Product<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> Name { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> ID { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">string</span> Description { <span style="color: blue;">get</span>;
<span style="color: blue;">set</span>; }<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now include the name space System.Collection.Generic for
using the collections in your example.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections.Generic;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now create a collection of objects of type “Product” and
define the property values. In a real-time application, you might get data from
the databases.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Add the following code in the Page Load event of the class:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.5in; mso-layout-grid-align: none; text-indent: 0.5in;">
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">List</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><<span style="color: #2b91af;">Product</span>>
ProductList = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Product</span>><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">new</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Product</span>(){Name=<span style="color: #a31515;">"Product1"</span>, ID=<span style="color: #a31515;">"1"</span>,Description
= <span style="color: #a31515;">"Description1"</span>},<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">new</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Product</span>(){Name=<span style="color: #a31515;">"Product2"</span>, ID=<span style="color: #a31515;">"2"</span>,Description
= <span style="color: #a31515;">"Description2"</span>},<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">new</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Product</span>(){Name=<span style="color: #a31515;">"Product3"</span>, ID=<span style="color: #a31515;">"3"</span>,Description
= <span style="color: #a31515;">"Description3"</span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>};<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>ShowProducts.DataSource =
ProductList;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>ShowProducts.DataBind();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">The above code initializes a collection object ProductList
with 3 Product type data and binds the data to the Grid View.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">When you run your application, your browser should be
displayed as below:<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfld23oQM4FtxceK3LxE8Xu46b58-EWCjKq7Ii8MC9K0MvGPKLrD5wwH_kyB2iDoDHAymPLH4GOkSvjj34XhDBo4NL-7zL6AgQVYwqr3wuU4m0PNtkB4vZL9h6NY3o2Q_Cvqx2G1WiR8M/s1600/C-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfld23oQM4FtxceK3LxE8Xu46b58-EWCjKq7Ii8MC9K0MvGPKLrD5wwH_kyB2iDoDHAymPLH4GOkSvjj34XhDBo4NL-7zL6AgQVYwqr3wuU4m0PNtkB4vZL9h6NY3o2Q_Cvqx2G1WiR8M/s1600/C-3.png" /></a></div>
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype id="_x0000_t75"
coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1026" type="#_x0000_t75"
style='width:163.5pt;height:80.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now we need to write client side script for Link Button
Click event. I am using jQuery in my example. You can download the jQuery from
the jQuery website or from the code attachment with this article.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Include the jQuery in the page and then write code for click
function. Get the custom property value and display as an alert.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">script</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">type</span><span style="color: blue;">="text/javascript"</span>
<span style="color: red;">src</span><span style="color: blue;">="JS/jquery.js"></</span><span style="color: #a31515;">script</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">script</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">type</span><span style="color: blue;">="text/javascript"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">$(document).ready(<span style="color: blue;">function</span>() {<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>jQuery(<span style="color: #a31515;">'[id$="LinkProducts"]'</span>).click(<span style="color: blue;">function</span>() {<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span> customID
= $(<span style="color: blue;">this</span>).attr(<span style="color: #a31515;">'myCustomID'</span>);;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>alert(customID);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}); <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>});<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">script</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now click on the hyperlink in your browser and you should see
that the javascript function is invoked and an alert with the ID of the Product
Name is displayed.<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY6kLgWhndwWGV4vSHmdP2GiW0SHQLuur9130bTf8Ah1gjkUhkRdYowWnwxoJXZ7vmuGsgZfd8YliTz45zrnUPmJ83hda2ZLnzNrH0Mfp6I-RaSHU1GRBSipXO9qG7cOIBPyODpjGJ6_o/s1600/C-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="153" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgY6kLgWhndwWGV4vSHmdP2GiW0SHQLuur9130bTf8Ah1gjkUhkRdYowWnwxoJXZ7vmuGsgZfd8YliTz45zrnUPmJ83hda2ZLnzNrH0Mfp6I-RaSHU1GRBSipXO9qG7cOIBPyODpjGJ6_o/s320/C-4.png" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Picture_x0020_2" o:spid="_x0000_i1025" type="#_x0000_t75" style='width:399.75pt;
height:191.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Conclusion:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In real-time applications, the custom property value will be
used for other purposes like displaying corresponding client side data for the
value or hiding/showing some of the elements and calculating some of the values
based on the requirements. <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">This article is intentionally made short so that if someone
searches for this requirement, he/she should be able to get the proper help.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In my next article we would see how to execute server side
functions when user clicks the Link Button.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Happy Coding!!!<o:p></o:p></span></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-6165603186875854602013-01-14T22:25:00.000-05:002013-01-22T22:47:29.751-05:00Calling Server side function from Link Button in ASP.NET<br />
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
</div>
<span style="font-family: Calibri;">This article explains on how to execute Server side
functions when the link button is clicked. <o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Example projects are created using Visual Studio 2008 and
the project type created is Web Application.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">Purpose:</b> Calling server
side function and passing the property value.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Here is my UI code:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">I have added a Grid View control of ASP.NET to display a
list of products. The columns displayed are Product Name and Description.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">To display the Product Name, I have added a Link Button
control which has got text value as the Product Name. I have added one custom
property called “myCustomID” and setting the property with a value of the
Product ID. <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Note: You can add as many custom properties in controls and
can access them wherever is needed though you will not see when using the
Intellisense while defining them.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">I am going to add a div tag to the UI that we used in the
previous article “<b style="mso-bidi-font-weight: normal;">Calling JavaScript
function from Link Button in ASP.NET</b>“<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Calibri;">This is how my UI body looks
like:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: Calibri;">We can set the value for
Command Argument for Link Button which can be accessed on the server side. We
can specify the server side method by specifying OnCommand event handler.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">form</span> <span style="color: red;">id</span><span style="color: blue;">="form1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">asp</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">:</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">GridView</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">ID</span><span style="color: blue;">="ShowProducts"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">AutoGenerateColumns</span><span style="color: blue;">="false"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">Columns</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TemplateField</span> <span style="color: red;">HeaderText</span><span style="color: blue;">="Product Name"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">ItemTemplate</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">LinkButton</span> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: red;">ID</span><span style="color: blue;">="LinkProducts"</span> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: red;">runat</span><span style="color: blue;">="server"</span> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">
</span><span style="color: red;">CommandArgument</span><span style="color: blue;">='</span><span style="background: yellow; mso-highlight: yellow;"><%</span>#Eval("ID")<span style="background: yellow; mso-highlight: yellow;">%></span><span style="color: blue;">'</span> <o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">
</span><span style="color: red;">OnCommand</span><span style="color: blue;">="Product_Command"<o:p></o:p></span></span></b></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: red;">Text</span><span style="color: blue;">='</span><span style="background: yellow; mso-highlight: yellow;"><%</span># Eval("Name")<span style="background: yellow; mso-highlight: yellow;">%></span><span style="color: blue;">'></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">LinkButton</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">ItemTemplate</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TemplateField</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">asp</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">:</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">BoundField</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">DataField</span><span style="color: blue;">="Description"</span>
<span style="color: red;">HeaderText</span><span style="color: blue;">="Description"</span>
<span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">Columns</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span> <span style="color: red;">id</span><span style="color: blue;">="displayDetails"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span> <span style="color: red;">ID</span><span style="color: blue;">="ShowDetails"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><span style="font-family: Calibri;">We are going to use the same
server side code with the new methods.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Page Load Event<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="sender"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="e"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">protected</span>
<span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Product</span>> ProductList = <span style="color: blue;">new</span>
<span style="color: #2b91af;">List</span><<span style="color: #2b91af;">Product</span>><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">new</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Product</span>(){Name=<span style="color: #a31515;">"Product1"</span>, ID=<span style="color: #a31515;">"1"</span>,Description
= <span style="color: #a31515;">"Description1"</span>},<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">new</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Product</span>(){Name=<span style="color: #a31515;">"Product2"</span>, ID=<span style="color: #a31515;">"2"</span>,Description
= <span style="color: #a31515;">"Description2"</span>},<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1.5in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">new</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Product</span>(){Name=<span style="color: #a31515;">"Product3"</span>, ID=<span style="color: #a31515;">"3"</span>,Description
= <span style="color: #a31515;">"Description3"</span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>};<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>ShowProducts.DataSource =
ProductList;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>ShowProducts.DataBind();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> OnCommand Method for Link Button<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="sender"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="e"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">protected</span>
<span style="color: blue;">void</span> Product_Command(<span style="color: #2b91af;">Object</span>
sender, <span style="color: #2b91af;">CommandEventArgs</span> e)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Get the
Product ID from the Command Argument<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">String</span>
productID = e.CommandArgument.ToString();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Call
the method to display the selected product ID<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>ShowDetailsOfProduct(productID);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Show the product id selected<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="productID"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">protected</span>
<span style="color: blue;">void</span> ShowDetailsOfProduct(<span style="color: blue;">string</span> productID)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">StringBuilder</span>
sbreport = <span style="color: blue;">new</span> <span style="color: #2b91af;">StringBuilder</span>();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">sbreport.Append(<span style="color: #a31515;">"<table
width='95%' border='0' cellpadding='0' cellspacing='0' align='center'>"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sbreport.Append(<span style="color: #a31515;">"<tr class='tdcolbg'>"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sbreport.Append(<span style="color: #a31515;">"<td>"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sbreport.Append(<span style="color: #a31515;">"You have clicked :"</span> + productID);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>sbreport.Append(<span style="color: #a31515;">"</td>"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sbreport.Append(<span style="color: #a31515;">"</tr>"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sbreport.Append(<span style="color: #a31515;">"</table>"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>ShowDetails.Text =
sbreport.ToString();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}</span><o:p></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><span style="font-family: Calibri;">Now run the application and
check. If you want you can put break point to understand the flow.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">When you click on the Product Name Links, it should execute
Server side code and display the information in the Label control in the Div
tag.<o:p></o:p></span></div>
<br />
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype id="_x0000_t75"
coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_3" o:spid="_x0000_i1026" type="#_x0000_t75"
style='width:156pt;height:89.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY8w5ECy1ck4sJD1TaKAs5Dd6n-uyLADiM4jmUKX_-IZbTp7v8CsC-iDdUDanTCLS0e9jb7tr6_3PV9kbiM-WC8zBdOVAIZ-YwnfptwL1ngIG10_Kdo7mHGqDQ48YlUAYAUyOTFqxnYDs/s1600/C-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjY8w5ECy1ck4sJD1TaKAs5Dd6n-uyLADiM4jmUKX_-IZbTp7v8CsC-iDdUDanTCLS0e9jb7tr6_3PV9kbiM-WC8zBdOVAIZ-YwnfptwL1ngIG10_Kdo7mHGqDQ48YlUAYAUyOTFqxnYDs/s1600/C-1.png" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjE3UvSu_Ty7kYgis5fnA9TNIfMoP_XU5rDvtPNyLr-VwbWRy0oA4ZaCiCIbO-_Y4KpI5LedZzi4Wv1ixX-wq8yv51Qcyp43dELinkP0w45-8-ivOWiWSAWC_65SQAdaq6wkdY_03pqQ9Q/s1600/C-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjE3UvSu_Ty7kYgis5fnA9TNIfMoP_XU5rDvtPNyLr-VwbWRy0oA4ZaCiCIbO-_Y4KpI5LedZzi4Wv1ixX-wq8yv51Qcyp43dELinkP0w45-8-ivOWiWSAWC_65SQAdaq6wkdY_03pqQ9Q/s1600/C-2.png" /></a></div>
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
</div>
<br />
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape id="Picture_x0020_4"
o:spid="_x0000_i1025" type="#_x0000_t75" style='width:162.75pt;height:90pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Conclusion:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">This article discusses on how to invoke server side code
when the Link Button is clicked in the ASPX file.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In my next article we would see how to execute server side function
through AJAX and jQuery. In today’s world customers mostly would like to see
the application to access the server side code from client code so that the
page will not get post back and also, can reduce the performance issues. Since,
to get some data from the server and if post back of whole page is not needed
it is always a best practice to go for AJAX.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Happy Coding!!!<o:p></o:p></span></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-57568104295872096362013-01-13T20:15:00.000-05:002013-01-22T22:47:44.978-05:00List all files in a folder based on file extension<br />
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
</div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">This is a very simple article on how to search and list all
the files in a folder based on the file extension provided.<span style="mso-spacerun: yes;"> </span>I am here taking an ASP.NET Website example
developed using Visual Studio 2008. You can use any version of .NET to work on
this example.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">I have placed few files in the location C:\Test for this
example.<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht7sdYTA5iWfRQx-kfWlqYbgT6uf50_X2Cu_Ph3u8yWsn3yGrn70BQTc-antGZr6SQnACmAja3uMMR8JNKPyLisRMtbuzIHKZs75V_P3kr9ut7AdkzxPMFEatKqDDgCBHV9lmAwbYx6bk/s1600/C-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="279" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEht7sdYTA5iWfRQx-kfWlqYbgT6uf50_X2Cu_Ph3u8yWsn3yGrn70BQTc-antGZr6SQnACmAja3uMMR8JNKPyLisRMtbuzIHKZs75V_P3kr9ut7AdkzxPMFEatKqDDgCBHV9lmAwbYx6bk/s320/C-1.png" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype
id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t"
path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1028" type="#_x0000_t75"
style='width:468pt;height:408pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now create a web site and add a text box control, listbox
and a submit button. The textbox takes the file extension to be searched and by
default, if no extension is specified “.txt” is taken and searched against the
folder.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">My ASPX file content looks like below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="background: yellow; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-highlight: yellow; mso-no-proof: yes;"><%</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #a31515;">Page</span> <span style="color: red;">Language</span><span style="color: blue;">="C#"</span>
<span style="color: red;">AutoEventWireup</span><span style="color: blue;">="true"</span><span style="mso-spacerun: yes;"> </span><span style="color: red;">CodeFile</span><span style="color: blue;">="Default.aspx.cs"</span> <span style="color: red;">Inherits</span><span style="color: blue;">="_Default"</span> <span style="background: yellow; mso-highlight: yellow;">%><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><!</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DOCTYPE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">html</span> <span style="color: red;">PUBLIC</span>
<span style="color: blue;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span>
<span style="color: blue;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">xmlns</span><span style="color: blue;">="http://www.w3.org/1999/xhtml"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">title</span><span style="color: blue;">></span>Untitled
Page<span style="color: blue;"></</span><span style="color: #a31515;">title</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">form</span> <span style="color: red;">id</span><span style="color: blue;">="form1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>Enter Extension of the file to be searched:<span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span> <span style="color: red;">ID</span><span style="color: blue;">="FileExtension"</span>
<span style="color: red;">runat</span><span style="color: blue;">="server"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">TextBox</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">br</span> <span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>Files List:<span style="color: blue;"><</span><span style="color: #a31515;">br</span> <span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">ListBox</span> <span style="color: red;">ID</span><span style="color: blue;">="FilesList"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">ListBox</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">br</span> <span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">br</span> <span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Button</span> <span style="color: red;">ID</span><span style="color: blue;">="Submit"</span> <span style="color: red;">Text</span><span style="color: blue;">="Search"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">My Code-behind file looks like below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Configuration;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Data;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Linq;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.Security;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.HtmlControls;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.WebControls.WebParts;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Xml.Linq;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.IO;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">public</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">partial</span>
<span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span>
: System.Web.UI.<span style="color: #2b91af;">Page</span> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Page Load event code<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="sender"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="e"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Bind the
file names to listbox control<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>BindFileNamesToList();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Event
Handler for search button click<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>Submit.Click += <span style="color: blue;">new</span> <span style="color: #2b91af;">EventHandler</span>(Submit_Click);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Submit button click functionality<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="sender"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="e"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">void</span>
Submit_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Bind the
file names to listbox control<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>BindFileNamesToList();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Get the files list by searching the files <o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> in the folder with the extension provided.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">private</span> <span style="color: blue;">void</span> BindFileNamesToList()<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//get the
file extension to be searched from the textbox<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">string</span>
extension = FileExtension.Text;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Get the
file information from the folder C:\Test based on the extension to be searched.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//FileInfo
class has methods for copying, moving, renaming, creating, opening, deleting, <o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//and
appending to files.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">FileInfo</span>[]
fileInfo = GetFilesFromFolder(<span style="color: #a31515;">@"C:\Test"</span>,
(extension == <span style="color: #a31515;">""</span>) ? <span style="color: #a31515;">"txt"</span> : extension);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Refer
http://msdn.microsoft.com/en-us/library/system.io.fileinfo.aspx for more
details.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Clear the
listbox items before loading.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>FilesList.Items.Clear();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Loop thru
the fileInfo array object to get each fileInfo object and get the name of the
file.<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Append the
filename as a value and text of a listbox<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">foreach</span>
(<span style="color: #2b91af;">FileInfo</span> fileInfoTemp <span style="color: blue;">in</span> fileInfo)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">ListItem</span>
listItem = <span style="color: blue;">new</span> <span style="color: #2b91af;">ListItem</span>(fileInfoTemp.Name,
fileInfoTemp.Name);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>FilesList.Items.Add(listItem);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Method to get the files list<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="folderName"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="extension"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">FileInfo</span>[]
GetFilesFromFolder(<span style="color: blue;">string</span> folderName, <span style="color: blue;">string</span> extension)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DirectoryInfo</span>
directoryInfo = <span style="color: blue;">new</span> <span style="color: #2b91af;">DirectoryInfo</span>(folderName);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">string</span>
internalExtension = <span style="color: blue;">string</span>.Concat(<span style="color: #a31515;">"*."</span>, extension);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">FileInfo</span>[]
fileInfo = directoryInfo.GetFiles(internalExtension, <span style="color: #2b91af;">SearchOption</span>.AllDirectories);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
</div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span>
fileInfo;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now let us run the web site and see how it works:<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIoCiIePrvS3CO7c2C6RFhglte00v9Up1dyixka9RKfXOAgsaGZ0__I_oUxMaXfUtfEzkqhObCIZ8qT0-WFryvy7-NaSk98VLYsX_DlGQyv6yXD19TcBvfuIQZTrsMxsJ7x2eqozjWLBQ/s1600/C-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="141" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIoCiIePrvS3CO7c2C6RFhglte00v9Up1dyixka9RKfXOAgsaGZ0__I_oUxMaXfUtfEzkqhObCIZ8qT0-WFryvy7-NaSk98VLYsX_DlGQyv6yXD19TcBvfuIQZTrsMxsJ7x2eqozjWLBQ/s320/C-2.png" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Picture_x0020_2" o:spid="_x0000_i1027" type="#_x0000_t75" style='width:384pt;
height:170.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Since I did not specify any file extension, it takes “.txt”
as default. Now let us enter the extension and search.<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg8_HKuceUFWmfahclRO0DT6LsnY82drmp4F4eQPpFhx91NETLit4IsGk3SdNvW1iNH-q9iGezo6J-ljpw5MaRYG2_0TvYhmW9VPOJjoK1fyEvj7YaOwxWnSsCfhML4ttsTltB7KcvcY8/s1600/C-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="110" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhg8_HKuceUFWmfahclRO0DT6LsnY82drmp4F4eQPpFhx91NETLit4IsGk3SdNvW1iNH-q9iGezo6J-ljpw5MaRYG2_0TvYhmW9VPOJjoK1fyEvj7YaOwxWnSsCfhML4ttsTltB7KcvcY8/s320/C-3.png" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Picture_x0020_3" o:spid="_x0000_i1026" type="#_x0000_t75" style='width:468pt;
height:161.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Search other types.<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrpdpvMaoMaxOXlLceIV-flDOPixweFt4e-KWFjH4f6cQR3ZBo38eDtpTgGWiF6WLXLEI9KliEwQzt_61YGMIzc_qNpETVH06gbAZL2MQfNRc164sNGpRAdR2qUIeouS86adRM6kOQ-dg/s1600/C-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="98" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrpdpvMaoMaxOXlLceIV-flDOPixweFt4e-KWFjH4f6cQR3ZBo38eDtpTgGWiF6WLXLEI9KliEwQzt_61YGMIzc_qNpETVH06gbAZL2MQfNRc164sNGpRAdR2qUIeouS86adRM6kOQ-dg/s320/C-4.png" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="mso-no-proof: yes;"><!--[if gte vml 1]><v:shape
id="Picture_x0020_4" o:spid="_x0000_i1025" type="#_x0000_t75" style='width:468pt;
height:143.25pt;visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png"
o:title=""/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><o:p></o:p><br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Hope you liked this article. You can add more search
functionalities by providing user to enter other criteria and search the files
using FileInfo class.<o:p></o:p></span></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-87450888026149045872012-09-02T17:01:00.000-04:002012-09-02T17:01:23.312-04:00URL Rewriting in ASP.NET<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
<div class="MsoNormal">
<b>What is “URL
rewriting”? <o:p></o:p></b></div>
<div class="MsoNormal">
Most sites include variables in their URLs that tell the
site what information to be shown to the user. It is something like telling the
code to load particular details of item number 7 from a shopping site.<o:p></o:p></div>
<div class="MsoNormal">
For example, the site may look like below:<o:p></o:p></div>
<div class="MsoNormal">
<a href="http://www.cshopping.com/showitem.aspx?itemid=7">http://www.cshopping.com/showitem.aspx?itemid=7</a><!--[if !supportNestedAnchors]--><a href="http://www.blogger.com/blogger.g?blogID=6469178881389701239" name="OLE_LINK1"></a><a href="http://www.blogger.com/blogger.g?blogID=6469178881389701239" name="OLE_LINK2"></a><!--[endif]--><o:p></o:p></div>
<div class="MsoNormal">
The problem with the above URL is it cannot be remembered.
It is even difficult to read on your mobile. Even the search engines like
Google cannot get any information about the content of a page from the URL.
What if you wanted to convey that itemid = 7 means a laptop with brand as
“DELL”? This is not speaking what it
should speak. <o:p></o:p></div>
<div class="MsoNormal">
So, what we expect from the above URL is it should be
understandable just at the first look. Will it not be good if the URL is as
below?<o:p></o:p></div>
<div class="MsoNormal">
<a href="http://www.blogger.com/blogger.g?blogID=6469178881389701239" name="OLE_LINK4"></a><a href="http://www.blogger.com/blogger.g?blogID=6469178881389701239" name="OLE_LINK3"></a><a href="http://www.cshopping.com/laptops/Dell/">http://www.cshopping.com/laptops/Dell/</a><o:p></o:p></div>
<div class="MsoNormal">
Now looking at the above URL you can easily tell that it is
related to laptops and the brand is DELL. So, there is a need to rewrite URL to
be somewhat meaningful and easily conveyable.<o:p></o:p></div>
<div class="MsoNormal">
<b>How to rewrite URL in
ASP.NET?<o:p></o:p></b></div>
<div class="MsoNormal">
To rewrite URLs in ASP.NET we are going to use HTTP Modules.
HTTP Modules are called before and after the HTTP handler executes. HTTP
modules help us to intercept, participate in, or modify each individual
request. HTTP Modules implement IHttpModule interface, which is located in
System.Web namespace. Modules are the ones which handles authentication and
authorization of the ASP.NET applications. If you want to implement encryption
of URL string or any custom changes to the application, it can be done by
writing our HTTP Module.<o:p></o:p></div>
<div class="MsoNormal">
Straight to the point, let us create a class in your app_Code
directory called “URLRewriter.cs” and add the following code:<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->1.<span style="font-size: 7pt;">
</span><!--[endif]-->Create a web site using visual studio and name
it as “URLRewriteTestingApp” and add a class file “URLRewriter.cs”.<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->2.<span style="font-size: 7pt;">
</span><!--[endif]-->Visual Studio will ask you that it will create a
directory called “App_Code” and place the class file in the folder. Select “OK”
to proceed.<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .25in;">
Your solution structure should
look something like this:<o:p></o:p></div>
<div class="MsoNormal" style="margin-left: .25in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsLpgFYK7QQElZ2COcVD4wVmYkueELxB_-IKw5Xvhcpv1huG5r1H0QYanWhWO6Xx78GdYaKtRS3hqpx7bBFDAIJgReF4vecOZdNzPsjC4rFdvBd5NctvhBdXjOEhhqrJL0O9jdcw2laNA/s1600/image1.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsLpgFYK7QQElZ2COcVD4wVmYkueELxB_-IKw5Xvhcpv1huG5r1H0QYanWhWO6Xx78GdYaKtRS3hqpx7bBFDAIJgReF4vecOZdNzPsjC4rFdvBd5NctvhBdXjOEhhqrJL0O9jdcw2laNA/s1600/image1.tif" /></a></div>
<div class="MsoNormal">
<!--[if gte vml 1]><o:wrapblock><v:shapetype id="_x0000_t75"
coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe"
filled="f" stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_s1030" type="#_x0000_t75"
style='position:absolute;margin-left:51pt;margin-top:-22.8pt;width:194.3pt;
height:114.75pt;z-index:251658240;visibility:visible;mso-wrap-style:square;
mso-width-percent:0;mso-height-percent:0;mso-wrap-distance-left:9pt;
mso-wrap-distance-top:0;mso-wrap-distance-right:9pt;
mso-wrap-distance-bottom:0;mso-position-horizontal:absolute;
mso-position-horizontal-relative:text;mso-position-vertical:absolute;
mso-position-vertical-relative:line;mso-width-percent:0;mso-height-percent:0;
mso-width-relative:page;mso-height-relative:page'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title=""/>
<w:wrap type="topAndBottom" anchory="line"/>
</v:shape><![endif]--><!--[if !vml]-->
<br />
<table align="left" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td height="0" width="68"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<!--[endif]--><!--[if gte vml 1]></o:wrapblock><![endif]--><br clear="ALL" />
<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->3.<span style="font-size: 7pt;">
</span><!--[endif]-->Now open the file “URLRewriter.cs” and add the
code for HTTP Module as below:<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
Basically your class must implement the
IHttpModule interface to implement its methods. You will see these 2 methods
created for you once you implement the interface.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: .75in; mso-add-space: auto; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]-->-<span style="font-size: 7pt;">
</span><!--[endif]-->Dispose<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: .75in; mso-add-space: auto; mso-list: l0 level1 lfo2; text-indent: -.25in;">
<!--[if !supportLists]-->-<span style="font-size: 7pt;">
</span><!--[endif]-->Init<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: .75in; mso-add-space: auto;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: .75in; mso-add-space: auto;">
Init method takes HttpApplication as a parameter. So, you need to create
an event handler for begin request of the HttpApplication to handle the
request.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: .75in; mso-add-space: auto;">
<br /></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: .75in; mso-add-space: auto;">
Here
is your code for the Module:<o:p></o:p></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: grey; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">///</span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span><span style="color: grey; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><summary><o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: grey; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">///</span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> Summary description for URLRewriter<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: grey; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">///</span><span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span><span style="color: grey; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></summary><o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">public</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">URLRewriter</span> : <span style="color: #2b91af;">IHttpModule<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> #region</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> IHttpModule
Members<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> Dispose
method for the class<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> If you
have any unmanaged resources to be disposed<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> free them
or release them in this method<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;">public</span> <span style="color: blue;">void</span>
Dispose()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//not implementing this method<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//for this example<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;">
Initialization of the http application instance<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="context"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;">public</span> <span style="color: blue;">void</span>
Init(<span style="color: #2b91af;">HttpApplication</span> context)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">context.BeginRequest += <span style="color: blue;">new</span> <span style="color: #2b91af;">EventHandler</span>(context_BeginRequest);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> Event
handler of instance begin request<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="sender"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="e"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;">void</span> context_BeginRequest(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span>
e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1.5in;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//Create an instance of the
application that has raised the event<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1.5in;">
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">HttpApplication</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> httpApplication = sender <span style="color: blue;">as</span> <span style="color: #2b91af;">HttpApplication</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1.5in;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//Safety check for the
variable httpApplication if it is not null<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;">if</span>
(httpApplication != <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 2in;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//get the request path -
request path is something you get in<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//the url<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 2in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">string</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> requestPath = httpApplication.Context.Request.Path;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//variable for translation path<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in; text-indent: 0.25in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">string</span>
translationPath = <span style="color: #a31515;">""</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1.75in;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//if the request path is
/urlrewritetestingapp/laptops/dell/<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//it
means the site is for DLL<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//else if
"/urlrewritetestingapp/laptops/hp/"<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//it
means the site is for HP<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//else it
is the default path<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">switch</span>
(requestPath.ToLower())<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">case</span>
<span style="color: #a31515;">"/urlrewritetestingapp/laptops/dell/"</span>:<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 2.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">translationPath = <span style="color: #a31515;">"/urlrewritetestingapp/showitem.aspx?itemid=7"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">break</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">case</span>
<span style="color: #a31515;">"/urlrewritetestingapp/laptops/hp/"</span>:<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 2.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">translationPath = <span style="color: #a31515;">"/urlrewritetestingapp/showitem.aspx?itemid=8"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">break</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">default</span>:<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 2.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">translationPath = <span style="color: #a31515;">"/urlrewritetestingapp/default.aspx"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">break</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1.75in;">
<span style="color: green; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//use server transfer to
transfer the request to the actual translated path<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 1.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
httpApplication.Context.Server.Transfer(translationPath);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> #endregion<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: .75in; mso-add-space: auto;">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->4.<span style="font-size: 7pt;">
</span><!--[endif]-->Now open your default.aspx page in the solution
and add the following html:<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
This code is to display two laptop brands
HP and DELL. <o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<br /></div>
<div class="MsoListParagraphCxSpMiddle">
<b>Note:
</b>Since I am not deploying the application in IIS you will see the runtime
host created by Visual Studio as localhost:8648. If your application has
different port number or if you have hosted your web application in IIS, you
may have to change the values of href in the following html.<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.25in;">
<span style="background: yellow; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: yellow; mso-no-proof: yes;"><%</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #a31515;">Page</span>
<span style="color: red;">Language</span><span style="color: blue;">="C#"</span>
<span style="color: red;">AutoEventWireup</span><span style="color: blue;">="true"</span> <span style="color: red;">CodeFile</span><span style="color: blue;">="Default.aspx.cs"</span> <span style="color: red;">Inherits</span><span style="color: blue;">="_Default"</span> <span style="background: yellow; mso-highlight: yellow;">%><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.25in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.25in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><!</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DOCTYPE</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">html</span>
<span style="color: red;">PUBLIC</span> <span style="color: blue;">"-//W3C//DTD
XHTML 1.0 Transitional//EN"</span> <span style="color: blue;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.25in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.25in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">xmlns</span><span style="color: blue;">="http://www.w3.org/1999/xhtml"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;"><</span><span style="color: #a31515;">title</span><span style="color: blue;">></span>Laptop Brands<span style="color: blue;"></</span><span style="color: #a31515;">title</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;"><</span><span style="color: #a31515;">form</span>
<span style="color: red;">id</span><span style="color: blue;">="form1"</span>
<span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;"><</span><span style="color: #a31515;">a</span>
<span style="color: red;">href</span><span style="color: blue;">="http://localhost:8648/URLRewriteTestingApp/laptops/Dell/"></span>Dell<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">a</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">br</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">/><o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">a</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">href</span><span style="color: blue;">="http://localhost:8648/URLRewriteTestingApp/laptops/HP/"></span>HP<span style="color: blue;"></</span><span style="color: #a31515;">a</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.75in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-left: .25in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">></span><o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->5.<span style="font-size: 7pt;">
</span><!--[endif]-->Since we are placing references in the html code
we do not need to do anything in the code behind file. Now add one more webform
ShowItem.aspx in the website. This page is to display the actual data that
clicking on the hyperlink in the default page should take it to. We are just
trying to make the application look simple and so we just display the name of
the laptop and a back button.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->6.<span style="font-size: 7pt;">
</span><!--[endif]-->HTML of the ShowItem.aspx page looks like as
below:<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: yellow; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-highlight: yellow; mso-no-proof: yes;"><%</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #a31515;">Page</span> <span style="color: red;">Language</span><span style="color: blue;">="C#"</span>
<span style="color: red;">AutoEventWireup</span><span style="color: blue;">="true"</span>
<span style="color: red;">CodeFile</span><span style="color: blue;">="ShowItem.aspx.cs"</span>
<span style="color: red;">Inherits</span><span style="color: blue;">="ShowItem"</span>
<span style="background: yellow; mso-highlight: yellow;">%><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><!</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DOCTYPE</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">html</span> <span style="color: red;">PUBLIC</span>
<span style="color: blue;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span>
<span style="color: blue;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">xmlns</span><span style="color: blue;">="http://www.w3.org/1999/xhtml"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"><</span><span style="color: #a31515;">title</span><span style="color: blue;">></span>Untitled
Page<span style="color: blue;"></</span><span style="color: #a31515;">title</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"><</span><span style="color: #a31515;">form</span> <span style="color: red;">id</span><span style="color: blue;">="form1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="labelShow"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"><</span><span style="color: #a31515;">br</span><span style="color: blue;">/><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"><</span><span style="color: #a31515;">br</span><span style="color: blue;">/><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Button</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="back"</span> <span style="color: red;">Text</span><span style="color: blue;">="Back"/><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpFirst">
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->7.<span style="font-size: 7pt;">
</span><!--[endif]-->Code behind file looks like as below:<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
Code behind is to display the text of the
laptop and back button event handler that takes back the user back to the
default page.<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">public</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">ShowItem</span> :
System.Web.UI.<span style="color: #2b91af;">Page<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> Page load
event for the page<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="sender"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="e"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//read the query string value of itemid that
is coming<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//from default page when user clicks on the
hyperlink<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;">string</span> laptopName = Request.QueryString[<span style="color: #a31515;">"itemid"</span>];<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//if value is "8" display the text
of the label as "HP"<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//else display the label as "DELL"<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
labelShow.Text = laptopName == <span style="color: #a31515;">"8"</span>
? <span style="color: #a31515;">"HP"</span> : <span style="color: #a31515;">"DELL"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//back button event handler<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
back.Click += <span style="color: blue;">new</span> <span style="color: #2b91af;">EventHandler</span>(back_Click);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<br /></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> Back
button click event<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="sender"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param name="e"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: blue;">void</span> back_Click(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
<span style="color: green;">//transfer the page back to default.aspx<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
Server.Transfer(<span style="color: #a31515;">"../default.aspx"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">
}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in;">
<br /></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l1 level1 lfo1; text-indent: -.25in;">
<!--[if !supportLists]-->8.<span style="font-size: 7pt;">
</span><!--[endif]-->Now we need to configure our custom HttpModule
“URLRewriter” in the configuration file to use the module.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">system.web</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="text-indent: .5in;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">httpModules</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 1.0in; mso-add-space: auto;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"> <</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">add</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"> </span><span style="color: red; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">name</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">=</span><span style="font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">"<span style="color: blue;">URLRewriter</span>"<span style="color: blue;"> </span><span style="color: red;">type</span><span style="color: blue;">=</span>"<span style="color: blue;">URLRewriter</span>"<span style="color: blue;">/><o:p></o:p></span></span></div>
<div class="MsoListParagraphCxSpMiddle" style="margin-left: 1.0in; mso-add-space: auto;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">httpModules</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoListParagraphCxSpLast">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">system.web</span><span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<div class="MsoNormal">
Now our coding is complete and let us test our application
by pressing F5 button.<o:p></o:p></div>
<div class="MsoNormal">
Our default.aspx page:<o:p></o:p></div>
<div class="MsoNormal">
<!--[if gte vml 1]><o:wrapblock><v:shape id="Picture_x0020_3"
o:spid="_x0000_s1029" type="#_x0000_t75" style='position:absolute;
margin-left:416.6pt;margin-top:.1pt;width:467.8pt;height:352.45pt;z-index:251660288;
visibility:visible;mso-wrap-style:square;mso-width-percent:0;
mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;
mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;
mso-position-horizontal:right;mso-position-horizontal-relative:margin;
mso-position-vertical:absolute;mso-position-vertical-relative:line;
mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;
mso-height-relative:page'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png"
o:title=""/>
<w:wrap type="topAndBottom" anchorx="margin" anchory="line"/>
</v:shape><![endif]--><!--[if !vml]-->
<br />
<table align="left" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td height="0" width="400"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<!--[endif]--><!--[if gte vml 1]></o:wrapblock><![endif]--><br clear="ALL" />
<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAXLhJhFUYHYsXcVcKRBYFDqAplsoXBnlOxG76dnwW-iVIaEVlwrpRvo_gGx7SAQQsC8d0sfjHETmrEK40JeOU9wEeRUW2qPxztHJvwPmvYUUhZ-YwqEhOiz7YFwwZz639b2_zZ9GS6Ig/s1600/image2.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="241" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAXLhJhFUYHYsXcVcKRBYFDqAplsoXBnlOxG76dnwW-iVIaEVlwrpRvo_gGx7SAQQsC8d0sfjHETmrEK40JeOU9wEeRUW2qPxztHJvwPmvYUUhZ-YwqEhOiz7YFwwZz639b2_zZ9GS6Ig/s320/image2.tif" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
When I place my cursor over Dell, the URL looks like <a href="http://localhost:8648/URLRewriteTestingApp/laptops/Dell/">http://localhost:8648/URLRewriteTestingApp/laptops/Dell/</a>
and similarly if you place your cursor on HP, it should look like <a href="http://localhost:8648/URLRewriteTestingApp/laptops/HP/">http://localhost:8648/URLRewriteTestingApp/laptops/HP/</a><o:p></o:p></div>
<div class="MsoNormal">
Put break points in your HTTP Module methods and now click
on any of the hyperlinks:<o:p></o:p></div>
<div class="MsoNormal">
I clicked on the Dell and the value at the breakpoint now
shows the value of requestPath.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5bHFldmqdq8dpn4bt7Z2fAu-Ij6gC2xT_EVxfFALTSNXt3Nf6MLn3RCSVzy_ZbiUPHT0kwRfthkZ0civpq72UCtIuOxvf5197Rbvc8MBsM3le1o5iZwgRxvU1A91wC72_BlYf0wk655M/s1600/image3.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="143" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5bHFldmqdq8dpn4bt7Z2fAu-Ij6gC2xT_EVxfFALTSNXt3Nf6MLn3RCSVzy_ZbiUPHT0kwRfthkZ0civpq72UCtIuOxvf5197Rbvc8MBsM3le1o5iZwgRxvU1A91wC72_BlYf0wk655M/s320/image3.tif" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<!--[if gte vml 1]><o:wrapblock><v:shape id="Picture_x0020_6"
o:spid="_x0000_s1028" type="#_x0000_t75" style='position:absolute;
margin-left:416.7pt;margin-top:0;width:467.9pt;height:210.05pt;z-index:251661312;
visibility:visible;mso-wrap-style:square;mso-width-percent:0;
mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;
mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;
mso-position-horizontal:right;mso-position-horizontal-relative:margin;
mso-position-vertical:absolute;mso-position-vertical-relative:line;
mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;
mso-height-relative:page'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png"
o:title=""/>
<w:wrap type="topAndBottom" anchorx="margin" anchory="line"/>
</v:shape><![endif]--><!--[if !vml]-->
<br />
<table align="left" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td height="0" width="400"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<!--[endif]--><!--[if gte vml 1]></o:wrapblock><![endif]--><br clear="ALL" />
<o:p></o:p></div>
<div class="MsoNormal">
Now the requestPath variable value is
“/URLRewriteTestingApp/laptops/Dell/”.
Our rewriting code must now identify the requestPath and change the path
to the actual URL path so that correct page gets called in the IIS by the
engine. So, our translated path will be “/urlrewritetestingapp/showitem.aspx?itemdid=7”.<o:p></o:p></div>
<div class="MsoNormal">
<!--[if gte vml 1]><o:wrapblock><v:shape id="Picture_x0020_7"
o:spid="_x0000_s1027" type="#_x0000_t75" style='position:absolute;
margin-left:0;margin-top:22.5pt;width:467.65pt;height:218.95pt;z-index:251662336;
visibility:visible;mso-wrap-style:square;mso-width-percent:0;
mso-height-percent:0;mso-wrap-distance-left:9pt;mso-wrap-distance-top:0;
mso-wrap-distance-right:9pt;mso-wrap-distance-bottom:0;
mso-position-horizontal:absolute;mso-position-horizontal-relative:text;
mso-position-vertical:absolute;mso-position-vertical-relative:line;
mso-width-percent:0;mso-height-percent:0;mso-width-relative:page;
mso-height-relative:page'>
<v:imagedata src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png"
o:title=""/>
<w:wrap type="topAndBottom" anchory="line"/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--><!--[if gte vml 1]></o:wrapblock><![endif]--><br clear="ALL" />
<o:p></o:p></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhVlXduM4nWypBj7hW-esYVblxsLKa_nUXTd7ZTuTkYJuMpLCUTtLkyJBzPoEMgljH0b3lwOdNZfL2q4byz0hhHq2SccYp57iIhrBfpMUbfGfyLoTC13dhT2WkZinJf8Y192AU4XaZyjs/s1600/image4.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="149" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhVlXduM4nWypBj7hW-esYVblxsLKa_nUXTd7ZTuTkYJuMpLCUTtLkyJBzPoEMgljH0b3lwOdNZfL2q4byz0hhHq2SccYp57iIhrBfpMUbfGfyLoTC13dhT2WkZinJf8Y192AU4XaZyjs/s320/image4.tif" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<o:p><br /></o:p></div>
<div class="MsoNormal">
Now the page looks like below:<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV9JxTcBzswtDQI2eaZj5kvcA8JZyyFXMD0PSZiNNPud_gLHafR8tg40kTZYmE2RH250P6_m56STogkxVNzm7DZn2TmVplItyY1DOXwjWXmYy7_cFdAR3JtmAurEB8ZTTRjT72IqPyqwk/s1600/image5.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="139" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiV9JxTcBzswtDQI2eaZj5kvcA8JZyyFXMD0PSZiNNPud_gLHafR8tg40kTZYmE2RH250P6_m56STogkxVNzm7DZn2TmVplItyY1DOXwjWXmYy7_cFdAR3JtmAurEB8ZTTRjT72IqPyqwk/s320/image5.tif" width="320" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br clear="ALL" />
<o:p></o:p></div>
<div class="MsoNormal">
Clicking on the “Back” button will take the user to the
default page. <o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Hope you like this article. If you have more number of URLs
to be maintained in your application, it is better to handle the URLs by one
dedicated server that processes the requests and redirects the request to the
relevant page for processing.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com2tag:blogger.com,1999:blog-6469178881389701239.post-33134596296318472612012-08-20T16:32:00.003-04:002012-08-20T16:32:58.821-04:00Find difference of data between two data sources
<br />
<div align="center" class="MsoNormal" style="margin: 0in 0in 8pt; text-align: center;">
<br /></div>
<span style="font-family: Calibri;"><b style="mso-bidi-font-weight: normal;">Problem: </b>User has
got two sets of data sources. One is a table in Sql Server and other one is an
excel sheet. So, we have 3 gridview controls in our web page. First grid shows
the data from Database table and second one shows the data from Excel sheet and
third one should show the difference of data between two grid views.<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<b style="mso-bidi-font-weight: normal;"><span style="font-family: Calibri;">Solution:<o:p></o:p></span></b></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Create a table in SQL server as below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">CREATE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">TABLE</span>
[dbo]<span style="color: grey;">.</span>[UserData]<span style="color: grey;">(<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span>[ID] [int] <span style="color: blue;">IDENTITY</span><span style="color: grey;">(</span>1<span style="color: grey;">,</span>1<span style="color: grey;">)</span> <span style="color: grey;">NOT</span> <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span>[Name] [varchar]<span style="color: grey;">(</span>50<span style="color: grey;">)</span> <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span>[Password] [varchar]<span style="color: grey;">(</span>50<span style="color: grey;">)</span> <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">CONSTRAINT</span>
[PK_UserData] <span style="color: blue;">PRIMARY</span> <span style="color: blue;">KEY</span>
<span style="color: blue;">CLUSTERED</span> <o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span>[ID] <span style="color: blue;">ASC<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">WITH </span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">PAD_INDEX</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">=</span> <span style="color: blue;">OFF</span><span style="color: grey;">,</span> <span style="color: blue;">STATISTICS_NORECOMPUTE</span><span style="mso-spacerun: yes;"> </span><span style="color: grey;">=</span> <span style="color: blue;">OFF</span><span style="color: grey;">,</span> <span style="color: blue;">IGNORE_DUP_KEY</span> <span style="color: grey;">=</span> <span style="color: blue;">OFF</span><span style="color: grey;">,</span> <span style="color: blue;">ALLOW_ROW_LOCKS</span><span style="mso-spacerun: yes;">
</span><span style="color: grey;">=</span> <span style="color: blue;">ON</span><span style="color: grey;">,</span> <span style="color: blue;">ALLOW_PAGE_LOCKS</span><span style="mso-spacerun: yes;"> </span><span style="color: grey;">=</span> <span style="color: blue;">ON</span><span style="color: grey;">)</span> <span style="color: blue;">ON</span> [PRIMARY]<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">)</span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">ON</span> [PRIMARY]<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Enter data in the above table. I have entered the following
data in the table:<o:p></o:p></span></div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: currentColor; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background: gray; border: 1pt solid windowtext; mso-background-themecolor: background1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="color: white; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-themecolor: background1;">ID<o:p></o:p></span></b></div>
</td>
<td style="background: gray; border-color: windowtext windowtext windowtext rgb(0, 0, 0); border-style: solid solid solid none; border-width: 1pt 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="color: white; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-themecolor: background1;">Name<o:p></o:p></span></b></div>
</td>
<td style="background: gray; border-color: windowtext windowtext windowtext rgb(0, 0, 0); border-style: solid solid solid none; border-width: 1pt 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<b style="mso-bidi-font-weight: normal;"><span style="color: white; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes; mso-themecolor: background1;">Password<o:p></o:p></span></b></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">1<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">abc<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">123<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">2<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">xyz<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">321<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">3<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">NNN<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">789<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">4<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">PPP<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 159.6pt;" valign="top" width="213">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">8998<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Here is the stored procedure to get the data from the table:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">ALTER</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">PROCEDURE</span>
[dbo]<span style="color: grey;">.</span>[GetUserData]<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">AS<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: blue;">select</span> Name<span style="color: grey;">,</span><span style="color: blue;">Password</span> <span style="color: blue;">from</span> userdata<span style="color: grey;">;</span></span><o:p></o:p></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now create an excel sheet document. It has two columns same
as in the table above. One is “Name” and other one “password”.<o:p></o:p></span></div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoTableGrid" style="border-collapse: collapse; border: currentColor; mso-border-alt: solid windowtext .5pt; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background: gray; border: 1pt solid windowtext; mso-background-themecolor: background1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="color: white; mso-themecolor: background1;"><span style="font-family: Calibri;">Name<o:p></o:p></span></span></div>
</td>
<td style="background: gray; border-color: windowtext windowtext windowtext rgb(0, 0, 0); border-style: solid solid solid none; border-width: 1pt 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 128; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="color: white; mso-themecolor: background1;"><span style="font-family: Calibri;">Password<o:p></o:p></span></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">abc<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">123<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">xyz<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">321<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">asas<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">856<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4; mso-yfti-lastrow: yes;">
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext; border-style: none solid solid; border-width: 0px 1pt 1pt; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">jklo<o:p></o:p></span></div>
</td>
<td style="background: rgb(191, 191, 191); border-color: rgb(0, 0, 0) windowtext windowtext rgb(0, 0, 0); border-style: none solid solid none; border-width: 0px 1pt 1pt 0px; mso-background-themecolor: background1; mso-background-themeshade: 191; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt; mso-border-top-alt: solid windowtext .5pt; padding: 0in 5.4pt; width: 239.4pt;" valign="top" width="319">
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt;">854<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Since, we need to compare two different sets of data, we
need to make sure that the column names are same so that we can compare them
using the features available in C# for .NET 3.5.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now let us build the UI for displaying the data from two
data sources and also the difference between the two data sets. My ASPX file
looks like below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="background: yellow; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-highlight: yellow; mso-no-proof: yes;"><%</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #a31515;">Page</span> <span style="color: red;">Language</span><span style="color: blue;">="C#"</span>
<span style="color: red;">AutoEventWireup</span><span style="color: blue;">="true"</span>
<span style="color: red;">CodeBehind</span><span style="color: blue;">="Default.aspx.cs"</span>
<span style="color: red;">Inherits</span><span style="color: blue;">="GridBind._Default"</span>
<span style="background: yellow; mso-highlight: yellow;">%><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><!</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DOCTYPE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">html</span> <span style="color: red;">PUBLIC</span>
<span style="color: blue;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span>
<span style="color: blue;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">xmlns</span><span style="color: blue;">="http://www.w3.org/1999/xhtml"</span>
<span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">title</span><span style="color: blue;">></span>Untitled
Page<span style="color: blue;"></</span><span style="color: #a31515;">title</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">form</span> <span style="color: red;">id</span><span style="color: blue;">="form1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="lblDataDisplay"></span>Display Data From
Database<span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="DisplayDBData"></span> <span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">br</span><span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="lblExcelDisplay"></span>Display Data From
Excel<span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="DisplayExcelData"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">br</span><span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="Label1"></span>Display Data Difference
Between Database and Excel<span style="color: blue;"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span> <span style="color: red;">runat</span><span style="color: blue;">="server"</span> <span style="color: red;">ID</span><span style="color: blue;">="DisplayDifferenceData"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">My Code behind file looks like below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections.Generic;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Configuration;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Data;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Linq;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.Security;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.HtmlControls;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.WebControls.WebParts;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Data;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Data.Sql;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Data.SqlClient;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Data.OleDb;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> GridBind<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> : System.Web.UI.<span style="color: #2b91af;">Page<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Page Load method<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="sender"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="e"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">protected</span>
<span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Get
data from UserData Table from DB<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span>
ds = GetUserData();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Assign
the data to the first gridview<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>DisplayDBData.DataSource = ds;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>DisplayDBData.DataBind();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DataSet</span>
dataSet;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Get
data from Excel data source and bind it to second gridview<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span>
oleDbConnection = GetDataFromExcel(<span style="color: blue;">out</span>
dataSet);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>DisplayExcelData.DataSource = dataSet.Tables[0];<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>DisplayExcelData.DataBind();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>oleDbConnection.Close();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Find
the difference of data and bind the data to third gridview<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">var</span>
dtAll = GetDataDifference(ds, dataSet);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>DisplayDifferenceData.DataSource =
dtAll;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>DisplayDifferenceData.DataBind();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Gets data difference between two data sets<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="ds"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="dataSet"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></span><span style="color: green;">DataTable value</span><span style="color: grey;"></returns><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 0.5in; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">DataTable</span> GetDataDifference(<span style="color: #2b91af;">DataSet</span> ds, <span style="color: #2b91af;">DataSet</span>
<span style="mso-spacerun: yes;"> </span>dataSet)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Query
first dataset<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">IEnumerable</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><<span style="color: #2b91af;">DataRow</span>> query1 = <span style="color: blue;">from</span> userData <span style="color: blue;">in</span>
ds.Tables[0].AsEnumerable()<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span>
userData;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Query
second dataset<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: #2b91af; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">IEnumerable</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><<span style="color: #2b91af;">DataRow</span>> query2 = <span style="color: blue;">from</span> userData <span style="color: blue;">in</span>
dataSet.Tables[0].AsEnumerable()<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">select</span>
userData;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Create
data tables and get the data from above queries<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DataTable</span>
userData1 = query1.CopyToDataTable();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DataTable</span>
userData2 = query2.CopyToDataTable();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//Now use Except operator to
find the data in first set and not in second<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">var</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> userDataFirstSet =
userData1.AsEnumerable().Except(userData2.AsEnumerable(),<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">
</span><span style="color: #2b91af;">DataRowComparer</span>.Default);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Find
data in second and not in first<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">var</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> userDataSecondSet =
userData2.AsEnumerable().Except(userData1.AsEnumerable(),<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;">
</span><span style="color: #2b91af;">DataRowComparer</span>.Default);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: green;">//Create
a new data table and add new columns<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DataTable</span>
dtAll = <span style="color: blue;">new</span> <span style="color: #2b91af;">DataTable</span>();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dtAll.Columns.Add(<span style="color: blue;">new</span> <span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Name"</span>, <span style="color: blue;">typeof</span>
(<span style="color: blue;">string</span>)));<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dtAll.Columns.Add(<span style="color: blue;">new</span> <span style="color: #2b91af;">DataColumn</span>(<span style="color: #a31515;">"Password"</span>, <span style="color: blue;">typeof</span>
(<span style="color: blue;">string</span>)));<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//Bind the data from both
user data sets and add it to the datatable<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">foreach</span>
(<span style="color: blue;">var</span> dataRow <span style="color: blue;">in</span>
userDataFirstSet)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DataRow</span>
dr = dtAll.NewRow();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dr[0] = dataRow[0];<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dr[1] = dataRow[1];<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dtAll.Rows.Add(dr);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">foreach</span>
(<span style="color: blue;">var</span> dataRow <span style="color: blue;">in</span>
userDataSecondSet)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DataRow</span>
dr = dtAll.NewRow();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dr[0] = dataRow[0];<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dr[1] = dataRow[1];<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dtAll.Rows.Add(dr);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span>
dtAll;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Method to get data from excel document<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="dataSet"></param><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">private</span>
<span style="color: blue;">static</span> <span style="color: #2b91af;">OleDbConnection</span>
GetDataFromExcel(<span style="color: blue;">out</span> <span style="color: #2b91af;">DataSet</span>
dataSet)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">OleDbConnection</span>
oleDbConnection;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">//Since I am using excel
2007, I have to specify the OLEDB connector for 2007</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">OleDbDataAdapter</span>
oleDbDataAdapter;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>oleDbConnection =<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">new</span>
<span style="color: #2b91af;">OleDbConnection</span>(<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@"provider=Microsoft.ACE.OLEDB.12.0;Data
Source='c: \UserData.xlsx';Extended Properties=Excel 12.0;"</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">oleDbDataAdapter = <span style="color: blue;">new</span> <span style="color: #2b91af;">OleDbDataAdapter</span>(<span style="color: #a31515;">"select rtrim(ltrim(name)) as [Name],rtrim(ltrim(password))
as [Password] from [Sheet1$]"</span>, oleDbConnection);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>oleDbDataAdapter.TableMappings.Add(<span style="color: #a31515;">"Table"</span>, <span style="color: #a31515;">"ExcelTable"</span>);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>dataSet = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataSet</span>();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>oleDbDataAdapter.Fill(dataSet);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span>
oleDbConnection;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> Method to get data from database<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">private</span>
<span style="color: blue;">static</span> <span style="color: #2b91af;">DataSet</span>
GetUserData()<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">SqlConnection</span>
sqlConnection = <span style="color: blue;">new</span> <span style="color: #2b91af;">SqlConnection</span>();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sqlConnection.ConnectionString =<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt 1in; mso-layout-grid-align: none;">
<span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">"Data
Source=(local);Initial Catalog=MyTestDB;Persist Security Info=True;User ID=userid;Password=password;Pooling=False"</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">SqlCommand</span>
sqlCommand = <span style="color: blue;">new</span> <span style="color: #2b91af;">SqlCommand</span>();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sqlCommand.Connection =
sqlConnection;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sqlCommand.CommandType = <span style="color: #2b91af;">CommandType</span>.StoredProcedure;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sqlCommand.CommandText = <span style="color: #a31515;">"GetUserData"</span>;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>sqlConnection.Open();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">SqlDataAdapter</span>
adapter = <span style="color: blue;">new</span> <span style="color: #2b91af;">SqlDataAdapter</span>(sqlCommand);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">DataSet</span>
ds = <span style="color: blue;">new</span> <span style="color: #2b91af;">DataSet</span>();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>adapter.Fill(ds);<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">return</span>
ds;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now let us run our code and see the output:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:wrapblock><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f"><span style="font-family: Calibri;">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
<span style="font-family: Times New Roman;"><span id="lblDataDisplay">Display Data From Database</span></span></o:lock></v:path></v:stroke></span></v:shapetype><span style="font-family: Calibri;"></span></o:wrapblock><span style="font-family: Calibri;"></span></div>
<span style="font-family: Calibri;"><div>
<table border="1" cellspacing="0" id="DisplayDBData" rules="all" style="border-collapse: collapse;"><tbody>
<tr><th scope="col">Name</th><th scope="col">Password</th></tr>
<tr><td>abc</td><td>123</td></tr>
<tr><td>xyz</td><td>321</td></tr>
<tr><td>NNN</td><td>789</td></tr>
<tr><td>PPP</td><td>8998</td></tr>
</tbody></table>
</div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<div>
<span id="lblExcelDisplay">Display Data From Excel</span><br /><div>
<table border="1" cellspacing="0" id="DisplayExcelData" rules="all" style="border-collapse: collapse;"><tbody>
<tr><th scope="col">Name</th><th scope="col">Password</th></tr>
<tr><td>abc</td><td>123</td></tr>
<tr><td>xyz</td><td>321</td></tr>
<tr><td>asas</td><td>856</td></tr>
<tr><td>jklo</td><td>854</td></tr>
</tbody></table>
</div>
</div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<div>
<span id="Label1">Display Data Difference Between Database and Excel</span><br /><div>
<table border="1" cellspacing="0" id="DisplayDifferenceData" rules="all" style="border-collapse: collapse;"><tbody>
<tr><th scope="col">Name</th><th scope="col">Password</th></tr>
<tr><td>NNN</td><td>789</td></tr>
<tr><td>PPP</td><td>8998</td></tr>
<tr><td>asas</td><td>856</td></tr>
<tr><td>jklo</td><td>854</td></tr>
</tbody></table>
</div>
</div>
</span><div>
<div>
<br clear="ALL" style="mso-ignore: vglayout;" /><span style="font-family: Calibri;">
<o:p></o:p></span></div>
</div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;"><span style="mso-no-proof: yes;">You can extend or change the
program with more efficient code. This article was written by keeping in mind
the first time programmers.</span><o:p></o:p></span></div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-37147612971762557542012-08-18T19:18:00.000-04:002012-09-02T17:08:11.300-04:00Displaying rows as columns with total displayed on each row and column<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
<div class="MsoNormal">
<b>Scenario:<o:p></o:p></b></div>
<div class="MsoNormal">
I have a table with the following columns as below:<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">CREATE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">TABLE</span>
[dbo]<span style="color: grey;">.</span>[TimeLogging]<span style="color: grey;">(<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> [ID] [int] <span style="color: grey;">NOT</span>
<span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> [Date] [date] <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> [timelogged] [decimal]<span style="color: grey;">(</span>18<span style="color: grey;">,</span> 2<span style="color: grey;">)</span> <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> [username] [varchar]<span style="color: grey;">(</span>50<span style="color: grey;">)</span> <span style="color: grey;">NULL,<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">CONSTRAINT</span>
[PK_TimeLogging] <span style="color: blue;">PRIMARY</span> <span style="color: blue;">KEY</span> <span style="color: blue;">CLUSTERED</span> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> [ID] <span style="color: blue;">ASC<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">WITH </span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">PAD_INDEX</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">=</span> <span style="color: blue;">OFF</span><span style="color: grey;">,</span> <span style="color: blue;">STATISTICS_NORECOMPUTE</span> <span style="color: grey;">=</span> <span style="color: blue;">OFF</span><span style="color: grey;">,</span> <span style="color: blue;">IGNORE_DUP_KEY</span> <span style="color: grey;">=</span> <span style="color: blue;">OFF</span><span style="color: grey;">,</span> <span style="color: blue;">ALLOW_ROW_LOCKS</span>
<span style="color: grey;">=</span> <span style="color: blue;">ON</span><span style="color: grey;">,</span> <span style="color: blue;">ALLOW_PAGE_LOCKS</span> <span style="color: grey;">=</span> <span style="color: blue;">ON</span><span style="color: grey;">)</span> <span style="color: blue;">ON</span> [PRIMARY]<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">)</span><span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">ON</span> [PRIMARY]<o:p></o:p></span></div>
<div class="MsoNormal">
I have data something as below:<o:p></o:p></div>
<div class="MsoNormal">
ID Date timelogged username<o:p></o:p></div>
<div class="MsoNormal">
1 2012-10-08 5.50 Ravi<o:p></o:p></div>
<div class="MsoNormal">
2 2012-11-08 2.30 Ravi<o:p></o:p></div>
<div class="MsoNormal">
3 2012-10-08 3.30 Joe<o:p></o:p></div>
<div class="MsoNormal">
4 2012-11-08 7.30 Joe<o:p></o:p></div>
<div class="MsoNormal">
5 2012-11-09 8.30 Marie<o:p></o:p></div>
<div class="MsoNormal">
6 2012-12-05 99.90 John<o:p></o:p></div>
<div class="MsoNormal">
7 2009-06-09 78.78 Kelly<o:p></o:p></div>
<div class="MsoNormal">
<b>Problem Statement:</b>
I want this data to be displayed with all the user names as columns in the
results with unique date displayed in each row and show the total on each row
and column. The output should be as below:<o:p></o:p></div>
<div class="MsoNormal">
Date Ravi Marie Kelly John Joe Total<o:p></o:p></div>
<div class="MsoNormal">
06/09/2009 0.00 0.00 78.78 0.00 0.00 78.78<o:p></o:p></div>
<div class="MsoNormal">
10/08/2012 5.50 0.00 0.00 0.00 3.30 8.80<o:p></o:p></div>
<div class="MsoNormal">
11/08/2012 2.30 0.00 0.00 0.00 7.30 9.60<o:p></o:p></div>
<div class="MsoNormal">
11/09/2012 0.00 8.30 0.00 0.00 0.00 8.30<o:p></o:p></div>
<div class="MsoNormal">
12/05/2012 0.00 0.00 0.00 99.90 0.00 99.90<o:p></o:p></div>
<div class="MsoNormal">
Total 7.80 8.30 78.78 99.90 10.60 205.38<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b>Solution:<o:p></o:p></b></div>
<div class="MsoNormal">
You can uncomment the SELECT statement to check what is
happening at each step. We are going to user Dynamic SQL for displaying the
data. Feel free to uncomment anytime in the query and see what is happening.<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @Count <span style="color: blue;">INT</span>
<span style="color: grey;">=</span> 1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxCount <span style="color: blue;">INT</span>
<span style="color: grey;">=</span> 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">---TABLE TO STORE THE USERNAMES IN A SEPERATE TABLE VARIABLE<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @ColumnNames <span style="color: blue;">Table<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> ID <span style="color: blue;">INT</span> <span style="color: blue;">PRIMARY</span> <span style="color: blue;">KEY</span> <span style="color: blue;">IDENTITY</span><span style="color: grey;">(</span>1<span style="color: grey;">,</span>1<span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> ColumnName <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span>50<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--INSERT THE USERNAMES IN TO THE TABLE VARIABLE<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--YOU CAN UNCOMMENT THE BELOW SELECT STATEMENTS TO SEE WHAT IS HAPPENING<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">INSERT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">INTO</span>
@ColumnNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">DISTINCT</span>
username <span style="color: blue;">FROM</span> [dbo]<span style="color: grey;">.</span>[TimeLogging]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxCount <span style="color: grey;">=</span>
<span style="color: magenta;">@@ROWCOUNT</span><span style="color: green;">--COLLECT
MAXIMUM OF USER NAMES COUNT<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @MaxCount<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT * FROM @ColumnNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--CREATE A TEMP TABLE WHERE WE ARE GOING TO STORE THE DATA<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--INITIALLY CREATE A TABLE WITH ONLY TWO COLUMNS<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">CREATE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">TABLE</span>
#Temp<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> ID <span style="color: blue;">INT</span> <span style="color: blue;">PRIMARY</span> <span style="color: blue;">KEY</span> <span style="color: blue;">IDENTITY</span><span style="color: grey;">(</span>1<span style="color: grey;">,</span>1<span style="color: grey;">),<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> [Date] <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span>50<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--alter TABLE #Temp add [bubai] decimal(18,2)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--NOW WE NEED TO ADD ALL THE USERNAMES AS COLUMNS IN THE #TEMP TABLE<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SQL <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @ColumnName <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span>50<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--LOOP THRU THE USERNAMES<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">WHILE</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@Count <span style="color: grey;"><=</span> @MaxCount<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">BEGIN<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">SET</span> @SQL <span style="color: grey;">=</span> <span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">--GETTING USERNAMES ONE BY ONE<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">SELECT</span> @ColumnName <span style="color: grey;">=</span>
Columnname <span style="color: blue;">FROM</span> @ColumnNames <span style="color: blue;">where</span> ID <span style="color: grey;">=</span> @Count<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">--NOW CREATING A ALTER STATEMENT TO ADD A NEW COLUMN WITH
USERNAME<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">SET</span> @SQL <span style="color: grey;">=</span> <span style="color: red;">'alter TABLE #Temp add ['</span><span style="color: grey;">+</span>@ColumnName<span style="color: grey;">+</span><span style="color: red;">'] decimal(18,2) default 0'<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">Exec</span><span style="color: grey;">(</span>@SQL<span style="color: grey;">)</span><span style="color: green;">--EXECUTE THE ALTER
STATEMENT<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">SET</span> @Count <span style="color: grey;">=</span> @Count<span style="color: grey;">+</span>1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">END<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT * FROM #Temp--UNCOMMENT THIS TO CHECK THE COLUMNS NOW<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SET</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SQL <span style="color: grey;">=</span> <span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @ColumnNameslist <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)=</span><span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @ColumnNameslist <span style="color: grey;">=</span> <span style="color: red;">'['</span><span style="color: grey;">+</span>ColumnName<span style="color: grey;">+</span><span style="color: red;">']'</span> <span style="color: grey;">+</span> <span style="color: red;">','</span><span style="color: grey;">+</span>@ColumnNameslist <span style="color: blue;">FROM</span>
@ColumnNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @ColumnNameslist <span style="color: grey;">=</span> <span style="color: grey;">LEFT(</span>@ColumnNameslist<span style="color: grey;">,</span> <span style="color: magenta;">LEN</span><span style="color: grey;">(</span>@ColumnNameslist<span style="color: grey;">)</span> <span style="color: grey;">-</span> 1<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @ColumnNameslist --NOW WE ARE CREATING COLUMN NAMES LIST<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @AnotherColumnNamesList <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)=</span><span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @AnotherColumnNamesList <span style="color: grey;">=</span> <span style="color: red;">'ISNULL(['</span><span style="color: grey;">+</span>ColumnName<span style="color: grey;">+</span><span style="color: red;">'],0)'</span> <span style="color: grey;">+</span> <span style="color: red;">','</span><span style="color: grey;">+</span>@AnotherColumnNamesList <span style="color: blue;">FROM</span>
@ColumnNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @AnotherColumnNamesList <span style="color: grey;">=</span> <span style="color: grey;">LEFT(</span>@AnotherColumnNamesList<span style="color: grey;">,</span> <span style="color: magenta;">LEN</span><span style="color: grey;">(</span>@AnotherColumnNamesList<span style="color: grey;">)</span>
<span style="color: grey;">-</span> 1<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @AnotherColumnNamesList--ANOTHER COLUMN LIST<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--THESE TWO COLUMN LISTS ARE USED TO BUILD THE PIVOT SQL STATEMENT<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--BUILDING THE PIVOT TABLE AND INSERTING DATA INTO TEMP TABLES<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SQL <span style="color: grey;">=</span> <span style="color: red;">'Insert INTO #Temp ( [Date],'</span><span style="color: grey;">+</span>@ColumnNameslist<span style="color: grey;">+</span><span style="color: red;">')<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT [Date],'</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">+</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@AnotherColumnNamesList<span style="color: grey;">+</span><span style="color: red;">'<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">FROM<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT [Date],[timelogged],[username]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">FROM [dbo].[TimeLogging]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">as S<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">Pivot<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SUM([timelogged])<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">FOR username IN ('</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">+</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@ColumnNameslist<span style="color: grey;">+</span><span style="color: red;">')<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">as P'<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @SQL<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">EXEC</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@SQL<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT * FROM #Temp<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxColumnList <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)=</span><span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxColumnList <span style="color: grey;">=</span>
<span style="color: red;">'Max(['</span><span style="color: grey;">+</span>ColumnName<span style="color: grey;">+</span><span style="color: red;">']) as '</span> <span style="color: grey;">+</span> ColumnName <span style="color: grey;">+</span> <span style="color: red;">','</span><span style="color: grey;">+</span>@MaxColumnList <span style="color: blue;">FROM</span>
@ColumnNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxColumnList <span style="color: grey;">=</span>
<span style="color: grey;">LEFT(</span>@MaxColumnList<span style="color: grey;">,</span>
<span style="color: magenta;">LEN</span><span style="color: grey;">(</span>@MaxColumnList<span style="color: grey;">)</span> <span style="color: grey;">-</span> 1<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @MaxColumnList<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxColumnListGroup <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)=</span><span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxColumnListGroup <span style="color: grey;">=</span> <span style="color: red;">'Max(['</span><span style="color: grey;">+</span>ColumnName<span style="color: grey;">+</span><span style="color: red;">'])'</span><span style="color: grey;">+</span> <span style="color: red;">' + '</span><span style="color: grey;">+</span>@MaxColumnListGroup <span style="color: blue;">FROM</span>
@ColumnNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @MaxColumnListGroup <span style="color: grey;">=</span> <span style="color: grey;">LEFT(</span>@MaxColumnListGroup<span style="color: grey;">,</span> <span style="color: magenta;">LEN</span><span style="color: grey;">(</span>@MaxColumnListGroup<span style="color: grey;">)</span>
<span style="color: grey;">-</span> 1<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @MaxColumnListGroup<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DECLARE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SumColumnListGroup <span style="color: blue;">VARCHAR</span><span style="color: grey;">(</span><span style="color: magenta;">max</span><span style="color: grey;">)=</span><span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SumColumnListGroup <span style="color: grey;">=</span> <span style="color: red;">'SUM(['</span><span style="color: grey;">+</span>ColumnName<span style="color: grey;">+</span><span style="color: red;">'])'</span><span style="color: grey;">+</span> <span style="color: red;">' , '</span><span style="color: grey;">+</span>@SumColumnListGroup <span style="color: blue;">FROM</span>
@ColumnNames<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SumColumnListGroup <span style="color: grey;">=</span> <span style="color: grey;">LEFT(</span>@SumColumnListGroup<span style="color: grey;">,</span> <span style="color: magenta;">LEN</span><span style="color: grey;">(</span>@SumColumnListGroup<span style="color: grey;">)</span>
<span style="color: grey;">-</span> 1<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @SumColumnListGroup<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SET</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SQL <span style="color: grey;">=</span> <span style="color: red;">''<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> @SQL <span style="color: grey;">=</span> <span style="color: red;">'SELECT Convert(nvarchar(30),Cast([Date] as Date),101) as
Date,'</span><span style="color: grey;">+</span>@MaxColumnList<span style="color: grey;">+</span><span style="color: red;">',('</span><span style="color: grey;">+</span>@MaxColumnListGroup<span style="color: grey;">+</span><span style="color: red;">') as Total <o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">FROM #Temp <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">group by Date<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">union<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">SELECT '''</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">+</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">'Total'</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">+</span><span style="color: red; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">''', '</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">+</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@SumColumnListGroup<span style="color: grey;">+</span><span style="color: red;">',SUM('</span><span style="color: grey;">+</span><span style="color: magenta;">Replace</span><span style="color: grey;">(</span>@ColumnNameslist<span style="color: grey;">,</span><span style="color: red;">','</span><span style="color: grey;">,</span><span style="color: red;">'+'</span><span style="color: grey;">)+</span><span style="color: red;">') FROM #Temp'<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: green; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">--SELECT @SQL<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">EXEC</span><span style="color: grey; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">(</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@SQL<span style="color: grey;">)<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">drop</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">TABLE</span>
#Temp<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Run the query and the output is as below:<o:p></o:p></div>
<div class="MsoNormal">
Date Ravi Marie Kelly John Joe Total<o:p></o:p></div>
<div class="MsoNormal">
06/09/2009 0.00 0.00 78.78 0.00 0.00 78.78<o:p></o:p></div>
<div class="MsoNormal">
10/08/2012 5.50 0.00 0.00 0.00 3.30 8.80<o:p></o:p></div>
<div class="MsoNormal">
11/08/2012 2.30 0.00 0.00 0.00 7.30 9.60<o:p></o:p></div>
<div class="MsoNormal">
11/09/2012 0.00 8.30 0.00 0.00 0.00 8.30<o:p></o:p></div>
<div class="MsoNormal">
12/05/2012 0.00 0.00 0.00 99.90 0.00 99.90<o:p></o:p></div>
<div class="MsoNormal">
Total 7.80 8.30 78.78 99.90 10.60 205.38<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This query dynamically changes with the number of users
inserted into the table. You should be able to display the result in the above
format with as many users are inserted into the table.<br />
<br />
Displaying the above data in a grid view:<br />
<div _idv_element_hash="45223680" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GridBind._Default" %></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<html xmlns="http://www.w3.org/1999/xhtml" ></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<head runat="server"></div>
<div _idv_element_hash="45222240" style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<title>Untitled Page</title></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</head></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<body></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<form id="form1" runat="server"></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<div></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<asp:GridView runat="server" ID="PivotGrid"></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</asp:GridView></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</div></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</form></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</body></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</html><br />
<br style="outline: 0px;" />
Here is the code behind:<br />
<div style="outline: 0px;">
public partial class _Default : System.Web.UI.Page</div>
<div style="outline: 0px;">
{</div>
<div style="outline: 0px;">
protected void Page_Load(object sender, EventArgs e)</div>
<div style="outline: 0px;">
{</div>
<div style="outline: 0px;">
SqlConnection sqlConnection = new SqlConnection();</div>
<div style="outline: 0px;">
sqlConnection.ConnectionString =</div>
<div style="outline: 0px;">
"Data Source=(local);Initial Catalog=MyDB;Persist Security Info=True;User ID=userid;Password=password;Pooling=False";</div>
<div style="outline: 0px;">
SqlCommand sqlCommand = new SqlCommand();</div>
<div style="outline: 0px;">
<br style="outline: 0px;" /></div>
<div style="outline: 0px;">
sqlCommand.Connection = sqlConnection;</div>
<div style="outline: 0px;">
sqlCommand.CommandType = CommandType.StoredProcedure;</div>
<div style="outline: 0px;">
sqlCommand.CommandText = "DisplayPivotResults";</div>
<div style="outline: 0px;">
sqlConnection.Open();</div>
<div style="outline: 0px;">
SqlDataAdapter adapter = new SqlDataAdapter(sqlCommand);</div>
<div style="outline: 0px;">
DataSet ds = new DataSet();</div>
<div style="outline: 0px;">
</div>
<div style="outline: 0px;">
adapter.Fill(ds);</div>
<div style="outline: 0px;">
PivotGrid.DataSource = ds;</div>
<div style="outline: 0px;">
PivotGrid.DataBind();</div>
<div style="outline: 0px;">
<br style="outline: 0px;" /></div>
<div style="outline: 0px;">
}</div>
<div style="outline: 0px;">
}</div>
<div style="outline: 0px;">
<span style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; display: inline !important; float: none; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Here is the stored procedure:</span><br />
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- ================================================</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- Template generated from Template Explorer using:</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- Create Procedure (New Menu).SQL</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- Use the Specify Values for Template Parameters </div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- command (Ctrl-Shift-M) to fill in the parameter </div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- values below.</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- This block of comments will not be included in</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- the definition of the procedure.</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- ================================================</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SET ANSI_NULLS ON</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
GO</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SET QUOTED_IDENTIFIER ON</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
GO</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- =============================================</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- Author:<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span><Author,,Name></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- Create date: <Create Date,,></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- Description:<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span><Description,,></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
-- =============================================</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
CREATE PROCEDURE DisplayPivotResults</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
AS</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
BEGIN</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>-- SET NOCOUNT ON added to prevent extra result sets from</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>-- interfering with SELECT statements.</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>SET NOCOUNT ON;</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @Count INT = 1</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @MaxCount INT = 0</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @ColumnNames Table</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
(</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>ID INT PRIMARY KEY IDENTITY(1,1),</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>ColumnName VARCHAR(50)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
INSERT INTO @ColumnNames</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT DISTINCT username FROM [dbo].[TimeLogging]</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @MaxCount = @@ROWCOUNT</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @MaxCount</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT * FROM @ColumnNames</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
CREATE TABLE #Temp</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
(</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>ID INT PRIMARY KEY IDENTITY(1,1),</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>[Date] VARCHAR(50)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--alter TABLE #Temp add [bubai] decimal(18,2)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @SQL VARCHAR(max)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @ColumnName VARCHAR(50)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
WHILE(@Count <= @MaxCount)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
BEGIN</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>SET @SQL = ''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>SELECT @ColumnName = Columnname FROM @ColumnNames where ID = @Count</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>SET @SQL = 'alter TABLE #Temp add ['+@ColumnName+'] decimal(18,2) default 0'</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>Exec(@SQL)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<span class="Apple-tab-span" style="outline: 0px; white-space: pre;"></span>SET @Count = @Count+1</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
END</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT * FROM #Temp</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SET @SQL = ''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @ColumnNameslist VARCHAR(max)=''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @ColumnNameslist = '['+ColumnName+']' + ','+@ColumnNameslist FROM @ColumnNames</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @ColumnNameslist = LEFT(@ColumnNameslist, LEN(@ColumnNameslist) - 1)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @ColumnNameslist</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @AnotherColumnNamesList VARCHAR(max)=''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @AnotherColumnNamesList = 'ISNULL(['+ColumnName+'],0)' + ','+@AnotherColumnNamesList FROM @ColumnNames</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @AnotherColumnNamesList = LEFT(@AnotherColumnNamesList, LEN(@AnotherColumnNamesList) - 1)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @AnotherColumnNamesList</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @SQL = 'Insert INTO #Temp ( [Date],'+@ColumnNameslist+')</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT [Date],'+@AnotherColumnNamesList+'</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
FROM</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
(</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT [Date],[timelogged],[username]</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
FROM [dbo].[TimeLogging]</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
as S</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
Pivot</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
(</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SUM([timelogged])</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
FOR username IN ('+@ColumnNameslist+')</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
as P'</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @SQL</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
EXEC(@SQL)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT * FROM #Temp</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @MaxColumnList VARCHAR(max)=''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @MaxColumnList = 'Max(['+ColumnName+']) as ' + ColumnName + ','+@MaxColumnList FROM @ColumnNames</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @MaxColumnList = LEFT(@MaxColumnList, LEN(@MaxColumnList) - 1)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @MaxColumnList</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @MaxColumnListGroup VARCHAR(max)=''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @MaxColumnListGroup = 'Max(['+ColumnName+'])'+ ' + '+@MaxColumnListGroup FROM @ColumnNames</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @MaxColumnListGroup = LEFT(@MaxColumnListGroup, LEN(@MaxColumnListGroup) - 1)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @MaxColumnListGroup</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
DECLARE @SumColumnListGroup VARCHAR(max)=''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @SumColumnListGroup = 'SUM(['+ColumnName+'])'+ ' , '+@SumColumnListGroup FROM @ColumnNames</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @SumColumnListGroup = LEFT(@SumColumnListGroup, LEN(@SumColumnListGroup) - 1)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @SumColumnListGroup</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SET @SQL = ''</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT @SQL = 'SELECT Convert(nvarchar(30),Cast([Date] as Date),101) as Date,'+@MaxColumnList+',('+@MaxColumnListGroup+') as Total </div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
FROM #Temp </div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
group by Date</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
union</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
SELECT '''+'Total'+''', '+@SumColumnListGroup+',SUM('+Replace(@ColumnNameslist,',','+')+') FROM #Temp'</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
--SELECT @SQL</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
EXEC(@SQL)</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
drop TABLE #Temp</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<br style="outline: 0px;" /></div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
END</div>
<div style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #333333; font-size-adjust: none; font-stretch: normal; font: 13px/normal "Segoe UI", Calibri, Verdana; letter-spacing: normal; orphans: 2; outline: 0px; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
GO</div>
</div>
</div>
</div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com4tag:blogger.com,1999:blog-6469178881389701239.post-14250579918074909492012-08-06T18:16:00.004-04:002013-01-22T22:46:45.662-05:00Populating GridView in ASP.NET using LINQ and SQL Stored Procedure<br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">This article assumes that developer knows how create a web
site and reference the projects using Visual Studio 2008. This article focuses
on simple display of data in a GridView control in ASP.NET page using LinqToSql
class and by populating the data running a stored procedure.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Open Visual Studio 2008 and create a web application
project. Now go to server explorer and add a new database or open existing
database. I am using a new database for testing purpose.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f"><span style="font-family: Calibri;">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></span></v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_s1032" style="height: 155.25pt; margin-left: 0px; margin-top: 22.55pt; mso-height-percent: 0; mso-height-relative: page; mso-position-horizontal-relative: text; mso-position-horizontal: absolute; mso-position-vertical-relative: line; mso-position-vertical: absolute; mso-width-percent: 0; mso-width-relative: page; mso-wrap-distance-bottom: 0; mso-wrap-distance-left: 9pt; mso-wrap-distance-right: 9pt; mso-wrap-distance-top: 0; mso-wrap-style: square; position: absolute; visibility: visible; width: 301.45pt; z-index: -251658240;" type="#_x0000_t75"><span style="font-family: Calibri;">
<v:imagedata o:title="" src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
<w:wrap anchory="line" type="tight">
</w:wrap></v:imagedata></span></v:shape><o:p></o:p></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg417_UOzsw1szHRtK7jIdJl1-MXLvGZ_fbkILAJur_Bvw4bnclbhbtJtJmJEyY-91gqrHMpF45KGO2O1inJ-pI07qb7fYSnAstEf7wb5Kg0pcvWnb0g6bKV8PYzWDs3-MbS31iAepUjbU/s1600/image.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="164" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg417_UOzsw1szHRtK7jIdJl1-MXLvGZ_fbkILAJur_Bvw4bnclbhbtJtJmJEyY-91gqrHMpF45KGO2O1inJ-pI07qb7fYSnAstEf7wb5Kg0pcvWnb0g6bKV8PYzWDs3-MbS31iAepUjbU/s320/image.tif" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<span style="font-family: Calibri;">I name my new database as MyTestDB. Note that you need to
provide the credentials for the SQL Server you are connecting to.<o:p></o:p></span><br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now add a new table called Students by expanding the tree in
the server explorer and right click on the tables and select “Add New Table”.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:wrapblock><v:shape id="Picture_x0020_2" o:spid="_x0000_s1031" style="height: 115.5pt; margin-left: 0px; margin-top: 22.5pt; mso-height-percent: 0; mso-height-relative: page; mso-position-horizontal-relative: text; mso-position-horizontal: absolute; mso-position-vertical-relative: line; mso-position-vertical: absolute; mso-width-percent: 0; mso-width-relative: page; mso-wrap-distance-bottom: 0; mso-wrap-distance-left: 9pt; mso-wrap-distance-right: 9pt; mso-wrap-distance-top: 0; mso-wrap-style: square; position: absolute; visibility: visible; width: 194.3pt; z-index: 251659264;" type="#_x0000_t75"><span style="font-family: Calibri;">
<v:imagedata o:title="" src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png">
<w:wrap anchory="line" type="topAndBottom">
</w:wrap></v:imagedata></span></v:shape></o:wrapblock><br />
<span style="font-family: Calibri;">
<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh392j0G-nrp41hNhS98PRtpE8yvYc-8r_gKEBhUbsBlwbE9qDekEoMdqWiSQPNbe-TOKgNVYT7aBYR70ECOAv7YBp8oiGAsMR_HYYFsRqcddq0qLofwO8sUH-P_4nUIH0Icd9BHk_4QQ0/s1600/image1.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh392j0G-nrp41hNhS98PRtpE8yvYc-8r_gKEBhUbsBlwbE9qDekEoMdqWiSQPNbe-TOKgNVYT7aBYR70ECOAv7YBp8oiGAsMR_HYYFsRqcddq0qLofwO8sUH-P_4nUIH0Icd9BHk_4QQ0/s1600/image1.tif" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now define the columns to be added to the table. For
simplicity I have named the table name as “Students” and also added two columns
StudentID, StudentName. Also I have specified StudentID is a primary key column
and set the Identity property to seed by 1.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjSXX53QgI5FS3oRAvxwWHwVUbTpxQHmd_RI7hFusaJzrumjXs3Lv1JDv9ZCAiX-9aF356BT4HG-irIMDKWibBpWwqEB9BV_VZA2bJuER0VeM6XcyIWCyYgMUk5Xo_NRU1ds1jyQ1OmAE/s1600/image2.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="275" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhjSXX53QgI5FS3oRAvxwWHwVUbTpxQHmd_RI7hFusaJzrumjXs3Lv1JDv9ZCAiX-9aF356BT4HG-irIMDKWibBpWwqEB9BV_VZA2bJuER0VeM6XcyIWCyYgMUk5Xo_NRU1ds1jyQ1OmAE/s320/image2.tif" width="320" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:wrapblock></o:wrapblock><br clear="ALL" style="mso-ignore: vglayout;" />
<span style="font-family: Calibri;">
<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now save the table with name as “Students”. Right click on
the table Student and select “Show Table Data”. Add the data to the table.<o:p></o:p></span></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBF3FtNwmzkNE0iv6PA5bRS7ihN0UB986KT-UKqhxwKM0kRo1MOW-Q5Bx4qkIRkBWeTuPH0s6jj_7ZbikjmgGtE9h4a-cfb53rNDWfNJak-1VDeXMRZ2xCLEJNkiHxFI1MGhlMgKwXTf4/s1600/image3.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiBF3FtNwmzkNE0iv6PA5bRS7ihN0UB986KT-UKqhxwKM0kRo1MOW-Q5Bx4qkIRkBWeTuPH0s6jj_7ZbikjmgGtE9h4a-cfb53rNDWfNJak-1VDeXMRZ2xCLEJNkiHxFI1MGhlMgKwXTf4/s1600/image3.tif" /></a></div>
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:wrapblock></o:wrapblock><br clear="ALL" style="mso-ignore: vglayout;" />
<span style="font-family: Calibri;">
<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Note that the StudentID is a primary key with Identity set
with seed 1, you do not need to enter the value for this column. Just enter the
data for the StudentName and then click the “!” icon in the right on the top
tool bar.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<o:wrapblock><v:shape id="Picture_x0020_6" o:spid="_x0000_s1028" style="height: 210.8pt; margin-left: 13.5pt; margin-top: 24.75pt; mso-height-percent: 0; mso-height-relative: page; mso-position-horizontal-relative: text; mso-position-horizontal: absolute; mso-position-vertical-relative: line; mso-position-vertical: absolute; mso-width-percent: 0; mso-width-relative: page; mso-wrap-distance-bottom: 0; mso-wrap-distance-left: 9pt; mso-wrap-distance-right: 9pt; mso-wrap-distance-top: 0; mso-wrap-style: square; position: absolute; visibility: visible; width: 203.2pt; z-index: 251662336;" type="#_x0000_t75"><span style="font-family: Calibri;">
<v:imagedata o:title="" src="file:///C:\Users\AkkiNAnu\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png">
<w:wrap anchory="line" type="topAndBottom">
</w:wrap></v:imagedata></span></v:shape></o:wrapblock><br />
<span style="font-family: Calibri;">
<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ_I8QThkaHZrPxLNEilBaD0CbQLG2kVZVIUXLTqi0Dhbc6GG9r13sDCIGJru3I_1lXBGeFSUPLcRBgSMYAN8P5J0A_XDNWWcHVW8LqTYi-w41yvMApOEwKaAW7Yz19S_Opt4YNWcjwMU/s1600/image4.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ_I8QThkaHZrPxLNEilBaD0CbQLG2kVZVIUXLTqi0Dhbc6GG9r13sDCIGJru3I_1lXBGeFSUPLcRBgSMYAN8P5J0A_XDNWWcHVW8LqTYi-w41yvMApOEwKaAW7Yz19S_Opt4YNWcjwMU/s1600/image4.tif" /></a></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">This saves your data. The next step is to write a stored
procedure to get the data.<span style="mso-spacerun: yes;"> </span>Expand the
tree in the server explorer and right click on the “Stored Procedures” and
select option “Add New Stored Procedure” and you are shown a stored procedure
with basic syntax as below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">CREATE PROCEDURE </span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">dbo.StoredProcedure2<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: green;">/*<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: green;">(<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: green;">@parameter1 int
= 5,<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: green;">@parameter2
datatype OUTPUT<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: green;">)<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: green;">*/<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">AS<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: green;">/* SET NOCOUNT
ON */<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: blue;">RETURN<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now you need to modify the stored procedure to populate the Students
data as below:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">ALTER PROCEDURE </span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">dbo.GetStudents<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">AS<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: blue;">select </span>* <span style="color: blue;">from </span>dbo.student<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now click on “Save” button on the top to save the stored
procedure.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">We are done with the database stuff needed for this example.
Let us create a LinqToSQL class by adding new item to the web application
project.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrtifFoKofHq3AlWgaKNzqVY4-6ojvVHJinBZYl5cH5SI6NAIaILzJLwoTGXPxlZrQOvyWk1-lhr_7TThqaQe2MLhBZ-9GQ6DENFbt9pOKXy8qIkHz8mjMWh3WE_AwdVUVW1SszGMTOew/s1600/image5.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="175" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrtifFoKofHq3AlWgaKNzqVY4-6ojvVHJinBZYl5cH5SI6NAIaILzJLwoTGXPxlZrQOvyWk1-lhr_7TThqaQe2MLhBZ-9GQ6DENFbt9pOKXy8qIkHz8mjMWh3WE_AwdVUVW1SszGMTOew/s320/image5.tif" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<span style="font-family: Calibri;">
</span><span style="font-family: Calibri;">I named my DBML file as “MyTestDB.DBML” and now drag and drop
the Table and Stored procedure created in the server explorer.<o:p></o:p></span><br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKl5aUJZyxNasI2sew7zCvsVq7AEu7ka84f3pbeW_jFXz6Qhbpp3wXbfOxYD6wxXyDyEAJNNr5aOuyT2RPxmBIZE4o0SaBH0EWRz_QuTUq0cTgHXLmfO0nKCanSeWVrxutoqoCFsxdP3w/s1600/image6.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="123" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKl5aUJZyxNasI2sew7zCvsVq7AEu7ka84f3pbeW_jFXz6Qhbpp3wXbfOxYD6wxXyDyEAJNNr5aOuyT2RPxmBIZE4o0SaBH0EWRz_QuTUq0cTgHXLmfO0nKCanSeWVrxutoqoCFsxdP3w/s320/image6.tif" width="320" /></a></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br clear="ALL" style="mso-ignore: vglayout;" />
<span style="font-family: Calibri;">
<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now we are done with adding table and stored procedure. This
makes the Visual Studio generate code for you to access the table and stored
procedures in your program. You can check the code generated by opening
MyTestDB.designer.cs file which is available under MyTestDB.dbml file.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Code for stored procedure:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">[<span style="color: #2b91af;">Function</span>(Name=<span style="color: #a31515;">"dbo.GetStudents"</span>)]<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 2;"> </span><span style="color: blue;">public</span>
<span style="color: #2b91af;">ISingleResult</span><<span style="color: #2b91af;">GetStudentsResult</span>>
GetStudents()<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 2;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 3;"> </span><span style="color: #2b91af;">IExecuteResult</span>
result = <span style="color: blue;">this</span>.ExecuteMethodCall(<span style="color: blue;">this</span>, ((<span style="color: #2b91af;">MethodInfo</span>)(<span style="color: #2b91af;">MethodInfo</span>.GetCurrentMethod())));<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 3;"> </span><span style="color: blue;">return</span>
((<span style="color: #2b91af;">ISingleResult</span><<span style="color: #2b91af;">GetStudentsResult</span>>)(result.ReturnValue));<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 2;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now we need to add a gridview in default.aspx page and add
the following code in the code behind file:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">ASPX file:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="background: yellow; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-highlight: yellow; mso-no-proof: yes;"><%</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">@</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #a31515;">Page</span> <span style="color: red;">Language</span><span style="color: blue;">="C#"</span>
<span style="color: red;">AutoEventWireup</span><span style="color: blue;">="true"</span>
<span style="color: red;">CodeBehind</span><span style="color: blue;">="Default.aspx.cs"</span>
<span style="color: red;">Inherits</span><span style="color: blue;">="LinqGridView._Default"</span>
<span style="background: yellow; mso-highlight: yellow;">%><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><!</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">DOCTYPE</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">html</span> <span style="color: red;">PUBLIC</span>
<span style="color: blue;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span>
<span style="color: blue;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">xmlns</span><span style="color: blue;">="http://www.w3.org/1999/xhtml"</span>
<span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">title</span><span style="color: blue;">></span>Untitled
Page<span style="color: blue;"></</span><span style="color: #a31515;">title</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">head</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">form</span> <span style="color: red;">id</span><span style="color: blue;">="form1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span> <span style="color: red;">ID</span><span style="color: blue;">="gvStudents"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">body</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"></</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">html</span><span style="color: blue; font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;">><o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Code behind:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Configuration;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Data;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Linq;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.Security;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.HtmlControls;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Web.UI.WebControls.WebParts;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Xml.Linq;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">namespace</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> LinqGridView<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">public</span> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> : System.Web.UI.<span style="color: #2b91af;">Page<o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: #2b91af;">MyTestDBDataContext</span>
ctxt = <span style="color: blue;">new</span> <span style="color: #2b91af;">MyTestDBDataContext</span>();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">protected</span>
<span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;">if</span>
(!IsPostBack)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>gvStudents.DataSource =
ctxt.GetStudents().ToList();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>gvStudents.DataBind();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">That’s it you are done with the coding and now run the
application. You should data populated as below:<o:p></o:p></span></div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div align="center" class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; text-align: center;">
<b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">StudentID<o:p></o:p></span></b></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div align="center" class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; text-align: center;">
<b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">StudentName<o:p></o:p></span></b></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">John<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Mary<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Rahul<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Sanjay<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 5;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">5<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Priyanka<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">6<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Modi<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">In case if you want to query a particular student by stored
procedure you can write another stored procedure and drag and drop the stored
procedure on to the DBML file and you can use the stored procedure to get the
data.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">I have added a new stored procedure:<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">ALTER PROCEDURE </span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">dbo.GetStudentByID<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span>@studentId <span style="color: blue;">int <o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">AS<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-tab-count: 1;"> </span><span style="color: blue;">select </span>* <span style="color: blue;">from </span>dbo.student <span style="color: blue;">where </span>StudentID
= @studentId<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now, I have modified my aspx to include a label to display
the student name and also the code behind file.<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><</span><span style="color: #a31515; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">form</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: red;">id</span><span style="color: blue;">="form1"</span>
<span style="color: red;">runat</span><span style="color: blue;">="server"><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span> <span style="color: red;">ID</span><span style="color: blue;">="gvStudents"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">GridView</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">br</span> <span style="color: blue;">/><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"><</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span> <span style="color: red;">ID</span><span style="color: blue;">="StudentName"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></</span><span style="color: #a31515;">asp</span><span style="color: blue;">:</span><span style="color: #a31515;">Label</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">div</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Courier New"; font-size: 10pt; line-height: 107%; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span><span style="color: blue;"></</span><span style="color: #a31515;">form</span><span style="color: blue;">><o:p></o:p></span></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="color: blue; font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;">if</span><span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> (!IsPostBack)<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>{<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>gvStudents.DataSource =
ctxt.GetStudents().ToList();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>gvStudents.DataBind();<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<br /></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>StudentName.Text =
ctxt.GetStudentByID(2).ToList()[0].StudentName;<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none;">
<span style="font-family: "Courier New"; font-size: 10pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>}<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: Calibri;">Now my output is as below:<o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<table border="1" cellpadding="0" cellspacing="0" class="MsoNormalTable" style="border-collapse: collapse; mso-yfti-tbllook: 1184;">
<tbody>
<tr style="mso-yfti-firstrow: yes; mso-yfti-irow: 0;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div align="center" class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; text-align: center;">
<b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">StudentID<o:p></o:p></span></b></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div align="center" class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt; text-align: center;">
<b><span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">StudentName<o:p></o:p></span></b></div>
</td>
</tr>
<tr style="mso-yfti-irow: 1;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">1<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">John<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 2;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">2<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Mary<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 3;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">3<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Rahul<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 4;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">4<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Sanjay<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 5;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">5<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Priyanka<o:p></o:p></span></div>
</td>
</tr>
<tr style="mso-yfti-irow: 6; mso-yfti-lastrow: yes;">
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">6<o:p></o:p></span></div>
</td>
<td style="background-color: transparent; border: rgb(0, 0, 0); padding: 0.75pt;"><div class="MsoNormal" style="line-height: normal; margin: 0in 0in 0pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;">Modi<o:p></o:p></span></div>
</td>
</tr>
</tbody></table>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12pt; line-height: 107%; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 0pt; mso-ligatures: none;"><br />
Mary<o:p></o:p></span></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<br />
<div class="MsoNormal" style="margin: 0in 0in 8pt;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0tag:blogger.com,1999:blog-6469178881389701239.post-53399273918633978392012-08-05T19:42:00.001-04:002012-08-05T19:48:34.346-04:00C# Extension Methods: Explained<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<br /></div>
<div class="MsoNormal">
This article assumes that user has knowledge of C#
programming and the intention of the article is not to stress too much on
extension methods. But, to give an idea on what are extension methods, benefits
and the most important part of the article is not to reinvent the wheel by coding
the methods which are already developed and shared by other developers and
contributed for the benefit of the Microsoft development community. CodePlex
provides the source openly for the developers.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
The best resource for any of the Microsoft articles is the
MSDN and to know more about extension methods from the Microsoft words please
refer to the URL <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx">http://msdn.microsoft.com/en-us/library/bb383977.aspx</a>.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Before extension methods, we used to write our own methods
in the class whenever needed in our projects. There are many built-in functions
provided by the Microsoft .NET framework which can be used by the developers
without having them to rewrite the code for achieving basic functionality like all
primitive date types can be converted into string object using method
ToString() or to check if both the string objects are equal by Equals(0bject
object) and so on.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
<b><u>Before the
invention of extension methods:<o:p></o:p></u></b></div>
<div class="MsoNormal">
Let us see how a normal developer writes code to achieve
functionality without using the extension methods.<o:p></o:p></div>
<div class="MsoNormal">
Here in this example we look at two ways of coding:<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l2 level1 lfo1; text-indent: -.25in;">
1.<span style="font-size: 7pt;">
</span>Writing lines of code without modularity i.e.,
just writing lines of code whenever needed by duplicating the efforts when the
same code is to be used in some other module or project in the application.<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="mso-list: l2 level1 lfo1; text-indent: -.25in;">
2.<span style="font-size: 7pt;">
</span>Converting the common lines of code into a
method which can be re used whenever needed.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Create a Console application project using visual studio
2008 and modify the file Program.CS with the following code:<o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">namespace</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> ExtensionMethods<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[]
args)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">string</span>
userName = <span style="color: #a31515;">"John"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">string</span>
emptyString = <span style="color: #a31515;">""</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">int</span>?
number = 5;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">int</span>?
number2 = <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Normally
we use the following condition to check if a string<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//is not
an empty value<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"****Writing lines of code as needed on the
fly****"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(!<span style="color: blue;">string</span>.IsNullOrEmpty(userName))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"User Name is not Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"User Name is Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(!<span style="color: blue;">string</span>.IsNullOrEmpty(emptyString))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"EmptyString is not Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"EmptyString is Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Similarly
to check if an integer is null then return default value<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//else
convert the integer value to string value.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(number == <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Number is null and so it is empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Converted string value of number is {0}"</span>,
number.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(number2 == <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"number2 is null and so it is empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Converted string value of number2 is {0}"</span>,
number2.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"*************************************************"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"****Calling a method to reuse the same
code*******"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Otherwise,
we write a method that checks if the string is not null or empty<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//More
better way to write code<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"User Name is Not Empty?? {0}"</span>,
IsNotNullOrEmpty(userName));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"EmptyString is Not Empty?? {0}"</span>,
IsNotNullOrEmpty(emptyString));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Better
way to write code. Convert the lines of code into a method and call it.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"String value of number is {1}"</span>, number,
ToString(number,<span style="color: #a31515;">"empty"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"String value of number2 is {1}"</span>,
number2, ToString(number2, <span style="color: #a31515;">"empty"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"***********************************************"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.ReadLine();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> Method to check if a string is not null or empty.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="input"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">static</span> <span style="color: blue;">bool</span> IsNotNullOrEmpty(<span style="color: blue;">string</span>
input)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">return</span>
!<span style="color: blue;">string</span>.IsNullOrEmpty(input);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> Method to convert an integer value to string if it is not
null<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> otherwise return default value.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="value"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="defaultvalue"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">static</span> <span style="color: blue;">string</span> ToString(<span style="color: blue;">int</span>?
value, <span style="color: blue;">string</span> defaultvalue)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(value == <span style="color: blue;">null</span>) <span style="color: blue;">return</span>
defaultvalue;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">return</span>
value.Value.ToString();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
Now run the program:<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br />
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"><o:p></o:p></span></div>
<div class="MsoNormal">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxpRneQLYzMxA7nqIfpBhTPv3PWpHCt8LAYpdf8Mvtu7Oy1813wfYt4iE_xx57ozkvEgEtY8EHiKZNX4zQkCTbVxUQH4uEX1BhjRNlORrmKiZZ9P03I7f1vFqFKHXNchoPKVwo3mIfUzg/s1600/image.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="117" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxpRneQLYzMxA7nqIfpBhTPv3PWpHCt8LAYpdf8Mvtu7Oy1813wfYt4iE_xx57ozkvEgEtY8EHiKZNX4zQkCTbVxUQH4uEX1BhjRNlORrmKiZZ9P03I7f1vFqFKHXNchoPKVwo3mIfUzg/s320/image.tif" width="320" /></a></div>
<br /></div>
<div class="MsoNormal">
<b>Tip: There are two
beautiful and helpful tools provided by Microsoft for developer community to
beautify the code to make it more clean and maintainable. One is the <u>Code
Analyzer</u> and other one <u>Code Metrics</u>.</b> Always use the Code
Analyzer and Code Metrics tools in the visual studio to fine tune your code so
that your code will be clean and maintainable. You are not compelled to do all
the changes, but you can follow whenever you feel it is good to change. As a
developer, we sometimes ignore the best practices in a hurry to complete the code
with in the dead line. For example, when I run code analysis on the above
project it shows me the following warning:<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
CA1305 : Microsoft.Globalization : Because the behavior of
'int.ToString()' could vary based on the current user's locale settings,
replace this call in 'Program.ToString(int?, string)' with a call to
'int.ToString(IFormatProvider)'. If the result of
'int.ToString(IFormatProvider)' will be displayed to the user, specify
'CultureInfo.CurrentCulture' as the 'IFormatProvider' parameter. Otherwise, if
the result will be stored and accessed by software, such as when it is
persisted to disk or to a database, specify 'CultureInfo.InvariantCulture'.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Back to topic. Now in my project, I have to check the string
value and show on the UI the value if it is not empty or null otherwise, show
that it is empty. To check that we use the built-in method for string class
IsNullOrEmpty and accordingly we will display the value in the UI. Similarly, I
have a requirement that I check if a integer value is null then show it as “No
records found” in the UI or convert the integer to string and append to your
message like “5 records found”. To do this we check if a integer is null then
return a default value otherwise, convert the integer to string using method
ToString() and append to the string message you would like to show on the UI.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
<b>Note:</b> In general
you cannot assign null value to an int variable. Microsoft has introduced
nullable types in the .NET framework to support assigning null to value types. Note
that reference types already supports null values. To learn more about the
Nullable types refer to the MSDN article <a href="http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=vs.80).aspx">http://msdn.microsoft.com/en-us/library/1t3y8s4s(v=vs.80).aspx</a>.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Now what? If I have to use the same methods in different
projects, I cannot rewrite the methods in each class and so we need to place
all these methods in one place. For that we need to create a class library and
add a static class and include all these methods in the class. Then reference
these methods by adding reference to the class library project.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
<b>Note: </b>In many
projects, we name this static class as “Helper” since it helps all the projects
in providing the helpful methods in achieving the functionality. It is not
necessary that the class be a static class, but the best practices from
Microsoft says that any class that only supports some operations and does not
need to be instantiated, you can make the class as static. You can learn more
about this from the MSDN article <a href="http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx">http://msdn.microsoft.com/en-us/library/79b3xss3(v=vs.80).aspx</a>.
Also note that even if you do not create static class and instantiate every
time to call the methods, when you run the Code Analyzer tool, it suggests you
make the class as static and use the methods without instantiating the class.
See how the tool helps you even you forget something. That is the great thing
about Microsoft which is committed to make developers life easy.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
So, our next step is to create a class library project and
add a static class called “Helper.CS” and add these methods in the class. I
name my project as “Common” and modified the name of the file “Class1.CS” to “Helper.cs”.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Here is my new class:<o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">namespace</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> Common<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Helper<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> Method to check if a string is not null or empty.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="input"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">bool</span>
IsNotNullOrEmpty(<span style="color: blue;">string</span> input)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">return</span>
!<span style="color: blue;">string</span>.IsNullOrEmpty(input);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> Method to convert an integer value to string if it is not
null<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> otherwise return default value.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="value"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="defaultvalue"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">string</span>
ToString(<span style="color: blue;">int</span>? value, <span style="color: blue;">string</span>
defaultvalue)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(value == <span style="color: blue;">null</span>) <span style="color: blue;">return</span>
defaultvalue;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">return</span>
value.Value.ToString();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now add the project reference to the Common project from
ExtensionMethods Console application and modify your “Program.cs” to add the
reference and use the Helper class methods.<o:p></o:p></div>
<div class="MsoNormal">
Here is my changed code:<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> Common;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">namespace</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> ExtensionMethods<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Program<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">static</span> <span style="color: blue;">void</span> Main(<span style="color: blue;">string</span>[]
args)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">string</span>
userName = <span style="color: #a31515;">"John"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">string</span>
emptyString = <span style="color: #a31515;">""</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">int</span>?
number = 5;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">int</span>?
number2 = <span style="color: blue;">null</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Normally
we use the following condition to check if a string<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//is not
an empty value<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"****Writing lines of code as needed on the
fly****"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(!<span style="color: blue;">string</span>.IsNullOrEmpty(userName))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"User Name is not Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"User Name is Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(!<span style="color: blue;">string</span>.IsNullOrEmpty(emptyString))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"EmptyString is not Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"EmptyString is Empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Similarly
to check if an integer is null then return default value<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//else
convert the integer value to string value.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(number == <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Number is null and so it is empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Converted string value of number is {0}"</span>,
number.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(number2 == <span style="color: blue;">null</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"number2 is null and so it is empty"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">else<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"Converted string value of number2 is {0}"</span>,
number2.ToString());<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"*************************************************"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"****Calling a method to reuse the same
code*******"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Otherwise,
we write a function that checks if the string is not null or empty<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//More
better way to write code<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"User Name is Not Empty?? {0}"</span>, <span style="color: #2b91af;">Helper</span>.IsNotNullOrEmpty(userName));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"EmptyString is Not Empty?? {0}"</span>, <span style="color: #2b91af;">Helper</span>.IsNotNullOrEmpty(emptyString));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: green;">//Better
way to write code. Convert the lines of code into a method and call it.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"String value of number is {1}"</span>, number,
<span style="color: #2b91af;">Helper</span>.ToString(number, <span style="color: #a31515;">"empty"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"String value of number2 is {1}"</span>,
number2, <span style="color: #2b91af;">Helper</span>.ToString(number2, <span style="color: #a31515;">"empty"</span>));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.WriteLine(<span style="color: #a31515;">"***********************************************"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: #2b91af;">Console</span>.ReadLine();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
I am done now. Now I have created a separate class library
project and I am able to reference the common methods used by any of the
projects with in the solution with no much efforts. Even, I am following the
best standards of making the class as static and referring to the methods
without instantiating the class thus avoiding the memory issues too. Then why
do I need extension methods? I am happy with the code in my project and it was
deployed in production and it is performing well.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
One fine day, another developer who is new to the project or
imagine a developer who is new to C# coding itself have joined in your team. What
he visualizes is that Microsoft’s tool for .NET so called the “Visual Studio
2008” is so developer friendly and whenever he wants to use the built-in
methods provided by the framework, he just have to put “.” after the variable
and it shows all the methods and properties supported. You might have told him
that you did a great job by adding all the common methods in the static class “Helper”
and he can use that whenever he has to write the similar kind of functionality.
But he may miss that part and plans to reinvent the wheel by writing his own
methods in the code. (This happened in one of my projects and believe me, when
that developer left the team it took lot of efforts in changing his code to
avoid the redundancy). So, how easy it would have been when he put “.” after
the variable, the intellisense have shown him the methods that I have placed in
the Helper file for the same purpose? Definitely, it would have made everyone’s
life easy. Most of the projects have these kind of code integration issues.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Here are the reasons why I go for extension methods:<o:p></o:p><br />
<br /></div>
<div class="MsoListParagraphCxSpFirst" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
-<span style="font-size: 7pt;"> </span>Extension methods helps to add methods to
existing types without creating a new derived types.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
-<span style="font-size: 7pt;">
</span>If I am using a Third party library file in my
project and I do not have source code available for the library, the best thing
is to extend the existing types and write your own methods without
understanding their code.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
-<span style="font-size: 7pt;">
</span>It makes developer’s life easy to check what are
all the methods supported by the type variable he is using at one place instead
of searching in the project for the similar kind of method.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
-<span style="font-size: 7pt;">
</span>It helps the first time programmers concentrate
on building the solution without much emphasizing on how to write that
functionality in a separate methods explicitly.<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
-<span style="font-size: 7pt;">
</span>Main point being I do not want to differentiate
between my own methods and the built-in methods provided by the framework.<o:p></o:p><br />
<br /></div>
<div class="MsoListParagraphCxSpMiddle" style="mso-list: l0 level1 lfo2; text-indent: -.25in;">
-<span style="font-size: 7pt;">
</span>With extension methods, now you can add
supported methods to values types which could not have been possible without it.
For example, I have a variable of type double and I want to calculate the
percentage of the value or any other functionality and if I check the
operations supported, they are only few as below:<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
<table align="left" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td height="0" width="132"></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHpzCPNQqmlcTxIsuYvd5rd6eZo0LS-TGXc5apgoIa7wekgScdod0UBEK8cK-Tuhg_dJFMOs3qXb-XQqqWlbf9Q_vTFzTRXkLlvmzIBbPkhFLyw-4liEEJFz7WBraxh0cdGH7Jpsboc3o/s1600/image.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHpzCPNQqmlcTxIsuYvd5rd6eZo0LS-TGXc5apgoIa7wekgScdod0UBEK8cK-Tuhg_dJFMOs3qXb-XQqqWlbf9Q_vTFzTRXkLlvmzIBbPkhFLyw-4liEEJFz7WBraxh0cdGH7Jpsboc3o/s1600/image.tif" /></a></div>
<br />
<o:p></o:p></div>
<div class="MsoListParagraphCxSpMiddle">
I would like to extend the methods that are
supported by the variable of type Double. You cannot do it in simple way
without using extension methods.<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast">
<br /></div>
<div class="MsoNormal">
<b><u>Hi to Extension
methods:<o:p></o:p></u></b></div>
<div class="MsoListParagraph">
<br /></div>
<div class="MsoNormal">
The basic steps needed to write extension methods are as
below:<o:p></o:p></div>
<div class="MsoListParagraphCxSpFirst" style="margin-left: .75in; mso-add-space: auto; mso-list: l1 level1 lfo3; text-indent: -.25in;">
1.<span style="font-size: 7pt;">
</span>You have to include the “<b>This” </b>keyword as the first parameter in the extension method
parameter list preceded by the variable type that you are extending.<o:p></o:p></div>
<div class="MsoListParagraphCxSpLast" style="margin-left: .75in; mso-add-space: auto; mso-list: l1 level1 lfo3; text-indent: -.25in;">
2.<span style="font-size: 7pt;">
</span>Make the extension method as static. <o:p></o:p></div>
<div class="MsoNormal">
That’s it and you are done with the extension methods for
the types used in your project.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
Now, I am going to modify the static helper class to make
the methods as extension methods. My Helper class now looks like below:<o:p></o:p><br />
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">using</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> System.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">namespace</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> Common<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Helper<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> Method to check if a string is not null or empty.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="input"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">bool</span>
IsNotNullOrEmpty(<b><span style="color: blue;">this</span></b> <span style="color: blue;">string</span> input)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">return</span>
!<span style="color: blue;">string</span>.IsNullOrEmpty(input);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> Method to convert an integer value to string if it is not
null<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> otherwise return default value.<o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"></summary><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="value"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><param
name="defaultvalue"></param><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: grey;">///</span><span style="color: green;"> </span><span style="color: grey;"><returns></returns><o:p></o:p></span></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">public</span> <span style="color: blue;">static</span> <span style="color: blue;">string</span>
ToString(<b><span style="color: blue;">this</span></b>
<span style="color: blue;">int</span>? value, <span style="color: blue;">string</span>
defaultvalue)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">if</span>
(value == <span style="color: blue;">null</span>) <span style="color: blue;">return</span>
defaultvalue;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> <span style="color: blue;">return</span>
value.Value.ToString();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFoIQU9r5Pa_sTFyvMiPnXEjj2RMYKzRgwKubvFx42ynRLAsVYEZ8ouyDosNMpzSqKUTHzI5E33naKQ8YfSyQX_YaQ4BWnhsNDTV5pgN0YNrF2TXKKp5C9DyMWkAI2esoDT6-RcT-t8d4/s1600/image.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFoIQU9r5Pa_sTFyvMiPnXEjj2RMYKzRgwKubvFx42ynRLAsVYEZ8ouyDosNMpzSqKUTHzI5E33naKQ8YfSyQX_YaQ4BWnhsNDTV5pgN0YNrF2TXKKp5C9DyMWkAI2esoDT6-RcT-t8d4/s320/image.tif" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhalqp-RpPB5e90ixiGZ5k8S5ZT0uty-pop4_gAiq6mOeUL5UgPptHXltUbxwCgqjkv2D9eZJpcjNqoCN6PqZuv61NwwFE7gtjy6lXi7KJWi0JZmSUYBWAID8UJ8Az5aWaT3vLMHel7x2c/s1600/image1.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="52" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhalqp-RpPB5e90ixiGZ5k8S5ZT0uty-pop4_gAiq6mOeUL5UgPptHXltUbxwCgqjkv2D9eZJpcjNqoCN6PqZuv61NwwFE7gtjy6lXi7KJWi0JZmSUYBWAID8UJ8Az5aWaT3vLMHel7x2c/s320/image1.tif" width="320" /></a></div>
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Courier New"; font-size: 10.0pt; mso-font-kerning: 0pt; mso-no-proof: yes;">}<o:p></o:p></span></div>
<div class="MsoNormal">
Now go to Program.cs file and try to check the methods
supported by the types we have used earlier. You find that they support the
methods that are defined in the helper class.<o:p></o:p></div>
<div class="MsoNormal">
<br />
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br />
<o:p></o:p></div>
<div class="MsoNormal">
Now modify your code and run the program. You will find that
the output remained the same. But, now you are able to use the methods as if
they are supported by the framework classes itself. That is the beauty of
extension methods.<o:p></o:p></div>
<div class="MsoNormal">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeiekVMo8ReBs72EJB7TT902mob8tng2ozXLWDHTrzY5_JPx40n_vJ_u4deyBKBCY1EvUSxfk8BBqGcM83RhcCddJ2p0WiiECNqAwV21L-z-os9rXAAHy2ET7g2N36MnvvHWXjXMgEHqg/s1600/image2.tif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="117" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeiekVMo8ReBs72EJB7TT902mob8tng2ozXLWDHTrzY5_JPx40n_vJ_u4deyBKBCY1EvUSxfk8BBqGcM83RhcCddJ2p0WiiECNqAwV21L-z-os9rXAAHy2ET7g2N36MnvvHWXjXMgEHqg/s320/image2.tif" width="320" /></a></div>
<br />
<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now coming to the last section of this article, the main
intention of this article. CodePlex provides you the source code for the
already defined extension methods that are shared by the developers’ community
to help other developers. You can use these methods in your projects without
investing time on reinventing the wheel. If you have ever developed any other
methods needed for your projects, share your code here so that it would be
beneficial for other developers.<o:p></o:p><br />
<br /></div>
<div class="MsoNormal">
You can find the source code of the extension methods from
the following URLs:<o:p></o:p></div>
<div class="MsoNormal">
<a href="http://extensionoverflow.codeplex.com/SourceControl/changeset/view/53192">http://extensionoverflow.codeplex.com/SourceControl/changeset/view/53192</a><o:p></o:p></div>
<div class="MsoNormal">
<a href="http://dnpextensions.codeplex.com/SourceControl/changeset/view/69562">http://dnpextensions.codeplex.com/SourceControl/changeset/view/69562</a><o:p></o:p></div>
<div class="MsoNormal">
<a href="http://extensionmethods.codeplex.com/SourceControl/changeset/view/15132">http://extensionmethods.codeplex.com/SourceControl/changeset/view/15132</a><o:p></o:p></div>
<div class="MsoNormal">
<a href="http://dotnetext.codeplex.com/SourceControl/changeset/view/67635">http://dotnetext.codeplex.com/SourceControl/changeset/view/67635</a>
<o:p></o:p></div>
<div class="MsoNormal">
<a href="http://extensionmethodsyay.codeplex.com/SourceControl/changeset/view/18197">http://extensionmethodsyay.codeplex.com/SourceControl/changeset/view/18197</a><o:p></o:p></div>Akkihttp://www.blogger.com/profile/00145294326045609518noreply@blogger.com0