tag:blogger.com,1999:blog-8160272272562546772024-03-21T13:14:55.188-07:00Sql Server and Asp.netSql Server and Asp.netbhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.comBlogger370125tag:blogger.com,1999:blog-816027227256254677.post-68715789945022849952019-09-08T23:32:00.001-07:002019-09-08T23:32:50.031-07:00Android Styling Radio Button<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr"></div><div><div id="m_-8214973549298581790emailbody" style="margin:0 2em;font-family:Georgia,Helvetica,Arial,Sans-Serif;line-height:140%;font-size:13px;color:#000000"><table style="border:0;padding:0;margin:0;width:100%"><tbody><tr><td style="vertical-align:top" width="99%"></td><td width="1%"><table id="m_-8214973549298581790itemcontentlist"><tbody><tr><td style="margin-bottom:0;line-height:1.4em"><p style="margin:1em 0 3px 0">Android Koltin RadioButton allows user select one option from a set , RadioButton Generally used along with RadioGroup .<br></p><div style="margin:0px;line-height:140%"><br>RadioGroup group contains multiple RadioButton , when user click one radio button that will it marked as checked and rest others are unchecked<br><br><div style="border-radius:3px 3px 3px 3px;border:1px solid #6cc;padding:8px"><h3>colorAccent </h3></div><br>To Change Radio Button Mark Color everywhere in your entire application , then change the colorAccent color of BaseTheme in style.xml<br><br><div><pre class="m_-8214973549298581790brush: m_-8214973549298581790xml"> <!-- Base application theme. --><br> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"><br> <!-- Customize your theme here. --><br> <item name="colorPrimary">@color/colorPrimary</item><br> <item name="colorPrimaryDark">@color/colorPrimaryDark</item><br> <item name="colorAccent">@color/colorAccent</item><br> </style></pre></div><br><div class="m_-8214973549298581790separator" style="clear:both;text-align:center"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8YoQRC_cWGHFdw132JgTC-MGr8phWIvrTAKlmOwimo5mEvSGjj8P12Gre_VdEDjKECBlUcsQy86bNsSUxIr5muO8LZZv4gGVGYNjLXqUBrfSAuWy9egqXyjR8uw6jWegAyKp1KbXp3-k/s1600/android_radio_button_01.png" style="margin-left:1em;margin-right:1em" target="_blank" rel="noreferrer"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg8YoQRC_cWGHFdw132JgTC-MGr8phWIvrTAKlmOwimo5mEvSGjj8P12Gre_VdEDjKECBlUcsQy86bNsSUxIr5muO8LZZv4gGVGYNjLXqUBrfSAuWy9egqXyjR8uw6jWegAyKp1KbXp3-k/s1600/android_radio_button_01.png"></a></div><br><div style="border-radius:3px 3px 3px 3px;border:1px solid #6cc;padding:8px"><h3>Particular Radio Button </h3></div><br> When you want to particular Radio Button then create your own style and extend it to <b>Widget.AppCompat.CompoundButton.RadioButton</b> Add items to style .<br><ol><li><b>colorControlNormal</b> controls the 'normal' state of components such as an unselected EditText, and unselected Checkboxes and RadioButtons</li><li><b>colorControlActivated</b> overrides colorAccent as the activated or checked state for Checkboxes and RadioButtons</li><li><b>colorControlHighlight</b> controls the ripple coloring .</li></ol><div><pre class="m_-8214973549298581790brush: m_-8214973549298581790xml"><style name="CustomRadioTheme" parent="Widget.AppCompat.CompoundButton.RadioButton"><br> <item name="android:colorControlNormal">#7a7a7a</item><br> <item name="android:colorControlActivated">#FF9800</item><br> <item name="android:colorControlHighlight">#FF9800</item><br></style></pre></div><br><div class="m_-8214973549298581790separator" style="clear:both;text-align:center"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM1JuXcFk1nX9fh0DokBfBBRgYdpliVktThE-HkuyFra7FV7hp5WfDiskv-ewQpLQ6VQjE9BWp6_W1Hmr1w0moJqZLrhslvuoXzu-lkVCr0cu96fhH5MJwIqtvTSSeCb7gRtHy2g7N_eM/s1600/android_radio_button_02.png" style="margin-left:1em;margin-right:1em" target="_blank" rel="noreferrer"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiM1JuXcFk1nX9fh0DokBfBBRgYdpliVktThE-HkuyFra7FV7hp5WfDiskv-ewQpLQ6VQjE9BWp6_W1Hmr1w0moJqZLrhslvuoXzu-lkVCr0cu96fhH5MJwIqtvTSSeCb7gRtHy2g7N_eM/s1600/android_radio_button_02.png"></a></div><br><div><pre class="m_-8214973549298581790brush: m_-8214973549298581790xml;highlight:[4]"><RadioGroup<br> android:layout_width="match_parent"<br> android:layout_height="wrap_content"<br> android:theme="@style/CustomRadioTheme"<br> android:id="@+id/radio_grp"><br><br> <RadioButton;<br> android:layout_width="wrap_content"<br> android:layout_height="wrap_content"<br> android:text="option 1"<br> android:textSize="16sp"/><br><br> <RadioButton<br> android:layout_width="wrap_content"<br> android:layout_height="wrap_content"<br> android:text="option 2"<br> android:textSize="16sp"/><br><br> <RadioButton<br> android:layout_width="wrap_content"<br> android:layout_height="wrap_content"<br> android:text="option 2"<br> android:textSize="16sp"/><br><br></RadioGroup></pre></div></div></td></tr></tbody></table></td></tr></tbody></table> </div> </div> </div></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-40873748587188941412019-09-08T23:27:00.001-07:002019-09-08T23:28:54.214-07:00Android Kotlin SwitchCompat (on/off) Button<div dir="auto"><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr"></div><div dir="auto"><div class="gmail_quote" dir="auto"><div><div id="m_8187481599334750267m_4813894860216799011emailbody" style="margin:0 2em;font-family:Georgia,Helvetica,Arial,Sans-Serif;line-height:140%;font-size:13px;color:#000000"><table style="border:0;padding:0;margin:0;width:100%"><tbody><tr><td style="vertical-align:top" width="99%"></td><td width="1%"><table id="m_8187481599334750267m_4813894860216799011itemcontentlist"><tbody><tr><td style="margin-bottom:0;line-height:1.4em"><p style="margin:1em 0 3px 0">A Switch is a two-state toggle switch widget that can select between two options. The user may drag the "thumb" back and forth to choose the selected option, or simply tap to toggle<br></p><div style="margin:0px;line-height:140%"><br>SwitchCompat is a version of the Switch widget which runs on devices back to API 7.<br><br>Android Switch and ToggleButton both are the subclasses of CompoundButton class.<br><br>Lets see a sample example .<br><br><div style="border-radius:3px 3px 3px 3px;border:1px solid #6cc;padding:8px"><h3> XML Layout</h3></div><ol><li>Create XML Layout activity_main.xml , this will be set as content view for launcher Activity (MainActivity.kt)</li><li>Added Seekbar To the xml layout .</li></ol><b>file : activity_main.xml</b><br><div><pre class="m_8187481599334750267m_4813894860216799011brush: m_8187481599334750267m_4813894860216799011xml m_8187481599334750267m_4813894860216799011; m_8187481599334750267m_4813894860216799011highlight: m_8187481599334750267m_4813894860216799011[11,12,13,14,15]"><?xml version="1.0" encoding="utf-8"?><br><LinearLayout<br> xmlns:android="<a href="http://schemas.android.com/apk/res/android" rel="noreferrer noreferrer" target="_blank">http://schemas.android.com/apk/res/android</a>"<br> xmlns:tools="<a href="http://schemas.android.com/tools" rel="noreferrer noreferrer" target="_blank">http://schemas.android.com/tools</a>"<br> android:layout_width="match_parent" android:layout_height="match_parent"<br> tools:context=".MainActivity"<br> android:padding="30dp"<br> android:orientation="vertical"<br> android:id="@+id/root"><br><br> <androidx.appcompat.widget.SwitchCompat<br> android:layout_width="match_parent"<br> android:layout_height="wrap_content"<br> android:text="Swtich Button"<br> android:id="@+id/switchCompat01"/><br><br></LinearLayout></pre></div><br><div style="border-radius:3px 3px 3px 3px;border:1px solid #6cc;padding:8px"><h3>setOnCheckedChangeListener For Switch Button</h3></div><br>setOnCheckedChangeListener is a callback that notifies swtich button is on /off<br><br><div><pre class="m_8187481599334750267m_4813894860216799011brush: m_8187481599334750267m_4813894860216799011java">switchCompat01.setOnCheckedChangeListener { buttonView, isChecked -><br> val msg: String = if (isChecked)<br> "Switch Button is Checked"<br> else<br> "Switch Button is UnChecked"<br> showToast(msg)<br> }</pre></div><br><div style="border-radius:3px 3px 3px 3px;border:1px solid #6cc;padding:8px"><h3>Activity </h3></div><br><ol><li>Create a koltin class MainActivity.kt and extend it to AppCompatActivity class .</li><li>Override onCreate function and set the content of this MainActivity with above defined xml layout (activity_main.xml).</li><li>Set the setOnCheckedChangeListener for swtich and show the status .</li></ol><br><b>file : MainActivity.kt</b><br><div><pre class="m_8187481599334750267m_4813894860216799011brush: m_8187481599334750267m_4813894860216799011java m_8187481599334750267m_4813894860216799011; m_8187481599334750267m_4813894860216799011highlight: m_8187481599334750267m_4813894860216799011[14,15,16,17,18,19,20]">package com.tutorialsbuzz.androidswtich<br><br>import android.os.Bundle<br>import android.widget.Toast<br>import androidx.appcompat.app.AppCompatActivity<br>import kotlinx.android.synthetic.main.activity_main.*<br><br>class MainActivity : AppCompatActivity() {<br><br> override fun onCreate(savedInstanceState: Bundle?) {<br> super.onCreate(savedInstanceState)<br> setContentView(R.layout.activity_main)<br><br> switchCompat01.setOnCheckedChangeListener { buttonView, isChecked -><br> val msg: String = if (isChecked)<br> "Switch Button is Checked"<br> else<br> "Switch Button is UnChecked"<br> showToast(msg)<br> }<br> }<br><br> private fun showToast(msg: String) {<br> Toast.makeText(this@MainActivity, msg, Toast.LENGTH_SHORT).show()<br> }<br>}<br></pre></div><div><br></div><br><table align="center" border="0" cellpadding="5" cellspacing="3" style="border-collapse:collapse"><tbody><tr><td><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzRhYGkRMx6_beFfYIwLpsRHpMKhZT4SZksqQlwQq4Z0IZG5fh6Gh84QaNUT9X5KRoyiIvyXAmvdsocsaOp43TG-JyXgAQM9-0hgORtsJEwWCUbdYLrof_pfYtz3abjpAtS1hsnsofH3I/s640/android_swtich_01.png" width="320"> </td><td><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjo2sp09i9hLQJdDNQAjQ8BQfkng1Wu2DvqrcT5YyOayY6Q3OQDctfMNDDqnLBJaEYOEMBXjHo1EcyotBq-2Dvz2EaVNROILWwSh6kgAE9mGzXLZPphNK7tfBpMTzfeMLEzwK843Y1dMyY/s640/android_swtich_02.png" width="320"> </td></tr></tbody></table><br><div style="background-color:#eaeae6;padding:25px;text-align:center"><b><span style="font-size:large"><a href="https://github.com/TutorialsBuzz/AndroidSwtichButton/archive/master.zip" style="background-color:#a3da5a;border-radius:10px;color:black;padding:10px" rel="noreferrer noreferrer" target="_blank">DOWNLOAD CODE </a></span></b></div><br><img src="http://feeds.feedburner.com/~r/tutorialsbuzz/~4/4tBAxiVSL8U?utm_source=feedburner&utm_medium=email" height="1" width="1" alt=""></div></td></tr></tbody></table></td></tr></tbody></table><table style="border-top:1px solid #999;padding-top:4px;margin-top:1.5em;width:100%" id="m_8187481599334750267m_4813894860216799011footer"><tbody> <tr> <td colspan="2" style="text-align:left;font-family:Helvetica,Arial,Sans-Serif;font-size:11px;margin:0 6px 1.2em 0;color:#333"><br></td> </tr> </tbody></table> </div> </div> </div></div> </div></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com2tag:blogger.com,1999:blog-816027227256254677.post-28367272368285603152016-10-25T06:05:00.001-07:002016-10-25T06:05:36.546-07:00Screenshot (25-Oct-2016 6:32:30 PM)<p class="mobile-photo"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGyrKa4GUZN58x3CtoKdA0l_8q0vydyHb8t90c49J32QOaE-hxz-cFWMdZdrI6NTfSotht3-UHHhik4Hz_I6FENeJPDNccofqj_aN3mzYf7Sl-OXyhUl1ey-E9eO2UkOE6ndyCYTNVStt-/s1600/Screenshot_20161025-183230-736547.png"><img src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGyrKa4GUZN58x3CtoKdA0l_8q0vydyHb8t90c49J32QOaE-hxz-cFWMdZdrI6NTfSotht3-UHHhik4Hz_I6FENeJPDNccofqj_aN3mzYf7Sl-OXyhUl1ey-E9eO2UkOE6ndyCYTNVStt-/s320/Screenshot_20161025-183230-736547.png" border="0" alt="" id="BLOGGER_PHOTO_ID_6345387847099054434" /></a></p> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com1tag:blogger.com,1999:blog-816027227256254677.post-40704302582207767842015-10-29T05:30:00.001-07:002016-02-20T21:43:04.519-08:00ASP.NET Interview Question<div dir="ltr" style="text-align: left;" trbidi="on">
<div style="font-family: "calibri"; font-size: 11pt; font-weight: bold; margin: 0in;">
<a href="http://asp.net/">ASP.NET</a> Life Cycle</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span style="mso-spacerun: yes;"> </span>ANS :<span style="mso-spacerun: yes;"> </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
When a visitor first requests an .aspx page on your server, the server sends it to the HTTP Pipeline. The HTTP Pipeline handles all processes involved in converting all of the application code into HTML to be interpreted by the browser. The first class initiated is called HttpRuntime. This class finds a free HttpApplication object to start processing the request. The HttpApplication object then runs the appropriate handler assigned in the web.config and machine.config files for the requested extension.</div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
The extension .aspx can be handled by the HandlerClass or HandlerFactory class. The HttpApplication objects starts the IHttpHandler interface which begins processing the application code by calling the processRequest() method.</div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
The processRequest() method then calls the FrameworkInitialize() method which begins building the control trees for the requested page. Now the processRequest() method cycles through the page's life cycle in the order listed below.</div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
Following are the page life cycle events:</div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<ul style="direction: ltr; margin-bottom: 0in; margin-left: 0.375in; margin-top: 0in;" type="disc">
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">PreInit</span><span style="font-family: "calibri"; font-size: 11pt;"> - PreInit is the first event in page life cycle. It checks the IsPostBack property and determines whether the page is a postback. It sets the themes and master pages, creates dynamic controls, and gets and sets profile property values. This event can be handled by overloading the OnPreInit method or creating a Page_PreInit handler.</span></li>
</ul>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<ul style="direction: ltr; margin-bottom: 0in; margin-left: 0.375in; margin-top: 0in;" type="disc">
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">Init</span><span style="font-family: "calibri"; font-size: 11pt;"> - Init event initializes the control property and the control tree is built. This event can be handled by overloading the OnInit method or creating a Page_Init handler.</span></li>
</ul>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<ul style="direction: ltr; margin-bottom: 0in; margin-left: 0.375in; margin-top: 0in;" type="disc">
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">InitComplete</span><span style="font-family: "calibri"; font-size: 11pt;"> - InitComplete event allows tracking of view state. All the controls turn on view-state tracking.</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">LoadViewState</span><span style="font-family: "calibri"; font-size: 11pt;"> - LoadViewState event allows loading view state information into the controls.</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">LoadPostData</span><span style="font-family: "calibri"; font-size: 11pt;"> - During this phase, the contents of all the input fields are defined with the <form> tag are processed.</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">PreLoad</span><span style="font-family: "calibri"; font-size: 11pt;"> - PreLoad occurs before the post back data is loaded in the controls. This event can be handled by overloading the OnPreLoad method or creating a Page_PreLoad handler.</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">Load</span><span style="font-family: "calibri"; font-size: 11pt;"> - The Load event is raised for the page first and then recursively for all child controls. The controls in the control tree are created. This event can be handled by overloading the OnLoad method or creating a Page_Load handler.</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">LoadComplete</span><span style="font-family: "calibri"; font-size: 11pt;"> - The loading process is completed, control event handlers are run, and page validation takes place. This event can be handled by overloading the OnLoadComplete method or creating a Page_LoadComplete handler</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">PreRender</span><span style="font-family: "calibri"; font-size: 11pt;"> - The PreRender event occurs just before the output is rendered. By handling this event, pages and controls can perform any updates before the output is rendered.</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">PreRenderComplete</span><span style="font-family: "calibri"; font-size: 11pt;"> - As the PreRender event is recursively fired for all child controls, this event ensures the completion of the pre-rendering phase. </span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">SaveStateComplete</span><span style="font-family: "calibri"; font-size: 11pt;"> - State of control on the page is saved. Personalization, control state and view state information is saved. The HTML markup is generated. This stage can be handled by overriding the Render method or creating a Page_Render handler.</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-weight: bold;">UnLoad</span><span style="font-family: "calibri"; font-size: 11pt;"> - The UnLoad phase is the last phase of the page life cycle. It raises the UnLoad event for all controls recursively and lastly for the page itself. Final cleanup is done and all resources and references, such as database connections, are freed. This event can be handled by modifying the OnUnLoad method or creating a Page_UnLoad handler</span></li>
</ul>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in; text-decoration: underline;">
What is Polymorphism</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in; text-decoration: underline;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in; text-decoration: underline;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
ANS :</div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
Polymorphism means many forms (ability to take more than one form). In Polymorphism poly means "multiple" and morph means "forms" so polymorphism means many forms. </div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
In polymorphism we will declare methods with same name and different parameters in same class or methods with same name and same parameters in different classes. Polymorphism has ability to provide different implementation of methods that are implemented with same name.</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
In Polymorphism we have 2 different types those are</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> -</span><span lang="en-US" style="font-family: "times new roman"; font-size: 7pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt; font-weight: bold;">Compile Time Polymorphism </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;">(Called as Early Binding or Overloading or static binding)</span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "verdana"; font-size: 10pt;"> -</span><span lang="en-US" style="font-family: "times new roman"; font-size: 7pt;"> </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt; font-weight: bold;">Run Time Polymorphism </span><span lang="en-US" style="font-family: "verdana"; font-size: 10pt;">(Called as Late Binding or Overriding or dynamic binding)</span></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in; text-decoration: underline;">
Compile Time Polymorphism</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">Compile time polymorphism means we will declare methods with same name but different signatures because of this we will perform different tasks with same method name. This compile time polymorphism also called as </span><span lang="en-US" style="font-weight: bold;">early binding</span><span lang="en-IN"> or </span><span lang="en-US" style="font-weight: bold;">method overloading</span><span lang="en-IN">.</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
Method Overloading or compile time polymorphism means same method names with different signatures (different parameters)</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
Example</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">public</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">class</span><span lang="en-US"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175);">Class1</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">public</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">void</span><span lang="en-US"> NumbersAdd(</span><span lang="en-US" style="color: blue;">int</span><span lang="en-US"> a, </span><span lang="en-US" style="color: blue;">int</span><span lang="en-US"> b)</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: rgb(43 , 145 , 175);">Console</span><span lang="en-US">.WriteLine(a + b);</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">public</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">void</span><span lang="en-US"> NumbersAdd(</span><span lang="en-US" style="color: blue;">int</span><span lang="en-US"> a, </span><span lang="en-US" style="color: blue;">int</span><span lang="en-US"> b, </span><span lang="en-US" style="color: blue;">int</span><span lang="en-US"> c)</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: rgb(43 , 145 , 175);">Console</span><span lang="en-US">.WriteLine(a + b + c);</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
In above class we have two methods with same name but having different input parameters this is called method overloading or compile time polymorphism or early binding. </div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in; text-decoration: underline;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in; text-decoration: underline;">
Run Time Polymorphism</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">Run time polymorphism also called as </span><span lang="en-US" style="font-weight: bold;">late binding</span><span lang="en-US"> or </span><span lang="en-US" style="font-weight: bold;">method overriding</span><span lang="en-US"> or </span><span lang="en-US" style="font-weight: bold;">dynamic polymorphism</span><span lang="en-US">. Run time polymorphism or method overriding means same method names with same signatures.</span></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">In this run time polymorphism or method overriding we can override a method in base class by creating similar function in derived class this can be achieved by using inheritance principle and using "</span><span lang="en-US" style="font-weight: bold;">virtual</span><span lang="en-IN"> & </span><span lang="en-US" style="font-weight: bold;">override</span><span lang="en-US">"</span><span lang="en-IN"> keywords.</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">In base class if we declare methods with </span><span lang="en-US" style="font-weight: bold;">virtual</span><span lang="en-IN"> keyword then only we can override those methods in derived class using </span><span lang="en-US" style="font-weight: bold;">override</span><span lang="en-IN"> keyword</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
Example</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="color: green; font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
//Base Class</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">public</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">class</span><span lang="en-US"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175);">Bclass</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">public</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">virtual</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">void</span><span lang="en-US"> Sample1()</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: rgb(43 , 145 , 175);">Console</span><span lang="en-US">.WriteLine(</span><span lang="en-US" style="color: rgb(163 , 21 , 21);">"Base Class"</span><span lang="en-US">);</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="color: green; font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
// Derived Class</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">public</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">class</span><span lang="en-US"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175);">DClass</span><span lang="en-US"> : </span><span lang="en-US" style="color: rgb(43 , 145 , 175);">Bclass</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">public</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">override</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">void</span><span lang="en-US"> Sample1()</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: rgb(43 , 145 , 175);">Console</span><span lang="en-US">.WriteLine(</span><span lang="en-US" style="color: rgb(163 , 21 , 21);">"Derived Class"</span><span lang="en-US">);</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="color: green; font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
// Using base and derived class</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">class</span><span lang="en-US"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175);">Program</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue;">static</span><span lang="en-US"> </span><span lang="en-US" style="color: blue;">void</span><span lang="en-US"> Main(</span><span lang="en-US" style="color: blue;">string</span><span lang="en-US">[] args)</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
{</div>
<div lang="en-IN" style="color: green; font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
// calling the overriden method</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: rgb(43 , 145 , 175);">DClass</span><span lang="en-US"> objDc = </span><span lang="en-US" style="color: blue;">new</span><span lang="en-US"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175);">DClass</span><span lang="en-US">();</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
objDc.Sample1();</div>
<div lang="en-IN" style="color: green; font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
// calling the base class method</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: rgb(43 , 145 , 175);">Bclass</span><span lang="en-US"> objBc = </span><span lang="en-US" style="color: blue;">new</span><span lang="en-US"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175);">DClass</span><span lang="en-US">();</span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
objBc.Sample1();</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
If we run above code we will get output like as shown below</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
Output </div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">:</span><span lang="en-US" style="color: rgb(163 , 21 , 21);">Derived Class</span></div>
<div style="color: rgb(163 , 21 , 21); font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
: Derived Class</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 16pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
Virtual Keyword</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">Virtual keyword is used for generating a virtual path for its derived classes on implementing method overriding. </span><span lang="en-US">Virtual </span><span lang="en-IN">keyword is used within a set with </span><span lang="en-US">override </span><span lang="en-IN">keyword. It is used as:</span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
// Base Class<br />
<span style="mso-spacerun: yes;"> </span>class A<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span>public virtual void show()<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span>Console.WriteLine("Hello: Base Class!");<br />
<span style="mso-spacerun: yes;"> </span>Console.ReadLine();<br />
<span style="mso-spacerun: yes;"> </span>}<br />
<span style="mso-spacerun: yes;"> </span>}</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 16pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
Override Keyword</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">Override keyword is used in the derived class of the base class in order to override the base class method. </span><span lang="en-US">Override </span><span lang="en-IN">keyword is used with </span><span lang="en-US">virtual </span><span lang="en-IN">keyword, as:</span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
// Base Class<br />
<span style="mso-spacerun: yes;"> </span>class A<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span>public virtual void show()<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span>Console.WriteLine("Hello: Base Class!");<br />
<span style="mso-spacerun: yes;"> </span>Console.ReadLine();<br />
<span style="mso-spacerun: yes;"> </span>}<br />
<span style="mso-spacerun: yes;"> </span>}<br />
<br />
// Derived Class<br />
<br />
<span style="mso-spacerun: yes;"> </span>class B : A<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span>public override void show()<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span>Console.WriteLine("Hello: Derived Class!");<br />
<span style="mso-spacerun: yes;"> </span>Console.ReadLine();<br />
<span style="mso-spacerun: yes;"> </span>}<br />
<span style="mso-spacerun: yes;"> </span>}</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
Sealed Class</div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">A </span><span lang="en-US" style="font-weight: bold;">sealed class</span><span lang="en-IN"> is a </span><span lang="en-US" style="font-weight: bold;">class</span><span lang="en-IN"> that cannot be inherited. </span><span lang="en-US" style="font-weight: bold;">Sealed classes</span><span lang="en-IN"> are used to restrict the inheritance feature of object oriented programming.</span></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;">Sealed class is used to define the inheritance level of a class.</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
The sealed modifier is used to prevent derivation from a class. An error occurs if a sealed class is specified as the base class of another class. </div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "arial"; font-size: 10pt; font-weight: bold;">Some points to remember:</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span><span lang="en-US" style="font-family: "arial"; font-size: 10pt;"> </span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">1.</span><span lang="en-US"> </span><span lang="en-IN"> A class, which restricts inheritance for security reason is declared, sealed class.</span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">2.</span><span lang="en-US"> </span><span lang="en-IN"> Sealed class is the last class in the hierarchy.</span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">3.</span><span lang="en-US"> </span><span lang="en-IN"> Sealed class can be a derived class but can't be a base class.</span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN">4.</span><span lang="en-US"> </span><span lang="en-IN"> A sealed class cannot also be an abstract class. Because abstract class has to provide functionality and here we are </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-US"> </span><span lang="en-IN"> restricting it to inherit.</span></div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
Sealed Methods</div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; font-weight: bold; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;">Sealed method is used to define the overriding level of a virtual method.</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
Sealed keyword is always used with override keyword. </div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="font-family: "arial"; font-size: 10pt; font-style: italic; font-weight: bold; margin: 0in 0in 0in 0.375in;">
Practical demonstration of sealed method</div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "arial"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue; font-family: "courier new"; font-size: 10pt;">using</span><span lang="en-US" style="font-family: "courier new"; font-size: 10pt;"> System;</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue; font-family: "courier new"; font-size: 10pt;">using</span><span lang="en-US" style="font-family: "courier new"; font-size: 10pt;"> System.Collections.Generic;</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue; font-family: "courier new"; font-size: 10pt;">using</span><span lang="en-US" style="font-family: "courier new"; font-size: 10pt;"> System.Linq;</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue; font-family: "courier new"; font-size: 10pt;">using</span><span lang="en-US" style="font-family: "courier new"; font-size: 10pt;"> System.Text;</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="color: blue; font-family: "courier new"; font-size: 10pt;">namespace</span><span lang="en-US" style="font-family: "courier new"; font-size: 10pt;"> sealed_method</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;">{</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">class</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">Program</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">public</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">class</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">BaseClass</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="font-family: "courier new"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
<span lang="en-IN"> </span><span lang="en-US"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">public</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">virtual</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">void</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> Display()</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">Console</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;">.WriteLine(</span><span lang="en-US" style="color: rgb(163 , 21 , 21); font-family: "courier new"; font-size: 10pt;">"Virtual method"</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;">);</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">public</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">class</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">DerivedClass</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> : </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">BaseClass</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">// Now the display method have been sealed and can;t be overridden</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">public</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">override</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">sealed</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">void</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> Display()</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">Console</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;">.WriteLine(</span><span lang="en-US" style="color: rgb(163 , 21 , 21); font-family: "courier new"; font-size: 10pt;">"Sealed method"</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;">);</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">//public class ThirdClass : DerivedClass</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">//{</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="color: green; font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">// public override void Display()</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">// {</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">// Console.WriteLine("Here we try again to override display method which is not possible and will give error");</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">// }</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: green; font-family: "courier new"; font-size: 10pt;">//}</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="color: green; font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">static</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">void</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> Main(</span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">string</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;">[] args)</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> {</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">DerivedClass</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> ob1 = </span><span lang="en-US" style="color: blue; font-family: "courier new"; font-size: 10pt;">new</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">DerivedClass</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;">();</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> ob1.Display();</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> </span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div style="margin: 0in 0in 0in 0.375in;">
<span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;"> </span><span lang="en-US" style="color: rgb(43 , 145 , 175); font-family: "courier new"; font-size: 10pt;">Console</span><span lang="en-IN" style="font-family: "courier new"; font-size: 10pt;">.ReadLine();</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="margin: 0in 0in 0in 0.375in;">
<span style="font-family: "courier new"; font-size: 10pt;"> }</span><span style="font-family: "calibri"; font-size: 11pt;"> </span></div>
<div lang="en-IN" style="font-family: "courier new"; font-size: 10pt; margin: 0in 0in 0in 0.375in;">
}</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 16pt; font-weight: bold; margin: 0in;">
<span lang="en-IN">Types of state management </span><span lang="en-US"> </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span lang="en-IN">There are two types of state management</span><span lang="en-US"> </span><span lang="en-IN">techniques:</span><span lang="en-US"> </span><span lang="en-IN">client side and server side.</span></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 12pt; font-weight: bold; margin: 0in;">
Client side</div>
<ol style="direction: ltr; font-family: "calibri"; font-size: 11pt; margin-bottom: 0in; margin-left: 0.375in; margin-top: 0in;" type="1">
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;" value="1"><span style="font-family: "calibri"; font-size: 11pt;">Hidden Field</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;" value="2"><span style="font-family: "calibri"; font-size: 11pt;">View State</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;" value="3"><span style="font-family: "calibri"; font-size: 11pt;">Cookies</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;" value="4"><span style="font-family: "calibri"; font-size: 11pt;">Control State</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;" value="5"><span style="font-family: "calibri"; font-size: 11pt;">Query Strings</span></li>
</ol>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 12pt; font-weight: bold; margin: 0in;">
Server side</div>
<ol style="direction: ltr; font-family: "calibri"; font-size: 11pt; margin-bottom: 0in; margin-left: 0.375in; margin-top: 0in;" type="1">
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;" value="1"><span style="font-family: "calibri"; font-size: 11pt;">Session</span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;" value="2"><span style="font-family: "calibri"; font-size: 11pt;">Application</span></li>
</ol>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 16pt; font-weight: bold; margin: 0in;">
<span lang="en-IN">1. Session </span><span lang="en-US"> </span></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
Session management is a very strong technique to maintain state. Generally session is used to store user's information and/or uniquely identify a user (or say browser). The server maintains the state of user information by using a session ID. When users makes a request without a session ID, <a href="http://asp.net/">ASP.NET</a> creates a session ID and sends it with every request and response to the same user.</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 12pt; font-weight: bold; margin: 0in;">
<span lang="en-IN">Session Events in <a href="http://asp.net/">ASP.NET</a></span><span lang="en-US"> </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span lang="en-IN">To manage a session, <a href="http://asp.net/">ASP.NET</a> provides two events: </span><span lang="en-US">session_start</span><span lang="en-IN"> and </span><span lang="en-US">session_end</span><span lang="en-IN"> that is written in a special file called </span><span lang="en-US" style="font-style: italic;">Global.asax</span><span lang="en-IN"> in the root directory of the project. </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span lang="en-IN" style="font-weight: bold;">Session_Start</span><span lang="en-IN">: The </span><span lang="en-US">Session_start</span><span lang="en-IN"> event is raised every time a new user makes a request without a session ID, i.e., new browser accesses the application, then a </span><span lang="en-US">session_start</span><span lang="en-IN"> event raised. Let's see the </span><span lang="en-US" style="font-style: italic;">Global.asax</span><span lang="en-IN"> file. </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
void Session_Start(object sender, EventArgs e)<br />
{<br />
<span style="mso-spacerun: yes;"> </span>Session["Count"] = 0;<span style="mso-spacerun: yes;"> </span>// Code that runs when a new session is started<br />
}</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span lang="en-IN" style="font-weight: bold;">Session_End</span><span lang="en-IN">: The </span><span lang="en-US">Session_End</span><span lang="en-IN"> event is raised when session ends either because of a time out expiry or explicitly by using </span><span lang="en-US">Session.Abandon()</span><span lang="en-IN">. The </span><span lang="en-US">Session_End</span><span lang="en-IN"> event is raised only in the case of In proc mode not in the state server and SQL Server modes. </span></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span lang="en-IN">There are four session storage</span><span lang="en-US"> </span><span lang="en-IN">mechanisms</span><span lang="en-US"> </span><span lang="en-IN">provided by <a href="http://asp.net/">ASP.NET</a>:</span></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<ul style="direction: ltr; margin-bottom: 0in; margin-left: 0.375in; margin-top: 0in;" type="disc">
<li style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt; font-style: italic;">In Proc mode</span><span lang="en-US" style="font-family: "calibri"; font-size: 11pt; font-style: italic;"> </span></li>
<li style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt; font-style: italic;">State Server mode</span><span lang="en-US" style="font-family: "calibri"; font-size: 11pt; font-style: italic;"> </span><span lang="en-US" style="font-family: "calibri"; font-size: 11pt;"> </span></li>
<li lang="en-IN" style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11pt; font-style: italic;">SQL Server mode </span></li>
<li style="margin-bottom: 0px; margin-top: 0px; vertical-align: middle;"><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt; font-style: italic;">Custom</span><span lang="en-US" style="font-family: "calibri"; font-size: 11pt; font-style: italic;"> </span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt; font-style: italic;">mode</span><span lang="en-IN" style="font-family: "calibri"; font-size: 11pt;"> </span></li>
</ul>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span style="font-weight: bold;">In Process mode</span>:</div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span style="mso-spacerun: yes;"> </span>In proc mode is the default mode provided by <a href="http://asp.net/">ASP.NET</a>. In this mode, session values are stored in the web server's memory (in IIS). If there are more than one IIS servers then session values are stored in each server separately on which request has been made. Since the session values are stored in server, whenever server is restarted the session values will be lost. </div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<configuration><br />
<span style="mso-spacerun: yes;"> </span><sessionstate mode="InProc" cookieless="false" timeout="10" <br />
<span style="mso-spacerun: yes;"> </span>stateConnectionString="tcpip=<a href="http://127.0.0.1:80808/">127.0.0.1:80808</a>" <br />
<span style="mso-spacerun: yes;"> </span>sqlConnectionString="Data Source=.\SqlDataSource;User ID=userid;Password=password"/><br />
</configuration> </div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span lang="en-IN" style="font-weight: bold;">In State Server mode</span><span lang="en-IN">: This mode could store session in the web server but out of the application pool. But usually if this mode is used there will be a separate server for storing sessions, i.e., </span><span lang="en-US">stateServer</span><span lang="en-IN">. The benefit is that when IIS restarts the session is available. It stores session in a separate Windows service. For State server session mode, we have to configure it explicitly in the web config file and start the </span><span lang="en-US">aspnet_state</span><span lang="en-IN"> service.</span></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<configuration><sessionstate mode="stateserver" cookieless="false" <br />
<span style="mso-spacerun: yes;"> </span>timeout="10"<span style="mso-spacerun: yes;"> </span>stateConnectionString="tcpip=<a href="http://127.0.0.1:42424/">127.0.0.1:42424</a>"<span style="mso-spacerun: yes;"> </span><br />
<span style="mso-spacerun: yes;"> </span>sqlConnectionString="Data Source=.\SqlDataSource;User ID=userid;Password=password"/> </configuration> </div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span style="font-weight: bold;">In SQL Server mode</span>: Session is stored in a SQL Server database. This kind of session mode is also separate from IIS, i.e., session is available even after restarting the IIS server. This mode is highly secure and reliable but also has a disadvantage that there is overhead from serialization and deserialization of session data. This mode should be used when reliability is more important than performance. </div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<configuration><br />
<span style="mso-spacerun: yes;"> </span><sessionstate mode="sqlserver" cookieless="false" timeout="10" <br />
<span style="mso-spacerun: yes;"> </span>stateConnectionString="tcpip=<a href="http://127.0.0.1:4/">127.0.0.1:4</a><span style="mso-spacerun: yes;"> </span>2424" <br />
<span style="mso-spacerun: yes;"> </span>sqlConnectionString="Data Source=.\SqlDataSource;User ID=userid;Password=password"/><br />
</configuration></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 16pt; font-weight: bold; margin: 0in;">
2. Application</div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
Application state is a server side state management technique. The date stored in application state is common for all users of that particular <a href="http://asp.net/">ASP.NET</a> application and can be accessed anywhere in the application. It is also called application level state management. Data stored in the application should be of small size. </div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span lang="en-IN">How to get and set a value in the </span><span lang="en-US" style="font-weight: bold;">application object</span><span lang="en-IN">:</span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
Application["Count"] = Convert.ToInt32(Application["Count"]) + 1; //Set Value to The Application Object<br />
Label1.Text = Application["Count"].ToString(); //Get Value from the Application Object </div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; font-weight: bold; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 14pt; font-weight: bold; margin: 0in;">
Static class</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<span lang="en-IN">C# provides the important feature to create static classes, there are two main features of a static class, one is no object of static class can be created and another is, a static class must contain only static members, then it is important that what is the main benefit to create a static class, the main benefit of making static class, we do not need to make any instance of this class ,all members can be accessible with its own name.</span><span lang="en-US"> </span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in;">
Declaration: </div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<span lang="en-IN">A static class is created by using keyword 'Static' as shown here:</span><span lang="en-US"> </span></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<span lang="en-IN">Static class </span><span lang="en-US" style="font-style: italic;">Clasname</span></div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
{</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
//C#</div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
} </div>
<div style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<span lang="en-IN">One more thing that is notable-within static class, all members must be explicitly specified as static, static class does not automatically make its members static. Static class can contain a collection of static methods.</span><span lang="en-US"> </span></div>
<div style="font-family: "verdana"; font-size: 10pt; font-weight: bold; margin: 0in;">
<span lang="en-IN">Example:</span><span lang="en-US"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-IN" style="color: blue; font-family: "verdana";">using</span><span lang="en-US" style="font-family: "verdana";"> System;</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span style="font-family: "verdana";"> </span><span style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-IN" style="color: blue; font-family: "verdana";">static</span><span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-US" style="color: blue; font-family: "verdana";">class</span><span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-US" style="color: teal; font-family: "verdana";">Shape</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-IN" style="font-family: "verdana";">{</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="color: blue; font-family: "verdana";">public</span><span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-US" style="color: blue; font-family: "verdana";">static</span><span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-US" style="color: blue; font-family: "verdana";">double</span><span lang="en-US" style="font-family: "verdana";"> GetArea(</span><span lang="en-US" style="color: blue; font-family: "verdana";">double</span><span lang="en-US" style="font-family: "verdana";"> Width, </span><span lang="en-US" style="color: blue; font-family: "verdana";">double</span><span lang="en-US" style="font-family: "verdana";"> height)</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="font-family: "verdana";">{</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="color: blue; font-family: "verdana";">return</span><span lang="en-US" style="font-family: "verdana";"> Width * Height;</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="font-family: "verdana";">}</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-IN" style="font-family: "verdana";">}</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span style="font-family: "verdana";"> </span><span style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-IN" style="color: blue; font-family: "verdana";">class</span><span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-US" style="color: teal; font-family: "verdana";">Ractangle</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-IN" style="font-family: "verdana";">{</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="color: blue; font-family: "verdana";">private</span><span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-US" style="color: blue; font-family: "verdana";">void</span><span lang="en-US" style="font-family: "verdana";"> GetRactangleArea()</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="font-family: "verdana";">{</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="color: teal; font-family: "verdana";">Double</span><span lang="en-US" style="font-family: "verdana";"> Area;</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="font-family: "verdana";">Area = </span><span lang="en-US" style="color: teal; font-family: "verdana";">Shape</span><span lang="en-US" style="font-family: "verdana";">.GetArea(10, 5);</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-US" style="font-family: "verdana";"> </span><span lang="en-IN" style="font-family: "verdana";"> </span><span lang="en-US" style="font-family: "verdana";">}</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div style="font-size: 10pt; margin: 0in;">
<span lang="en-IN" style="font-family: "verdana";">}</span><span lang="en-US" style="font-family: "verdana";"> </span></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
Shape is static class, it contain staic function GetArea.Ractangle is other class and with in GetArea function can be access without creating instace of Class Shape. </div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
Although a static class cannot have an instance constructor, it can have a static constructor.</div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 20pt; font-weight: bold; margin: 0in;">
Abstract and Sealed Classes and Class Members</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
The <a href="https://msdn.microsoft.com/en-IN/library/sf985hc5.aspx">abstract</a> keyword enables you to create classes and <a href="https://msdn.microsoft.com/en-IN/library/0b0thckt.aspx">class</a> members that are incomplete and must be implemented in a derived class.</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
The <a href="https://msdn.microsoft.com/en-IN/library/88c54tsw.aspx">sealed</a> keyword enables you to prevent the inheritance of a class or certain class members that were previously marked <a href="https://msdn.microsoft.com/en-IN/library/9fkccyh4.aspx">virtual</a>. </div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 16pt; font-weight: bold; margin: 0in;">
Abstract Classes and Class Members</div>
<div style="font-family: "calibri"; font-size: 16pt; font-weight: bold; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
Classes can be declared as abstract by putting the keyword <span style="font-weight: bold;">abstract</span> before the class definition. For example:</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
C#</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">abstract</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> A<br /> {<br /> <span style="mso-spacerun: yes;"> </span></span><span style="color: green;">// Class members here.</span><span style="color: black;"><br /> }<br /> </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
An abstract class cannot be instantiated. The purpose of an abstract class is to provide a common definition of a base class that multiple derived classes can share. For example, a class library may define an abstract class that is used as a parameter to many of its functions, and require programmers using that library to provide their own implementation of the class by creating a derived class.</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
Abstract classes may also define abstract methods. This is accomplished by adding the keyword <span style="font-weight: bold;">abstract</span> before the return type of the method. For example:</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
C#</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">abstract</span><span style="color: black;"> </span><span style="color: blue;">class</span><span style="color: black;"> A<br /> {<br /> <span style="mso-spacerun: yes;"> </span></span><span style="color: blue;">public</span><span style="color: black;"> </span><span style="color: blue;">abstract</span><span style="color: black;"> </span><span style="color: blue;">void</span><span style="color: black;"> DoWork(</span><span style="color: blue;">int</span><span style="color: black;"> i);<br /> }<br /> </span></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
Abstract methods have no implementation, so the method definition is followed by a semicolon instead of a normal method block. Derived classes of the abstract class must implement all abstract methods. When an abstract class inherits a virtual method from a base class, the abstract class can override the virtual method with an abstract method. For example:</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 20pt; font-weight: bold; margin: 0in;">
interface</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
An interface contains only the signatures of <a href="https://msdn.microsoft.com/en-us/library/ms173114.aspx">methods</a>, <a href="https://msdn.microsoft.com/en-us/library/x9fsa0sw.aspx">properties</a>, <a href="https://msdn.microsoft.com/en-us/library/awbftdfh.aspx">events</a> or <a href="https://msdn.microsoft.com/en-us/library/6x16t2tx.aspx">indexers</a>. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition. In the </div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<span style="color: blue;">interface</span> ISampleInterface<br />
{<br />
<span style="mso-spacerun: yes;"> </span><span style="color: blue;">void</span> SampleMethod();<br />
}<br />
<br />
<span style="color: blue;">class</span> ImplementationClass : ISampleInterface<br />
{<br />
<span style="mso-spacerun: yes;"> </span><span style="color: green;">// Explicit interface member implementation: </span><br />
<span style="mso-spacerun: yes;"> </span><span style="color: blue;">void</span> ISampleInterface.SampleMethod()<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span><span style="color: green;">// Method implementation.</span><br />
<span style="mso-spacerun: yes;"> </span>}<br />
<br />
<span style="mso-spacerun: yes;"> </span><span style="color: blue;">static</span> <span style="color: blue;">void</span> Main()<br />
<span style="mso-spacerun: yes;"> </span>{<br />
<span style="mso-spacerun: yes;"> </span><span style="color: green;">// Declare an interface instance.</span><br />
<span style="mso-spacerun: yes;"> </span>ISampleInterface obj = <span style="color: blue;">new</span> ImplementationClass();<br />
<br />
<span style="mso-spacerun: yes;"> </span><span style="color: green;">// Call the member.</span><br />
<span style="mso-spacerun: yes;"> </span>obj.SampleMethod();<br />
<span style="mso-spacerun: yes;"> </span>}<br />
}</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<h2 style="margin: 0in; text-align: left;">
<span style="font-family: "calibri"; font-size: large;"><b>ArrayList</b></span></h2>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">1. ArrayList belongs to the System.Collections namespace, i.e. you need to import the following namespace.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">using System.Collections;</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Imports System.Collections</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">2. ArrayList does not have type restriction for storing data i.e. it is not Type Safe. You can store anything in ArrayList. In fact same ArrayList can store multiple types of objects.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">ArrayList arrList = new ArrayList();</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arrList.Add(921);</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arrList.Add("Mudassar Khan");</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arrList.Add(DateTime.Now);</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Dim arrList As New ArrayList()</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arrList.Add(921)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arrList.Add("Mudassar Khan")</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arrList.Add(DateTime.Now)</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">3. ArrayList stores all data as object thus to get it back you must remember what you stored where and correspondingly Type Cast it as per its original Type when stored.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">int number = Convert.ToInt32(arrList[0]);</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">string name = arrList[1].ToString();</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">DateTime dt = Convert.ToDateTime(arrList[2]);</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Dim number As Integer = Convert.ToInt32(arrList(0))</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Dim name As String = arrList(1).ToString()</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Dim dt As DateTime = Convert.ToDateTime(arrList(2))</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">4. ArrayList is mainly for .Net 2.0 Framework projects as during that period Generic List was not invented.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">5. While running a Loop on ArrayList you need to use Object data type. Thus this is another disadvantage as you again do not know what type of data particular item contains.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">foreach (object o in arrList)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">{</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">}</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">For Each o As Object In arrList</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Next</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri"; font-size: large;"><b>Generic Lists (List<t>)</t></b></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">1. Generic List (List<t>) belongs to the System.Collections.Generic namespace, i.e. you need to import the following namespace.</t></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">using System.Collections.Generic;</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Imports System.Collections.Generic</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">2. In Generic List (List<t>), T means data type, i.e. string, int, DateTime, etc. Thus it will store only specific types of objects based on what data type has been specified while declarations i.e. it is Type Safe. Thus if you have a Generic List of string you can only store string values, anything else will give compilation error.</t></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Below I had no option other than having three different Generic Lists for three different data types.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">List<string> lstString = new List<string>();</string></string></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstString.Add("Mudassar Khan");</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstString.Add("Robert Hammond");</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstString.Add("Ramesh Singh");</span></span></div>
<div style="margin: 0in;">
<span style="background-color: #e69138; color: white;"><br /></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">List<int> lstInt = new List<int>();</int></int></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstInt.Add(991);</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstInt.Add(10);</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstInt.Add(4450);</span></span></div>
<div style="margin: 0in;">
<span style="background-color: #e69138; color: white;"><br /></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">List<datetime> lstDateTime = new List<datetime>();</datetime></datetime></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstDateTime.Add(DateTime.Now);</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstDateTime.Add(DateTime.Now.AddDays(20));</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: white; font-size: 14.6667px;">lstDateTime.Add(DateTime.Now.AddHours(-10));</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">Dim lstString As New List(Of String)()</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstString.Add("Mudassar Khan")</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstString.Add("Robert Hammond")</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstString.Add("Ramesh Singh")</span></span></div>
<div style="margin: 0in;">
<span style="background-color: #e69138;"><span style="color: #444444;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">Dim lstInt As New List(Of Integer)()</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstInt.Add(991)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstInt.Add(10)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstInt.Add(4450)</span></span></div>
<div style="margin: 0in;">
<span style="background-color: #e69138;"><span style="color: #444444;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">Dim lstDateTime As New List(Of DateTime)()</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstDateTime.Add(DateTime.Now)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstDateTime.Add(DateTime.Now.AddDays(20))</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="background-color: #e69138; color: #444444; font-size: 14.6667px;">lstDateTime.Add(DateTime.Now.AddHours(-10))</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">3. Generic List stores all data of the data type it is declared thus to getting the data back is hassle free and no type conversions required.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">int number = lstInt[0];</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">string name = lstString[0];</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">DateTime dt = lstDateTime[0];</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Dim number As Integer = lstInt(0)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Dim name As String = lstString(0)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Dim dt As DateTime = lstDateTime(0)</span></span></div>
<div style="margin: 0in;">
<br /></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">4. Generic List must be used instead of ArrayList unless specific requirement for projects higher than .Net 2.0 Framework.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">5. While running a Loop on Generic List again it is problem free as we exactly know what the List contains.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">C#</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">foreach (int number in lstInt)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">{</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">}</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">foreach (string name in lstString)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">{</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">}</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">foreach (DateTime dt in lstDateTime)</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">{</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">}</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">VB.Net</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">For Each number As Integer In lstInt</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Next</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">For Each name As String In lstString</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Next</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">For Each dt As DateTime In lstDateTime</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Next</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri"; font-size: large;">Arrays</span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Arrays are strongly typed collection of same datatype and these arrays are fixed length that cannot be changed during runtime. Generally in arrays we will store values with index basis that will start with zero. If we want to access values from arrays we need to pass index values.</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Declaration of Arrays</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">Generally we will declare arrays with fixed length and store values like as shown below</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">string[] arr=new string[2];</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arr[0] = "welcome";</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">arr[1] = "Aspdotnet-suresh";</span></span></div>
<div style="margin: 0in;">
<span style="font-family: "calibri";"><span style="font-size: 14.6667px;">In above code I declared array size 2 that means we can store only 2 string values in array.</span></span></div>
<div style="font-family: calibri; margin: 0in;">
<div style="font-size: 11pt;">
<br /></div>
<div style="font-size: 11pt;">
<br />
<br />
<br />
<h1 id="ctl00_ArticleTitle" itemprop="name" style="background-color: white; color: #333333; font-family: 'Segoe UI', Arial, sans-serif; font-size: 29px; margin: 0px 0px 15px; padding: 0px;">
Indexes in MS SQL Server</h1>
<div>
<br /></div>
</div>
<div class="title" style="background-color: white; border-image-outset: initial; border-image-repeat: initial; border-image-slice: initial; border-image-source: initial; border-image-width: initial; border: 0px; color: grey; font-family: 'Segoe UI', Arial, sans-serif; margin: 0px; padding: 0px;">
<h1 id="ctl00_ArticleTitle" itemprop="name" style="color: #333333; margin: 0px 0px 15px; padding: 0px;">
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
This article focuses on how MS SQL Server uses indexes to read and write data. Data is arranged by SQL Server in the form of <em style="border: 0px; margin: 0px; padding: 0px;">extents</em> and <em style="border: 0px; margin: 0px; padding: 0px;">pages</em>. Each extent is of size 64 KB, having 8 pages of 8KB sizes. An extent may have data from multiple or same table, but each page holds data from a single table only. Logically, data is stored in record sets in the table. We have fields (columns) identifying the type of data contained in each of the record sets. A table is nothing but a collection of record sets; by default, rows are stored in the form of heaps unless a clustered index has been defined on the table, in which case, record sets are sorted and stored on the clustered index. The heaps structure is a simple arrangement where the inserted record is stored in the next available space on the table page.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
Heaps seem a great option when the motive is simply storing data, but when data retrieval steps in, this option back fires. An index acts as a fire fighter in this scenario. Indexes are arranged in the form of a B-Tree where the leaf node holds the data or a pointer to the data. Since the stored data is in a sorted order, indexes precisely know which record is sitting where. Hence an index optimizes and enhances the data retrieval immensely.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
But everything comes at a cost; the price we pay for having an index on the table is, each time there is an Insert/Update/Delete, SQL Server updates the active indexes on the table where these DML are operated. Hence simply creating indexes madly for the sake of better data retrieval will not serve the purpose. If there are 20 indexes on a table, each time a DML is done on the table, all these 20 indexes shall be updated so that they can uniquely figure out the location of the record. Let’s dive deep into the indexes.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
<br /></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
<br /></div>
</h1>
<h2 style="color: #ff9900; font-family: 'Segoe UI', Arial, sans-serif; font-size: 29px; font-weight: 200; margin: 20px 0px 11px; padding: 0px 0px 10px;">
Clustered Index (CI)</h2>
<h1 itemprop="name" style="color: #333333; margin: 0px 0px 15px; padding: 0px;">
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
A clustered index is something that reorganizes the way records in the table are physically stored. Therefore a table can have only one clustered index. The leaf nodes of a clustered index contain the data pages, by which I mean the key-value pair in the clustered index has the index key and the actual data value. Also remember, a clustered index will be created on a table by default the moment a primary key is created on the table. A clustered index is something like your train ticket B4/24, you know that you need to board coach B4 and sit on seat number 24. So this index physically leads you to your actual seat.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
We will follow this up closely with an example:</div>
<div class="pre-action-link" id="premain648200" style="border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; font-weight: normal; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide648200" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre648200" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; font-weight: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">USE</span> TestDB
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">GO</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">CREATE</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">TABLE</span> Sales(
ID <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INT</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">IDENTITY</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>,<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>)
,ProductCode <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">VARCHAR</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">20</span>)
,Price <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">FLOAT</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">53</span>)
,DateTransaction <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">DATETIME</span>);</pre>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
I have created a table Sales, and then created a Stored Procedure to insert 2,00,000 records into the Sales table. This sizable chunk of data will help us to notice the differences very clearly.</div>
<div class="pre-action-link" id="premain290633" style="border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; font-weight: normal; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide290633" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre290633" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; font-weight: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">CREATE</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">PROCEDURE</span> InsertIntoSales
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">AS</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> NOCOUNT <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">BEGIN</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">DECLARE</span> <span class="code-sdkkeyword" style="border: 0px; color: #339999; margin: 0px; padding: 0px;">@PC</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">VARCHAR</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">20</span>)=<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">A12CB'</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">DECLARE</span> <span class="code-sdkkeyword" style="border: 0px; color: #339999; margin: 0px; padding: 0px;">@Price</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INT</span> = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">50</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">DECLARE</span> <span class="code-sdkkeyword" style="border: 0px; color: #339999; margin: 0px; padding: 0px;">@COUNT</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INT</span> = <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">WHILE</span> @COUNT<200000 class="code-keyword" span="" style="border: 0px; color: blue; margin: 0px; padding: 0px;">BEGIN<!--200000--></200000></pre>
</h1>
</div>
</div>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> @PC=@PC+CAST(<span class="code-sdkkeyword" style="border: 0px; color: #339999; margin: 0px; padding: 0px;">@COUNT</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">AS</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">VARCHAR</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">20</span>))
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> @Price=@Price+@COUNT
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INSERT</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INTO</span> Sales <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">VALUES</span> (<span class="code-sdkkeyword" style="border: 0px; color: #339999; margin: 0px; padding: 0px;">@PC</span>,<span class="code-sdkkeyword" style="border: 0px; color: #339999; margin: 0px; padding: 0px;">@Price</span>,GETDATE())
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> @PC=<span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">A12CB'</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> @Price=50
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> @COUNT+=1
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">END</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">END</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">EXEC</span> InsertIntoSales<br />
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
Now we have created the table and inserted 2,00,000 records into it, but there is no index defined on any column.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
Press Control+M. This will “Include the Actual Execution Plan” in the results. Let's run the below query.</div>
<div class="pre-action-link" id="premain605813" style="border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; font-weight: normal; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide605813" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre605813" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; font-weight: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">STATISTICS</span> IO <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SELECT</span> * <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">FROM</span> Sales <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">WHERE</span> ID=189923
ID ProductCode Price DateTransaction
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">--</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">--------- ---------------- ---------- -----------------------
</span><span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">189923</span> A12CB189922 <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">189972</span> 2011-03-21 12:07:48.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">310</span>
(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span> row(s) affected)
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">Table</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Sales'</span>. Scan count <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>, logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1129</span>, physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
lob physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.
(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span> row(s) affected)</pre>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
<img complete="true" src="http://www.codeproject.com/KB/database/IndexesMSSQLServer/image001.png" height="144" style="border: 0px; height: auto; margin: 0px; max-width: 100%; overflow: auto; padding: 0px;" width="450" /></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
The Execution plan tab on the results show that the record has been retrieved on a table scan and the logical reads are 1129.</div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
Now let’s build a clustered index on the ID column of the Sales table.</div>
<div class="pre-action-link" id="premain927850" style="border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; font-weight: normal; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide927850" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre927850" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; font-weight: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">CREATE</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">CLUSTERED</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INDEX</span> CL_ID <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span> SALES(ID);</pre>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
Let us press CTRL+M and rerun the same query:</div>
<div class="pre-action-link" id="premain893262" style="border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; font-weight: normal; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide893262" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre893262" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; font-weight: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">STATISTICS</span> IO <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SELECT</span> * <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">FROM</span> Sales <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">WHERE</span> ID=189923
ID ProductCode Price DateTransaction
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">--</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">--------- ---------------- ------------ -----------------------
</span><span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">189923</span> A12CB189922 <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">189972</span> 2011-03-21 12:07:48.<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">310</span>
(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span> row(s) affected)
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">Table</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Sales'</span>. Scan count <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>, logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">3</span>, physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
lob physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.
(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span> row(s) affected)</pre>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
<img complete="true" src="http://www.codeproject.com/KB/database/IndexesMSSQLServer/image002.png" height="138" style="border: 0px; height: auto; margin: 0px; max-width: 100%; overflow: auto; padding: 0px;" width="416" /></div>
<div style="color: #111111; font-family: 'Segoe UI', Arial, sans-serif; font-size: 14px; font-weight: normal;">
The Execution plan tab on the results shows that the record has been retrieved on Index seek and the logical reads are 3. After the clustered index creation, SQL Server has been able to reduce the logical reads dramatically and the query has been optimized. Clearly the index knows where to look for the record.<br />
<br />
<br />
<h2 style="background-color: white; color: #ff9900; font-family: 'Segoe UI', Arial, sans-serif; font-size: 29px; font-weight: 200; margin: 20px 0px 11px; padding: 0px 0px 10px;">
Non-Clustered Index (NCI)</h2>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non-clustered index does not consist of the data pages but a pointer to it. That goes to say that a non-clustered index can’t survive on its own - it needs a base to live on. A non-clustered index uses a clustered index (if defined) or the heap to build itself.</div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
When a non-clustered index uses the heap, the leaf node (or the pointer) is a physical location of the data. When it uses a clustered index, the leaf node (or the pointer) is the clustered index key value and this key value in turn points to the actual data.</div>
<h2 style="background-color: white; color: #ff9900; font-family: 'Segoe UI', Arial, sans-serif; font-size: 29px; font-weight: 200; margin: 20px 0px 11px; padding: 0px 0px 10px;">
Part I: When NCI Uses a CI</h2>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
Getting back to Sales, we already have a CI (CL_ID) on the ID column, now if we have a query something like:</div>
<div class="pre-action-link" id="premain259573" style="background-color: white; border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide259573" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre259573" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">STATISTICS</span> IO <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SELECT</span> * <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">FROM</span> Sales <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">WHERE</span> ProductCode <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">like</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">A12CB908%'</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">order</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">by</span> Price
Press Control+M <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">and</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">execute</span> the query
There are arround <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">111</span> records retrived
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">--</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">---------------------------------------------------
</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">111</span> row(s) affected)
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">Table</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Sales'</span>. Scan count <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>, logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1130</span>, physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
lob physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.
(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span> row(s) affected)</pre>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
<img complete="true" height="154" src="http://www.codeproject.com/KB/database/IndexesMSSQLServer/image003.png" style="border: 0px; height: auto; margin: 0px; max-width: 100%; overflow: auto; padding: 0px;" width="600" /></div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
We find that the query first uses the clustered index to get 111 records and then uses a sort operation; the logical reads are as high as 1130. There is also a missing index suggestion.</div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
Let’s consider SQL Server’s advice and create a non-clustered index (NONCI_PC) on the ProductCode column. Since we have a CI already, this NCI would be built on the CI.</div>
<div class="pre-action-link" id="premain605904" style="background-color: white; border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide605904" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre605904" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">CREATE</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">NONCLUSTERED</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INDEX</span> NONCI_PC <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span> SALES(ProductCode);</pre>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
Press Control+M and rerun the same query, this time around, we can see the data fetch plan change.</div>
<div class="pre-action-link" id="premain570001" style="background-color: white; border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide570001" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre570001" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">STATISTICS</span> IO <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SELECT</span> * <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">FROM</span> Sales <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">WHERE</span> ProductCode <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">like</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">A12CB908%'</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">order</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">by</span> Price
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">--</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">-----------------------------
</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">111</span> row(s) affected)
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">Table</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Sales'</span>. Scan count <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>, logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">351</span>, physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">7</span>, lob logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
lob physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.
(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span> row(s) affected)</pre>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
<img complete="true" height="221" src="http://www.codeproject.com/KB/database/IndexesMSSQLServer/image004.png" style="border: 0px; height: auto; margin: 0px; max-width: 100%; overflow: auto; padding: 0px;" width="583" /></div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
The logical reads have been minimized and the revised execution plan is as in the figure. This was the example where a <strong style="border: 0px; margin: 0px; padding: 0px;"><em style="border: 0px; margin: 0px; padding: 0px;">non-clustered index used a clustered index</em></strong>.</div>
<h2 style="background-color: white; color: #ff9900; font-family: 'Segoe UI', Arial, sans-serif; font-size: 29px; font-weight: 200; margin: 20px 0px 11px; padding: 0px 0px 10px;">
Part II: When NCI Uses a Heap</h2>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
When there is no clustered index built on a table and a non-clustered index is built, it uses the heap for data retrieval. The indexed column or columns are sorted along with a pointer to the physical location of the data.</div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
<em style="border: 0px; margin: 0px; padding: 0px;">The big question is, how do I know if I should create an NCI on a CI or on a heap?</em></div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
The answer is in the query, if data is queried typically on one particular column, it would be beneficial to build NCI upon a CI, but when the case is something like what we have in the present Sales example where we will be building a one-column NC index on a heap, the NCI would be merely a two-column table containing the key-value pair (index key and physical location, i.e., value). This would be the best optimization in this scenario. To follow this up, let’s review the example closely.</div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
With respect to the sales example, let’s delete the clustered index CL_ID created on the ID column and re-evaluate.</div>
<div class="pre-action-link" id="premain248634" style="background-color: white; border: 0px; color: #999999; font-family: 'Segoe UI', Arial, sans-serif; font-size: 11px; margin: 0px; padding: 0px; text-align: right; width: 700px;">
<span id="prehide248634" style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Hide</span> <span style="border: 0px; cursor: pointer; margin: 0px; padding: 0px; transition: color 0.1s linear;">Copy Code</span></div>
<pre id="pre248634" lang="sql" style="background-color: #fbedbb; border: 1px solid rgb(251, 237, 187); color: black; font-family: Consolas, 'Courier New', Courier, mono; font-size: 9pt; font-stretch: normal; overflow: auto; padding: 6px; tab-size: 4; white-space: pre-wrap; word-wrap: break-word;"><span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">DROP</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">INDEX</span> Sales.CL_ID;
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SET</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">STATISTICS</span> IO <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">ON</span>
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">SELECT</span> * <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">FROM</span> Sales <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">WHERE</span> ProductCode <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">like</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">A12CB908%'</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">order</span> <span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">by</span> Price
<span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">--</span><span class="code-comment" style="border: 0px; color: green; font-style: italic; margin: 0px; padding: 0px;">----------------------------------
</span>(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">111</span> row(s) affected)
<span class="code-keyword" style="border: 0px; color: blue; margin: 0px; padding: 0px;">Table</span> <span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">'</span><span class="code-string" style="border: 0px; color: purple; margin: 0px; padding: 0px;">Sales'</span>. Scan count <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span>, logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">114</span>, physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob logical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>,
lob physical reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>, lob read-ahead reads <span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">0</span>.
(<span class="code-digit" style="border: 0px; color: navy; margin: 0px; padding: 0px;">1</span> row(s) affected)</pre>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
<img complete="true" height="227" src="http://www.codeproject.com/KB/database/IndexesMSSQLServer/image005.png" style="border: 0px; height: auto; margin: 0px; max-width: 100%; overflow: auto; padding: 0px;" width="584" /></div>
<div style="background-color: white; font-family: 'Segoe UI', Arial, sans-serif;">
The logical reads have been further optimized and the execution plan also has been revised. In this case, the query uses the non-clustered index to be run on the heap.</div>
</div>
<br />
<br />
<div class="entry float-left" style="border: 0px; float: left; margin: 0px; padding: 0px;">
</div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br />
<br />
<br />
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br />
<br />
<br />
<br />
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div lang="en-IN" style="font-family: "verdana"; font-size: 10pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div lang="en-IN" style="font-family: "calibri"; font-size: 11pt; margin: 0in 0in 0in 0.375in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
<div style="font-family: "calibri"; font-size: 11pt; margin: 0in;">
<br /></div>
</div>
bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-42510025623095044472015-09-27T01:39:00.013-07:002015-09-27T01:39:39.756-07:00jQuery input vs input<div class='post-body entry-content' id='post-body-802723770744000799' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-attribute-selector.html" style="font-family: Arial, Helvetica, sans-serif;">Part 7 - jQuery attribute selector</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-attribute-value-selector.html">Part 8 - jQuery attribute value selector</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-case-insensitive-attribute.html">Part 9 - jQuery case insensitive attribute selector</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss the <b>difference between $(input) and $(:input)</b> selectors </span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #990000;">':input'</span>) selects all input, textarea, select and button elements where as $(<span style="color: #990000;">'input'</span>) just selects elements with an input tag.</span> <br /> <br/> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Consider the web page below</b></span> <br /> <img alt="jQuery input vs input" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTGKWVbL_OrdDC3rtsJ26jzOUkmu2uugF-zKxk0DAYnwKNrNMhQv2DQcYlY7r2usqzD10zHOUca4Y1gcpXz8MbIp39qM4gHkr2nf7bda8pSYSAElsn2GxUsGfZms2ISRMSfF9xQvrsAAk/s1600/jQuery+input+vs+input.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">The following is the HTML of the above page</span><br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="background: white; color: blue; font-family: Arial, Helvetica, sans-serif; line-height: 18.3999996185303px;"><</span><span style="background: white; color: maroon; font-family: Arial, Helvetica, sans-serif; line-height: 18.3999996185303px;">html</span><span style="background: white; color: blue; font-family: Arial, Helvetica, sans-serif; line-height: 18.3999996185303px;">></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-89208816044043322192015-09-27T01:39:00.005-07:002015-09-27T01:39:22.644-07:00jQuery attribute value selectors<div class='post-body entry-content' id='post-body-7880230815465518239' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-element-selector.html" style="font-family: Arial, Helvetica, sans-serif;">Part 5 - jQuery Element Selector</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-class-selector.html">Part 6 - jQuery class selector</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-attribute-selector.html">Part 7 - jQuery attribute selector</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>In this video we will discuss </b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Attribute Equals Selector [name="value"]</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Attribute Not Equal Selector [name!="value"]</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Attribute Contains Selector [name*="value"]</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Attribute Contains Word Selector [name~="value"]</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Attribute Contains Prefix Selector [name|="value"]</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Attribute Starts With Selector [name^="value"]</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Attribute Ends With Selector [name$="value"]</span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">This is continuation to <a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-attribute-selector.html">Part 7</a>, please watch <a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-attribute-selector.html">Part 7</a> before proceeding.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value equal to div1Title</span><span style="font-family: Arial, Helvetica, sans-serif;"><br />$(<span style="color: #990000;">'[title="div1Title"]'</span>) </span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value not equal to div1Title</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #990000;">'[title!="div1Title"]'</span>) </span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value containing the given substring - Title</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #990000;">'[title*="Title"]'</span>) </span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value containing the given word - mySpan, delimited by spaces</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #990000;">'[title~="mySpan"]'</span>)</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value equal to myTitle or starting with myTitle followed by a hyphen (-)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #990000;">'[title|="myTitle"]'</span>) </span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value starting with div</span><span style="font-family: Arial, Helvetica, sans-serif;"><br />$(<span style="color: #990000;">'[title^="div"]'</span>)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value ending with Heading</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #990000;">'[title$="Heading"]'</span>)</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Selects all elements that have title attribute value equal to div1Title and sets 5px solid red border</span><br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <div class="MsoNormal"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="background: white; color: blue; line-height: 115%;"><</span><span style="background: white; color: maroon; line-height: 115%;">html</span><span style="background: white; color: blue; line-height: 115%;">></span></span><o:p></o:p></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-41801921086715971602015-09-27T01:39:00.001-07:002015-09-27T01:39:14.209-07:00jQuery attribute selector<div class='post-body entry-content' id='post-body-5319389553110237434' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-id-selector.html" style="font-family: Arial, Helvetica, sans-serif;">Part 4 - jQuery #id selector</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-element-selector.html">Part 5 - jQuery Element Selector</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-class-selector.html">Part 6 - jQuery class selector</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>In this video we will discuss selecting elements</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. That have specified attribute</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. That have specified attribute values</span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Syntax : </b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #cc0000;">'[attribute]'</span>)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">$(<span style="color: #cc0000;">'[attribute="value"]'</span>)</span><br /> <br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="background: white;">$(</span><span style="background: white; color: #a31515;">'[title]'</span><span style="background: white;">) </span><span style="background: white; color: green;">// Selects all elements that have title attribute</span><span style="background: white;"><o:p></o:p></span></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-89992897066291858262015-09-27T01:38:00.019-07:002015-09-27T01:38:47.659-07:00jQuery class selector<div class='post-body entry-content' id='post-body-4880361022549229018' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/benefits-of-using-cdn.html">Part 3 - Benefits of using CDN</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-id-selector.html">Part 4 - jQuery #id selector</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-element-selector.html">Part 5 - jQuery Element Selector</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss <b>jQuery class selector</b> i.e <b>selecting elements using their class name </b></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Syntax : $(<span style="color: #990000;">'.class'</span>)</span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">jQuery class selectors uses JavaScript's native <b>getElementsByClassName</b>() function if the browser supports it.</span> <br /> <br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="background: white;">$(</span><span style="background: white; color: #a31515;">'.small'</span><span style="background: white;">) </span><span style="background: white; color: green;">// Selects all elements with class small</span><span style="background: white;"><o:p></o:p></span></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-51838721877621526292015-09-27T01:38:00.015-07:002015-09-27T01:38:39.565-07:00jQuery Element Selector<div class='post-body entry-content' id='post-body-5356594443284633577' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2015/03/what-is-documentreadyfunction-in-jquery.html" style="font-family: Arial, Helvetica, sans-serif;">Part 2 - What is $(document).ready(function() in jquery</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/benefits-of-using-cdn.html">Part 3 - Benefits of using CDN</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/jquery-id-selector.html">Part 4 - jQuery #id selector</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss <b>jQuery Element Selector</b>, i.e selecting elements by tag name. </span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">To select the elements by tag name use <b>jQuery Element Selector</b></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Syntax :</b> $(element)</span><br /> <br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;">$(</span></span><span style="background: white; color: #a31515; line-height: 115%;"><span style="font-family: Arial, Helvetica, sans-serif;">'td'</span></span><span style="font-family: Arial, Helvetica, sans-serif;"><span style="background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial; background-repeat: initial; background-size: initial;">) </span></span><span style="background-color: white; color: green; line-height: 115%;"><span style="font-family: Arial, Helvetica, sans-serif;">// Selects all td elements</span></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-43578228876014983522015-09-27T01:38:00.011-07:002015-09-27T01:38:31.334-07:00jQuery #id selector<div class='post-body entry-content' id='post-body-6532081906843656748' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/what-is-jquery.html">Part 1 - What is jQuery</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/what-is-documentreadyfunction-in-jquery.html">Part 2 - What is $(document).ready(function() in jquery</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/benefits-of-using-cdn.html">Part 3 - Benefits of using CDN</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. <b>What are jQuery selectors</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. <b>Different selectors in jQuery</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">3. <b>#id selector in jquery</b></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>What are jQuery selectors</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">One of the most important concept in jQuery is selectors. jQuery selectors allow you to select and manipulate HTML elements.</span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Different selectors in jQuery</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">jQuery selectors allow you to select html elements in the DOM by</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. Element ID</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. Element Tag Name</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">3. Element Class Name</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">4. Element attribute</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">5. Element Attribute values and many more</span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Id selector in jquery</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">To find an HTML element by ID, use the jQuery #id selector</span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Example : </b>The following example finds button with ID <b>button1 </b>and attaches the click event handler.</span><br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="background: white; color: blue; line-height: 115%;"><</span><span style="background: white; color: maroon; line-height: 115%;">html</span><span style="background: white; color: blue; line-height: 115%;">></span></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-73819166593802409792015-09-27T01:38:00.007-07:002015-09-27T01:38:22.944-07:00Benefits of using CDN<div class='post-body entry-content' id='post-body-3163767563627383527' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/what-is-jquery.html">Part 1 - What is jQuery</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/what-is-documentreadyfunction-in-jquery.html">Part 2 - What is $(document).ready(function() in jquery</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. <b>What is a CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. <b>Advantages and disadvantages of loading jQuery from CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">3. <b>What if the required jQuery file cannot be downloaded from CDN</b></span><br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>What is a CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>CDN</b> stands for <b>Content Delivery Network</b>. A CDN is a system of distributed servers that hosts resources such as images, CSS, </span><span style="font-family: Arial, Helvetica, sans-serif;">JavaScript files etc.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Companies like Microsoft, Google, Yahoo etc have a free public CDN from which we can load jQuery instead of hosting it on our own </span><span style="font-family: Arial, Helvetica, sans-serif;">web server.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Microsoft jQuery CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://www.asp.net/ajax/cdn#jQuery_Releases_on_the_CDN_0">http://www.asp.net/ajax/cdn#jQuery_Releases_on_the_CDN_0</a></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Google jQuery CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://developers.google.com/speed/libraries/devguide#jquery">https://developers.google.com/speed/libraries/devguide#jquery</a></span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Advantages of using a CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. <b>Distributed CDN servers</b> : The jQuery file can be downloaded from the CDN server that is closest to the user</span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. <b>Browser Caching</b> : jQuery is used on many popular websites. If a user has already visited a webpage that uses jQuery from a CDN, </span><span style="font-family: Arial, Helvetica, sans-serif;">and then if he arrives at your page, the jQuery file has already been cached by the browser so there is no need to download it again.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">3. <b>Parallel Downloads</b> : There is a browser limit on how many files can be concurrently downloaded from a given domain. This </span><span style="font-family: Arial, Helvetica, sans-serif;">number varies from browser to browser. For example, if the browser allows only 2 concurrent downloads from a given domain, the </span><span style="font-family: Arial, Helvetica, sans-serif;">3rd download is blocked until one of the previous files has been fully downloaded. Since the jQuery file is on a CDN, it is being </span><span style="font-family: Arial, Helvetica, sans-serif;">downloaded from a different domain. So this means the browser allows another 2 parallel downloads from the CDN server.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">4. <b>Reduced server load</b> : The HTTP request for jQuery file is handled by the CDN server, so the load on your web server is reduced. </span><span style="font-family: Arial, Helvetica, sans-serif;">This also means there is a saving on your website bandwidth consumption which in turn will reduce your hosting cost.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Disadvantages of using a CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Your clients may block the CDN. So you may have to request your clients to whitelist the CDN.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>What if the required jQuery file cannot be downloaded from CDN</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Let assume that, the CDN is down or because of some network issue we are not able to download jQuery from CDN. In this case we </span><span style="font-family: Arial, Helvetica, sans-serif;">will have to fallback to use jQuery file that we hosted on our own server. </span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Here is the code that falls back to use jQuery on your web server, if it can't be downloaded from CDN. If jQuery is successfully </span><span style="font-family: Arial, Helvetica, sans-serif;">downloaded, jQuery property is added to the window object. If this property is not found then jQuery is not downloaded. So in this </span><span style="font-family: Arial, Helvetica, sans-serif;">case we are writing a script tag to fallback to the local jQuery file.</span><br /> <br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="background: white; color: blue;"><</span><span style="background: white; color: maroon;">script</span><span style="background: white;"> </span><span style="background: white; color: red;">src</span><span style="background: white; color: blue;">="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.3.min.js"></</span><span style="background: white; color: maroon;">script</span><span style="background: white; color: blue;">></span><span style="background: white;"><o:p></o:p></span></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-57100486175145244262015-09-27T01:38:00.003-07:002015-09-27T01:38:12.422-07:00What is $(document).ready(function() in jquery<div class='post-body entry-content' id='post-body-3498935304706682327' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/03/what-is-jquery.html">Part 1 - What is jQuery</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>In this video we will discuss </b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. What is <b>$(document).ready(function()</b> in jQuery and when to use it</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. Difference between <b>$(window).load</b> and <b>$(document).ready</b></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>$(document).ready</b> is a jQuery event. It fires as soon as the DOM is loaded and ready to be manipulated by script. This is the earliest point in the page load process where the script can safely access elements in the page's html DOM. This event is fired before all the images, css etc.. are fully loaded.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">The following example works, because the jquery code that adds the event handler to the button is inside the ready() function, which ensures that the DOM is fully loaded before this piece of code is executed, so the JavaScript can find the button element in the DOM and adds the click event handler.</span><br /> <br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="background: white; color: blue; font-family: Arial, Helvetica, sans-serif; line-height: 18.3999996185303px;"><</span><span style="background: white; color: maroon; font-family: Arial, Helvetica, sans-serif; line-height: 18.3999996185303px;">html</span><span style="background: white; color: blue; font-family: Arial, Helvetica, sans-serif; line-height: 18.3999996185303px;">></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-26131765544879425262015-09-27T01:37:00.001-07:002015-09-27T01:37:56.228-07:00What is jQuery<div class='post-body entry-content' id='post-body-6967329232427287117' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Video Tutorials</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhUA99nOsJkKXBqokT3MBK0b">JavaScript Tutorial</a></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhUlURq2QyAu_ABMcY1dcxtS">Using JavaScript with ASP.NET</a></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhXQS_p1i-HLIftB9Y7Vnxlo">ASP.NET Tutorial</a></span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>What is jQuery</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">jQuery is a lightweight JavaScript library that simplifies programming with JavaScript. </span> <br /> <br /> <!-- 336 X 280 ASP --> <script> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>According to jQuery.com</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. With a combination of versatility and extensibility, jQuery has changed the way that millions of people write JavaScript.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Why should we use jQuery</b> </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">OR</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Advantages of using jQuery over raw JavaScript</b></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">The use of JQuery has several benefits over using the raw javascript.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. jQuery is cross-browser</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. jQuery is a lot more easy to use than raw javascript</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">3. jQuery is extensible</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">4. jQuery simplifies and has rich AJAX support</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">5. jQuery has large development community and many plugins. Example autocomplete textbox plugin.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">6. Excellent documentation</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>How to use jQuery in a web application</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">Download the jQuery file from jQuery.com and reference it in your application just like any other JavaScript file.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>What is the difference between jQuery 1.x and 2.x</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">If you want to support IE6/7/8, then use jQuery 1.x where as if you don't have the need to support IE6/7/8 then use jQuery 2.x. jQuery 2.x is smaller in size than jQuery 1.x.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Example : </b>Adding a click event handler for a button control using raw JavaScript. addEventListener() method is not supported in IE < 9.</span> <br /> <br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <div class="MsoNormal"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="background: white; color: blue; line-height: 115%;"><</span><span style="background: white; color: maroon; line-height: 115%;">script</span><span style="background: white; line-height: 115%;"> </span><span style="background: white; color: red; line-height: 115%;">type</span><span style="background: white; color: blue; line-height: 115%;">="text/javascript"></span></span><o:p></o:p></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-92087093952032709892015-09-26T02:39:00.023-07:002015-10-07T05:48:25.575-07:00How to show images from database in gridview in asp.net<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="post-body entry-content" id="post-body-8104874371943662371" itemprop="articleBody">
<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br />
<a href="http://csharp-video-tutorials.blogspot.com/2014/10/customizing-recaptcha-control_12.html" style="font-family: Arial, Helvetica, sans-serif;">Part 168 - Customizing recaptcha control</a><br />
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/08/save-image-to-database-using-aspnet.html">Part 169 - Save image to database using asp.net</a></span> <br />
<span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/08/load-image-from-database-in-aspnet.html">Part 170 - Load image from database in asp.net</a></span> <br />
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss <b>how to retrieve images from database and display them in gridview</b> using c# and asp.net. This is continuation to <a href="http://csharp-video-tutorials.blogspot.com/2015/08/save-image-to-database-using-aspnet.html">Parts 169</a> and <a href="http://csharp-video-tutorials.blogspot.com/2015/08/load-image-from-database-in-aspnet.html">170</a>. Please watch <a href="http://csharp-video-tutorials.blogspot.com/2015/08/save-image-to-database-using-aspnet.html">Parts 169</a> and <a href="http://csharp-video-tutorials.blogspot.com/2015/08/load-image-from-database-in-aspnet.html">170</a> from <a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhXQS_p1i-HLIftB9Y7Vnxlo">ASP.NET tutorial for beginners</a> tutorial. </span> <br />
<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b>When the web page initially loads</b>, all the images should be retrieved from the database table and displayed in the GridView control. When you click upload button, the new image should be uploaded to the database, and the GridView should refresh and display the image you just uploaded.</span> <br />
<br />
<img alt="How to show images from database in gridview in asp.net" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhdyXhL6nFPAi74DmX38LPW8c4o_ElGtuGa58qUBBVBm9OlricqV5TJs6JGj2v2Ko1wg5OkwlIGxO8dwoBvxP-5dZb9ij5GGGJFAvpPcO3nf-0fQ7oiQqvpJQ9HX61Ss0icOTdC9TJKywI/s1600/how+to+show+images+from+database+in+gridview+in+asp.net.png" /> <br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif;"><b>Webform HTML</b></span><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Arial, Helvetica, sans-serif;"><span style="background: white; color: blue;"><</span><span style="background: white; color: maroon;">asp</span><span style="background: white; color: blue;">:</span><span style="background: white; color: maroon;">FileUpload</span><span style="background: white;"> </span><span style="background: white; color: red;">ID</span><span style="background: white; color: blue;">="FileUpload1"</span><span style="background: white;"> </span><span style="background: white; color: red;">runat</span><span style="background: white; color: blue;">="server"</span><span style="background: white;"> </span><span style="background: white; color: blue;">/></span><span style="background: white;"><o:p></o:p></span></span></div>
</div>
</div>
</div>
bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-499533489353930262015-09-26T02:39:00.021-07:002015-10-07T05:50:43.957-07:00Load image from database in asp.net<div class='post-body entry-content' id='post-body-6208107422433062955' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2014/10/using-aspnet-validation-controls-with.html" style="font-family: Arial, Helvetica, sans-serif;">Part 167 - Using ASP.NET validation controls with recaptcha</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/customizing-recaptcha-control_12.html">Part 168 - Customizing recaptcha control</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2015/08/save-image-to-database-using-aspnet.html">Part 169 - Save image to database using asp.net</a></span> <br /> <br /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss <b>how to load image from database using asp.net and c#</b>. This is continuation to <a href="http://dreamit-sanjay.blogspot.in/2015/09/save-image-to-database-using-aspnet.html">Part 169</a>. Please watch <a href="http://dreamit-sanjay.blogspot.in/2015/09/save-image-to-database-using-aspnet.html">Part 169</a> from <a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhXQS_p1i-HLIftB9Y7Vnxlo">ASP.NET tutorial for beginner</a>. </span> <br /> <br /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">When we click on <b>"View Uploaded Image"</b> link, the user will be redirected to <b>WebForm2.aspx</b>. The Id of the image will be passed as a query string parameter. In the page load event, we need to retrieve the image from the database and display it on the web page.</span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 1 : </b>Create stored procedure to retrieve image by Id.</span><br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Create</span> <span style="color: blue;">procedure</span> spGetImageById<o:p></o:p></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-23947802165666784992015-09-26T02:39:00.019-07:002015-10-07T05:51:32.845-07:00Save image to database using asp.net<div class='post-body entry-content' id='post-body-2029294701863784029' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2014/10/captcha-control-in-aspnet.html" style="font-family: Arial, Helvetica, sans-serif;">Part 166 - Captcha control in asp.net</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/using-aspnet-validation-controls-with.html">Part 167 - Using ASP.NET validation controls with recaptcha</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/customizing-recaptcha-control_12.html">Part 168 - Customizing recaptcha control</a></span> <br /> <br /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss <b>how to save images to database table using asp.net and c#</b>. </span> <br /> <br /> <br /> <br /> <img alt="Save image to database using asp.net" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdcGgQ4XIPSzf0BCMaV2x3454wuJdLQVYoapNaOv1JnR4r7f6fqDNZ0en3kC-Orbt65n-l1NTmfyw6Diw96D2MYiFgkv7ikUQmXE9QeeR3ZhLBdPIy2N5f8DRepzCSo5reKl3A0F5c5J4/s1600/Save+image+to+database+using+asp.net.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">When <b>upload button is clicked</b>, the image should be uploaded to a database table and <b>"View Uploaded Image"</b> link should appear. When you click on this link we should load the image from the database and display it on the web page.</span> <br /> <br /> <img alt="upload image to database asp.net" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFIcrZavd7Geya8iwjIRJuuRnUAzwtWu6fP9yH8vRXotMLUh0VSvKJhMR63dVFON-XNpD4mrwJ8B-d3DUjk4G9WnyoVzJZwEpVlL1Y6Zi6XXI4450ZOy7sUAVYvMqz6kedtM9tuD6tuPU/s1600/upload+image+to+database+asp.net.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss how to upload the image to the database. In our next video we will discuss how to download the image from the database and display it on the web page.</span> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 1 : </b>Create table <b>tblImages</b>. This table stores the uploaded images along with it's name and size in bytes.</span> <br /> <br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Create</span> <span style="color: blue;">table</span> tblImages<o:p></o:p></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-66289797986365567302015-09-26T02:39:00.017-07:002015-09-26T02:39:38.628-07:00Customizing recaptcha control<div class='post-body entry-content' id='post-body-8801243369717554007' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2014/10/part-165-how-to-display-icon-for.html" style="font-family: Arial, Helvetica, sans-serif;">Part 165 - How to display an icon for website on browser tab</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/captcha-control-in-aspnet.html">Part 166 - Captcha control in asp.net</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/using-aspnet-validation-controls-with.html">Part 167 - Using ASP.NET validation controls with recaptcha</a></span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this short video <b>we will discuss using the standard themes that come with recaptcha control to customize it's look and feel in an asp.net web application</b>. </span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>The following are the different standard themes available.</b> The default theme is red.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. red</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">2. white</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">3. blackglass</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">4. clean</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">The <b>Theme </b>property can be set <b>declaratively in the HTML</b> or <b>programatically in the code-behind </b>file. The theme that is set programatically overrides the theme that is set declaratively in the HTML.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">The following example sets the <b>Theme </b>property to <b>blackglass</b></span><br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">recaptcha</span><span style="color: blue;">:</span><span style="color: maroon;">RecaptchaControl</span> <span style="color: red;">ID</span><span style="color: blue;">="recaptcha"</span> <span style="color: red;">Theme</span><span style="color: blue;">="blackglass"</span><o:p></o:p></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-55648194768689294472015-09-26T02:39:00.015-07:002015-09-26T02:39:34.313-07:00Using ASP.NET validation controls with recaptcha<div class='post-body entry-content' id='post-body-3309006903184177653' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/11/part-164-displaying-organization.html" style="font-family: Arial, Helvetica, sans-serif;">Part 164 - Displaying organization employee chart using treeview control</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/part-165-how-to-display-icon-for.html">Part 165 - How to display an icon for website on browser tab</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/captcha-control-in-aspnet.html">Part 166 - Captcha control in asp.net</a></span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video, we will discuss <b>using ASP.NET validation controls with recaptcha control</b>. This is continuation to Part <a href="http://csharp-video-tutorials.blogspot.com/2014/10/captcha-control-in-aspnet.html">166</a>. Please watch <a href="http://csharp-video-tutorials.blogspot.com/2014/10/captcha-control-in-aspnet.html">Part 166</a>, before proceeding. </span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">If you have a <b>validation summary control </b>on the page and if the Recaptcha control has failed validation it automatically displays the error message in Validation Summary control. All you need is a validation summary control on the page where you want the error message to appear.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Include validation summary control on the page</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue; line-height: 115%;"><</span><span style="color: maroon; line-height: 115%;">asp</span><span style="color: blue; line-height: 115%;">:</span><span style="color: maroon; line-height: 115%;">ValidationSummary</span><span style="line-height: 115%;"> </span><span style="color: red; line-height: 115%;">ID</span><span style="color: blue; line-height: 115%;">="ValidationSummary1"</span><span style="line-height: 115%;"> </span><span style="color: red; line-height: 115%;">ForeColor</span><span style="color: blue; line-height: 115%;">="Red"</span><span style="line-height: 115%;"> </span><span style="color: red; line-height: 115%;">runat</span><span style="color: blue; line-height: 115%;">="server"</span><span style="line-height: 115%;"> </span><span style="color: blue; line-height: 115%;">/></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Run the application and click the Submit Button. Notice that the error message is displayed in the validation summary control as expected.</span> <br /> <img alt="Using ASP.NET validation controls with recaptcha" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFImTtxHfsVSUqj07PYkddJG92i7Uny-a9-S1IOlxBLc9PYnBM7RNuQkXOBOJFDwEc6Kc4M5GN9zTMngmw_UcMSOqjoArDWp82v-C3YRzLp3osK2xLMxp4N7iV-QbfTA_XOak9JfEYEMOM/s1600/Using+ASP.NET+validation+controls+with+recaptcha.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Now let's discuss <b>using a custom validator control with the recaptcha control</b>. When the word verification fails we want to display a <span style="color: red;">RED asterisk (<b>*</b>)</span> next to the captcha control and the error message in validation summary control.</span> <br /> <img alt="using asp.net custom validator with recaptcha control" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJD5Mk5E23MTuPF-ZeBcPeaIit9M2KXuHRcziffMzGTc73hWtBIiStx5EmCbtWlgos5eYK472wJpqDfpXrpb1hNiKZ-blTSbh7pW3oplag-HSsxsi7rG4OhXeRH_154TAtFgL_lcRN01J_/s1600/using+asp.net+custom+validator+with+recaptcha+control.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>To achieve this</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 1 :</b> Include the custom validator on the page where you want the RED asterisk (*) to appear</span><br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: maroon;">asp</span><span style="color: blue;">:</span><span style="color: maroon;">CustomValidator</span><b> </b><span style="color: red;">ID</span><span style="color: blue;">="CustomValidator1"</span><b> </b><span style="color: red;">runat</span><span style="color: blue;">="server"</span><b> </b><span style="color: red;">Text</span><span style="color: blue;">="*"</span><b> </b><span style="color: red;">ForeColor</span><span style="color: blue;">="Red"</span><b><o:p></o:p></b></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-87098859493814315642015-09-26T02:39:00.013-07:002015-09-26T02:39:30.277-07:00Captcha control in asp.net<div class='post-body entry-content' id='post-body-3395196298201619543' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/11/part-163-dynamically-adding-treenodes.html" style="font-family: Arial, Helvetica, sans-serif;">Part 163 - Dynamically adding treenodes to treeview control</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/11/part-164-displaying-organization.html">Part 164 - Displaying organization employee chart using treeview control</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2014/10/part-165-how-to-display-icon-for.html">Part 165 - How to display an icon for website on browser tab</a></span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video, we will discuss using captcha control in asp.net web application. </span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>What is the use of Captcha control </b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">The term <b>CAPTCHA </b>stands for <b>Completely Automated Public Turing Test To Tell Computers and Humans Apart</b>. The following are the 2 most compelling reason for using captcha control </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;">1. To prevent automated computer programs from submitting comments (SPAM). CAPTCHA control ensures only humans can enter comments.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;">2. To prevent bogus user registrations. For example, when you try to create a new gmail account, notice that there is a captcha control displayed on the registration page. This ensures only humans can register and not automated scripts.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;">It is very difficult for automated computer programs to read the distorted text displayed in a captcha control.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Example : </b>The data entered in the webform below should only be saved to the database table when captcha control passes validation</span> <br /> <img alt="captcha in asp.net" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi24WNllQzIbMsnuLD8Qu4spfoEw-9i1crBYX2bX4qSrN7Nj7jhCa5tqNJQaU0-fvYbxqj84yO0SdNmkLQvRk0bJ_xrZt9ZSIOfdR77QRGm5bGRNpqhsWNI4BTDdau_PXtuiv4XCXbuHeXh/s1600/captcha+in+asp.net.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">There are several free captcha controls available on the internet. I have tested <b>reCAPTCHA </b>control with ASP.NET and works very well. It is very easy to integrate as well. Here are the steps.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 1 :</b> Sign up for API keys.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://developers.google.com/recaptcha/intro">https://developers.google.com/recaptcha/intro</a></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 2 : </b>Download reCAPTCHA ASP.NET library</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="https://developers.google.com/recaptcha/docs/aspnet">https://developers.google.com/recaptcha/docs/aspnet</a></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 3 :</b> Extract Recaptcha.dll from the downloaded ZIP folder</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 4 :</b> Create an empty asp.net web application. Name it Demo. Add a reference to Recaptcha.dll assembly.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 5 : </b>Include the database connection string in web.config file</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><br /></span> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Step 6 : </b>Create database table RegisteredUsers to store data</span><br /> <div class="MsoNormal" style="margin-bottom: 0.0001pt;"> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue; font-size: 12pt;">Create</span><span style="font-size: 12pt;"> <span style="color: blue;">table</span> RegisteredUsers<o:p></o:p></span></span></div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-75325112588253543762015-09-26T02:39:00.011-07:002015-09-26T02:39:26.286-07:00How to display an icon for website on browser tab<div class='post-body entry-content' id='post-body-5548756376984784221' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-162-binding-aspnet-treeview.html" style="font-family: Arial, Helvetica, sans-serif;">Part 162 - Binding asp.net treeview control to database table</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/11/part-163-dynamically-adding-treenodes.html">Part 163 - Dynamically adding treenodes to treeview control</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/11/part-164-displaying-organization.html">Part 164 - Displaying organization employee chart using treeview control</a></span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video we will discuss <b>displaying an icon for an asp.net website on a browser tab.</b> Let me explain what I mean. </span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Navigate to <a href="http://www.google.com/">http://www.Google.com</a>, notice in the address bar an icon is displayed. </span> <br /> <img alt="how to display icon on browser tab" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio_Mui2KlQsh2zzv_vO8YLt0T-dL3vMFxXbu9dlvi0IB8Hi5K2IjpgaDvktSIf3cyXzTDo9Nv3vekRUZeHEwNUipVDr8F1aQ712WCsWsEDOJj0YWwxXqJUEZBSmXsnw2RNcUazJ6T32uyo/s1600/how+to+display+icon+on+browser+tab.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">This icon is called <b>favicon </b>(short for Favorite icon). It is also known as a shortcut icon, Web site icon, tab icon or bookmark icon.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">The size of the image should be <b>16 X16 pixels</b> and it should be named <b>favicon.ico</b>. You can either create your own image or use many free websites that are available. <a href="http://www.favicon.cc/">http://www.favicon.cc</a> is one such website. </span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">Once you have the image, place it in the root directory of your web application and include the following link in the head section of the page. If you have a master page, place it in the head section of the master page.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue; line-height: 115%;"><</span><span style="color: maroon; line-height: 115%;">link</span><span style="line-height: 115%;"> </span><span style="color: red; line-height: 115%;">rel</span><span style="color: blue; line-height: 115%;">="shortcut icon"</span><span style="line-height: 115%;"> </span><span style="color: red; line-height: 115%;">href</span><span style="color: blue; line-height: 115%;">="~/favicon.ico"</span><span style="line-height: 115%;"> </span><span style="color: red; line-height: 115%;">type</span><span style="color: blue; line-height: 115%;">="image/x-icon"/></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">If you are testing this on your local machine, make sure to use local IIS Web Server instead of built-in visual studio development server, otherwise the image will not be displayed.</span> <br /> <br /> <a href=" "> <img src=" " /></a> </div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-39295165973892178612015-09-26T02:39:00.009-07:002015-09-26T02:39:22.289-07:00Displaying organization chart using treeview control<div class='post-body entry-content' id='post-body-8463510377804346365' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-161-binding-treeview-control-to.html" style="font-family: Arial, Helvetica, sans-serif;">Part 161 - Binding treeview control to web.sitemap file</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-162-binding-aspnet-treeview.html">Part 162 - Binding asp.net treeview control to database table</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/11/part-163-dynamically-adding-treenodes.html">Part 163 - Dynamically adding treenodes to treeview control</a></span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video, we will discuss, displaying organization employee chart using <b>TreeView </b>control. </span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>We will use the following table tblEmployee in this demo</b></span> <br /> <img alt="table tblEmployee" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhbj_1oJJP_T2ikpaikovRkwpc7p42qR2BDsl4OSeV7brwBenbKIPqzu3rFOQx7-5A_ZLgnqcEymF3rQlK6tbuYB6N4pdMRoS7YlvuR3Bk0zBYcDKBlazhcdVjb56fxFu_cKrOD-2PPfQDi/s1600/table+tblEmployee.png" /> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">We want to display above data in a <b>TreeView </b>control as shown below. A check box should be displayed next to every TreeNode. On clicking the button, the selected employees must be added to the listbox.</span> <br /> <img alt="Displaying organization chart in asp.net" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgIxlMvbwsFaCXKUmJ81PwGsNzgTxj-pGp2bRNMSYRASY1zKBaquw66id5ctyJUOEwHgfEjTs_gVhIfmGTnUfPKar5F895BV3KHOT4Y00f_FpGfFmI6HtcERRqwvTGZBvQ_VPY0hdCOk-E5/s1600/Displaying+organization+chart+in+asp.net.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>SQL script to create and populate table tblEmployee</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Create table </span>tblEmployee</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">(</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ID <span style="color: blue;">int identity primary key</span>,</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> Name <span style="color: blue;">nvarchar</span>(50),</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ManagerId <span style="color: blue;">int foreign key references </span>tblEmployee(ID)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">)</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Insert into</span> tblEmployee <span style="color: blue;">values</span>(<span style="color: red;">'David'</span>, <span style="color: blue;">NULL</span>)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblEmployee </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;">(<span style="color: red;">'Sam'</span>, 1)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblEmployee </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;">(<span style="color: red;">'Pam'</span>, 1)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblEmployee </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;">(<span style="color: red;">'Mike'</span>, 1)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblEmployee </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;">(<span style="color: red;">'John'</span>, 2)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblEmployee </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;">(<span style="color: red;">'Tara'</span>, 2)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblEmployee </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;">(<span style="color: red;">'Todd'</span>, 4)</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Stored procedure to retrieve data from table tblEmployee </b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Create Proc </span>spGetEmployees</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">as</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Begin</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Select</span> ID, Name, ManagerId <span style="color: blue;">from </span>tblEmployee</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">End</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>ASPX HTML</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><div style="font-family:Arial"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <table></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <tr></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <td style="border:1px solid black"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <asp:TreeView ID="TreeView1" ShowCheckBoxes="All" </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> runat="server"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </asp:TreeView></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </td></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <td></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <asp:Button ID="Button1" runat="server" onclick="Button1_Click" </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> Text=">>" /> </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </td></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <td></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <asp:ListBox ID="ListBox1" runat="server" Height="145px" </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> Width="100px"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </asp:ListBox></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </td></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </tr></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </table></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"></div></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>ASPX.CS Code:</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">using</span> System;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Web.UI.WebControls;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Data;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Data.SqlClient;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Configuration;</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">namespace </span>WebFormsDemo</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">{</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">public partial class</span> WebForm1 : System.Web.UI.<span style="color: #3d85c6;">Page</span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">protected void</span> Page_Load(<span style="color: blue;">object </span>sender, <span style="color: #3d85c6;">EventArgs </span>e)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(!IsPostBack)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetTreeViewItems();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">private void</span> GetTreeViewItems()</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">string </span>cs = <span style="color: #3d85c6;">ConfigurationManager</span>.ConnectionStrings[<span style="color: #990000;">"DBCS"</span>].ConnectionString;</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">SqlConnection</span> con = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">SqlConnection</span><span style="font-family: Arial, Helvetica, sans-serif;">(cs);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">SqlDataAdapter</span><span style="font-family: Arial, Helvetica, sans-serif;"> da = </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">new</span><span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">SqlDataAdapter</span>(<span style="color: #990000;">"spGetEmployees"</span>, con);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">DataSet </span>ds = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">DataSet</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> da.Fill(ds);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ds.Relations.Add(<span style="color: #990000;">"ChildRows"</span>, ds.Tables[0].Columns[<span style="color: #990000;">"ID"</span>],</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ds.Tables[0].Columns[<span style="color: #990000;">"ManagerId"</span>]);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">foreach </span>(<span style="color: #3d85c6;">DataRow </span>level1DataRow <span style="color: blue;">in </span>ds.Tables[0].Rows)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(<span style="color: blue;">string</span>.IsNullOrEmpty(level1DataRow[<span style="color: #990000;">"ManagerId"</span>].ToString()))</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">TreeNode </span>parentTreeNode = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">TreeNode</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> parentTreeNode.Text = level1DataRow[<span style="color: #990000;">"Name"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> parentTreeNode.Value = level1DataRow[<span style="color: #990000;">"ID"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetChildRows(level1DataRow, parentTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> TreeView1.Nodes.Add(parentTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">private void</span> GetChildRows(<span style="color: #3d85c6;">DataRow </span>dataRow, <span style="color: #3d85c6;">TreeNode </span>treeNode)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">DataRow</span>[] childRows = dataRow.GetChildRows(<span style="color: #990000;">"ChildRows"</span>);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">foreach </span>(<span style="color: #3d85c6;">DataRow </span>row <span style="color: blue;">in </span>childRows)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">TreeNode </span>childTreeNode = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">TreeNode</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> childTreeNode.Text = row[<span style="color: #990000;">"Name"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> childTreeNode.Value = row[<span style="color: #990000;">"ID"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> treeNode.ChildNodes.Add(childTreeNode);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(row.GetChildRows(<span style="color: #990000;">"ChildRows"</span>).Length > 0)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetChildRows(row, childTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">protected void</span> Button1_Click(<span style="color: blue;">object </span>sender, <span style="color: #3d85c6;">EventArgs </span>e)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ListBox1.Items.Clear();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetSelectedTreeNodes(TreeView1.Nodes[0]);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">private void</span> GetSelectedTreeNodes(<span style="color: #3d85c6;">TreeNode </span>parentTreeNode)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(parentTreeNode.Checked)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ListBox1.Items.Add(parentTreeNode.Text + <span style="color: #990000;">" - "</span> + parentTreeNode.Value);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(parentTreeNode.ChildNodes.Count > 0)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">foreach </span>(<span style="color: #3d85c6;">TreeNode </span>childTreeNode <span style="color: blue;">in </span>parentTreeNode.ChildNodes)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetSelectedTreeNodes(childTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">}</span> <br /> <br /> <a href=" "> <img src=" " /></a> </div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-69771945006828836342015-09-26T02:39:00.007-07:002015-09-26T02:39:17.732-07:00Dynamically adding treenodes to treeview control<div class='post-body entry-content' id='post-body-3377921942777183195' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-160-binding-aspnet-treeview.html" style="font-family: Arial, Helvetica, sans-serif;">Part 160 - Binding asp.net treeview control to an xml file</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-161-binding-treeview-control-to.html">Part 161 - Binding treeview control to web.sitemap file</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-162-binding-aspnet-treeview.html">Part 162 - Binding asp.net treeview control to database table</a></span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">This is continuation to <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-162-binding-aspnet-treeview.html">Part 162</a>. Please watch <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-162-binding-aspnet-treeview.html">Part 162</a>, before proceeding. </span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">We want to bind this data to a <b>TreeView </b>control. If you need the SQL Script to create and populate the table with sample data, please refer to <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-162-binding-aspnet-treeview.html">Part 162</a>.</span> <br /> <img alt="Dynamically adding treenodes to treeview control in asp.net" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTHysHLTobJa5o84mg5o3LfsydfsqjX9L1D1U6Uv4T3dwjaFipCn6QOvFdzW9gVL7yjkF5ySbq6QOkt8HqCqRsLKpNiWZSgYo5bFC47QJvSnBUEXpdrCVfUzhch-sBGsuglCNe-OP6hsNF/s1600/Dynamically+adding+treenodes+to+treeview+control+in+asp.net.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>This is how the treeview control should look.</b></span> <br /> <img alt="Adding treenodes to treeview control from a database table" border="1" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzDGOdR1fd10rqdW4CsLgNhqsIHU0S7Up_Q6h9_qRMeIa9BYruH6We7QAmwhEME2xafSdWzvG66B3kqxEE8HpxWw9nGQqVxY4FXToaFuNZxWBYhQTLl62fT0XZtt64GZYqO6JSqaXK7YEU/s1600/Adding+treenodes+to+treeview+control+from+a+database+table.png" /> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Drag and drop a treeview control</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:TreeView </span><span style="color: red;">ID</span><span style="color: blue;">="Treeview1" </span><span style="color: red;">Target="_blank"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"></</span><span style="color: #990000;">asp:TreeView</span><span style="color: blue;">></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Copy and paste the following code in the code-behind file.</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">using</span> System;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Collections.Generic;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Linq;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Web;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Web.UI;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Web.UI.WebControls;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Data;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Data.SqlClient;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Configuration;</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">namespace </span>WebFormsDemo</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">{</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">public partial class</span> <span style="color: #3d85c6;">WebForm1 </span>: System.Web.UI.<span style="color: #3d85c6;">Page</span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">protected void</span> Page_Load(<span style="color: blue;">object </span>sender, <span style="color: #3d85c6;">EventArgs </span>e)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(!IsPostBack)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetTreeViewItems();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">private void</span> GetTreeViewItems()</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">string </span>cs = <span style="color: #3d85c6;">ConfigurationManager</span>.ConnectionStrings[<span style="color: #990000;">"DBCS"</span>].ConnectionString;</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">SqlConnection</span> con = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">SqlConnection</span><span style="font-family: Arial, Helvetica, sans-serif;">(cs);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">SqlDataAdapter</span><span style="font-family: Arial, Helvetica, sans-serif;"> da = </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">new</span><span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">SqlDataAdapter</span>(<span style="color: #990000;">"spGetTreeViewItems"</span>, con);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">DataSet </span>ds = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">DataSet</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> da.Fill(ds);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ds.Relations.Add(<span style="color: #990000;">"ChildRows"</span>, ds.Tables[0].Columns[<span style="color: #990000;">"ID"</span>], </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ds.Tables[0].Columns[<span style="color: #990000;">"ParentId"</span>]);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">foreach </span>(<span style="color: #3d85c6;">DataRow </span>level1DataRow <span style="color: blue;">in </span>ds.Tables[0].Rows)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(<span style="color: blue;">string</span>.IsNullOrEmpty(level1DataRow[<span style="color: #990000;">"ParentId"</span>].ToString()))</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">TreeNode </span>parentTreeNode = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">TreeNode</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> parentTreeNode.Text = level1DataRow[<span style="color: #990000;">"TreeViewText"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> parentTreeNode.NavigateUrl = level1DataRow[<span style="color: #990000;">"NavigateURL"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetChildRows(level1DataRow, parentTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> Treeview1.Nodes.Add(parentTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">private void</span> GetChildRows(<span style="color: #3d85c6;">DataRow </span>dataRow, <span style="color: #3d85c6;">TreeNode </span>treeNode)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">DataRow</span>[] childRows = dataRow.GetChildRows(<span style="color: #990000;">"ChildRows"</span>);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">foreach </span>(<span style="color: #3d85c6;">DataRow </span>row <span style="color: blue;">in </span>childRows)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">TreeNode </span>childTreeNode = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">TreeNode</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> childTreeNode.Text = row[<span style="color: #990000;">"TreeViewText"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> childTreeNode.NavigateUrl = row[<span style="color: #990000;">"NavigateURL"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> treeNode.ChildNodes.Add(childTreeNode);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(row.GetChildRows("ChildRows").Length > 0)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetChildRows(row, childTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">}</span> <br /> <br /> <a href=" "> <img src=" " /></a> </div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-74229466869884886072015-09-26T02:39:00.005-07:002015-09-26T02:39:13.229-07:00Binding asp.net treeview control to database table<div class='post-body entry-content' id='post-body-5644838165616133695' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-159-treeview-control-in-aspnet.html" style="font-family: Arial, Helvetica, sans-serif;">Part 159 - TreeView control</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-160-binding-aspnet-treeview.html">Part 160 - Binding asp.net treeview control to an xml file</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-161-binding-treeview-control-to.html">Part 161 - Binding treeview control to web.sitemap file</a></span><br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video, we will discuss <b>binding asp.net treeview control </b>to <b>database table. </b>This is continuation to <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-161-binding-treeview-control-to.html">Part 161</a>, please watch <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-161-binding-treeview-control-to.html">Part 161</a> before proceeding.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>1. </b>Create the required database table using the script below.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Create table </span>tblTreeViewItems</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">(</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ID <span style="color: blue;">int identity primary key</span>,</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TreeViewText <span style="color: blue;">nvarchar</span>(50),</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>NavigateURL </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">nvarchar</span><span style="font-family: Arial, Helvetica, sans-serif;">50),</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ParentId <span style="color: blue;">int references </span>tblTreeViewItems(ID)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">)</span><br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="color: #38761d; font-family: Arial, Helvetica, sans-serif;">-- Insert top level TreeView items</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Insert into</span> tblTreeViewItems <span style="color: blue;">values </span>(<span style="color: red;">'Home', '~/Home.aspx'</span>, NULL)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Employee', '~/Employee.aspx'</span>, NULL)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Employer', '~/Employer.aspx'</span>, NULL)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Admin', '~/Admin.aspx'</span>, NULL)</span><br /> <span style="color: #38761d; font-family: Arial, Helvetica, sans-serif;">-- Insert Employee child items</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Upload Resume', '~/UploadResume.aspx'</span>, 2)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Edit Resume', '~/EditResume.aspx'</span>, 2)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'View Resume', '~/ViewResume.aspx'</span>, 2)</span><br /> <span style="color: #38761d; font-family: Arial, Helvetica, sans-serif;">-- Insert Employer child items</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Upload Job', '~/UploadJob.aspx'</span>, 3)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Edit Job', '~/EditJob.aspx'</span>, 3)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'View Job', '~/ViewJob.aspx'</span>, 3)</span><br /> <span style="color: #38761d; font-family: Arial, Helvetica, sans-serif;">-- Insert Admin child items</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Add User', '~/AddUser.aspx'</span>, 4)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'Edit User', '~/EditUser.aspx'</span>, 4)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'View User', '~/ViewUser.aspx'</span>, 4)</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>2. </b>Create a stored procedure that returns data from <b>tblTreeViewItems </b>table.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Create proc </span>spGetTreeViewItems</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">as</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Begin</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><span class="Apple-tab-span" style="white-space: pre;"> </span>Select</span> ID, TreeViewText, NavigateURL, ParentId</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span class="Apple-tab-span" style="white-space: pre;"> </span><span style="color: blue;">from </span>tblTreeViewItems</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">End</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>3. </b>Drag and drop a <b>treeview </b>control on the <b>webform</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:TreeView </span><span style="color: red;">ID</span><span style="color: blue;">="Treeview1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"></</span><span style="color: #990000;">asp:TreeView</span><span style="color: blue;">></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>4. </b>Copy and paste the following ado.net code in the code-behind file.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">protected void </span>Page_Load(<span style="color: blue;">object </span>sender, <span style="color: #3d85c6;">EventArgs </span>e)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">{</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(!IsPostBack)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> GetTreeViewItems();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">}</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">private void</span> GetTreeViewItems()</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">{</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">string </span>cs = <span style="color: #3d85c6;">ConfigurationManager</span>.ConnectionStrings[<span style="color: #990000;">"DBCS"</span>].ConnectionString;</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">SqlConnection </span>con = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">SqlConnection</span><span style="font-family: Arial, Helvetica, sans-serif;">(cs);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">SqlDataAdapter</span> da = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">SqlDataAdapter</span><span style="font-family: Arial, Helvetica, sans-serif;">(<span style="color: #990000;">"spGetTreeViewItems"</span>, con);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">DataSet </span><span style="font-family: Arial, Helvetica, sans-serif;">ds = </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">new </span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">DataSet</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> da.Fill(ds);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ds.Relations.Add(<span style="color: #990000;">"ChildRows"</span>, ds.Tables[0].Columns[<span style="color: #990000;">"ID"</span>], </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> ds.Tables[0].Columns[<span style="color: #990000;">"ParentId"</span>]);</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">foreach</span> (<span style="color: #3d85c6;">DataRow </span>level1DataRow <span style="color: blue;">in </span>ds.Tables[0].Rows)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">if </span>(<span style="color: blue;">string</span>.IsNullOrEmpty(level1DataRow[<span style="color: #990000;">"ParentId"</span>].ToString()))</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">TreeNode </span>treeNode = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">TreeNode</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> treeNode.Text = level1DataRow[<span style="color: #990000;">"TreeViewText"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> treeNode.NavigateUrl = level1DataRow[<span style="color: #990000;">"NavigateURL"</span>].ToString();</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">DataRow</span>[] level2DataRows = level1DataRow.GetChildRows(<span style="color: #990000;">"ChildRows"</span>);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;">foreach </span>(<span style="color: #3d85c6;">DataRow </span>level2DataRow <span style="color: blue;">in </span>level2DataRows)</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> {</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: #3d85c6;">TreeNode </span>childTreeNode = <span style="color: blue;">new </span></span><span style="color: #3d85c6; font-family: Arial, Helvetica, sans-serif;">TreeNode</span><span style="font-family: Arial, Helvetica, sans-serif;">();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> childTreeNode.Text = level2DataRow[<span style="color: #990000;">"TreeViewText"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> childTreeNode.NavigateUrl = level2DataRow[<span style="color: #990000;">"NavigateURL"</span>].ToString();</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> treeNode.ChildNodes.Add(childTreeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> Treeview1.Nodes.Add(treeNode);</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> }</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">}</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Note: </b>Please include the following <b>using </b>declarations.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">using </span>System.Data;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Data.SqlClient;</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">using</span><span style="font-family: Arial, Helvetica, sans-serif;"> System.Configuration;</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">The above code works as expected only with <b>2 levels </b>of <b>TreeNode </b>objects. If you include a third level, those <b>TreeNodes </b>will not be displayed in the TreeView control. For example, if you execute the following insert sql script. These rows will not be displayed in the TreeView control, we will discuss fixing this in our next video.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;">Insert into</span> tblTreeViewItems <span style="color: blue;">values</span> (<span style="color: red;">'AAA', '~/AAA.aspx'</span>, 5)</span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;">Insert into</span><span style="font-family: Arial, Helvetica, sans-serif;"> tblTreeViewItems </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">values</span><span style="font-family: Arial, Helvetica, sans-serif;"> (<span style="color: red;">'BBB', '~/BBB.aspx'</span>, 5)</span> <br /> <br /> <a href=" "> <img src=" " /></a> </div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-3802333079079104722015-09-26T02:39:00.003-07:002015-09-26T02:39:08.180-07:00Binding treeview control to web.sitemap file<div class='post-body entry-content' id='post-body-1038810826972091278' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-158-binding-aspnet-menu-control-to.html" style="font-family: Arial, Helvetica, sans-serif;">Part 158 - Binding menu control to web.sitemap file</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-159-treeview-control-in-aspnet.html">Part 159 - TreeView control</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-160-binding-aspnet-treeview.html">Part 160 - Binding asp.net treeview control to an xml file</a></span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">This is continuation to <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-160-binding-aspnet-treeview.html">Part 160</a>. Please watch <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-160-binding-aspnet-treeview.html">Part 160</a>, before proceeding. In <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-158-binding-aspnet-menu-control-to.html">Part 158</a>, we discussed binding <b>menu control </b>to <b>web.sitemap </b>file using <b>sitemapdatasource </b>control. Binding <b>treeview </b>control to <b>web.sitemap </b>file is similar. </span> <br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Here are the steps to achieve this.</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>1.</b> Add <b>web.sitemap </b>file. Copy and paste the following XML</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><?xml version="1.0" encoding="utf-8" ?></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode title="DummyRoot"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/Home.aspx" title="Home"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/Employee.aspx" title="Employee"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/UploadResume.aspx" title="Upload Resume"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/EditResume.aspx" title="Edit Resume"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/ViewResume.aspx" title="View Resume"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </siteMapNode></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/Employer.aspx" title="Employer"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/UploadJob.aspx" title="Upload Job"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/EditJob.aspx" title="Edit Job"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/ViewJob.aspx" title="View Job"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </siteMapNode></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/Admin.aspx" title="Admin"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/AddUser.aspx" title="Add User"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/EditUser.aspx" title="Edit User"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <siteMapNode url="~/ViewUser.aspx" title="View User"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </siteMapNode></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </siteMapNode></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"></siteMap></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>2. </b>Drag and drop <b>"SiteMapDataSource" </b>control onto the webform. By default, a <b>SiteMapDataSource </b>control reads data automatically from <b>web.sitemap </b>file. </span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:SiteMapDataSource </span><span style="color: red;">ID</span><span style="color: blue;">="SiteMapDataSource1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server" /></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>3. </b>Finally drag and drop <b>TreeView </b>control onto the <b>webform </b>and set <b>DataSourceID </b>attribute, to the <b>ID </b>of the <b>SiteMapDataSource </b>control created in <b>Step 2.</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:TreeView </span><span style="color: red;">ID</span><span style="color: blue;">="Treeview1"</span> <span style="color: red;">DataSourceID</span><span style="color: blue;">="SiteMapDataSource1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"></</span><span style="color: #990000;">asp:TreeView</span><span style="color: blue;">></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">That's it. Run the application and notice that, the <b>TreeView </b>control is bound to <b>web.sitemap </b>file. One problem here is that, the <b>Root node </b>is also displayed.</span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Hiding Root node in the TreeView control.</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;">To hide the Root node in the TreeView control, set <b>ShowStartingNode </b>attribute of the <b>SiteMapDataSource </b>control to <b>false.</b></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:SiteMapDataSource </span><span style="color: red;">ShowStartingNode</span><span style="color: blue;">="false"</span> <span style="color: red;">ID</span><span style="color: blue;">="SiteMapDataSource1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server" /></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">To open the target page in a new window set <b>Target </b>attribute of <b>TreeView </b>control to <b>_blank </b>as shown below.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:TreeView </span><span style="color: red;">ID</span><span style="color: blue;">="Treeview1"</span> <span style="color: red;">Target</span><span style="color: blue;">="_blank"</span> <span style="color: red;">DataSourceID</span><span style="color: blue;">="SiteMapDataSource1" </span><span style="color: red;">runat</span><span style="color: blue;">="server"></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"></</span><span style="color: #990000;">asp:TreeView</span><span style="color: blue;">></span></span> <br /> <br /> <a href=" "> <img src=" " /></a> </div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0tag:blogger.com,1999:blog-816027227256254677.post-77733765293793244552015-09-26T02:39:00.001-07:002015-09-26T02:39:03.961-07:00Binding treeview control to an xml file<div class='post-body entry-content' id='post-body-6524465140293416415' itemprop='articleBody'> <div dir="ltr" style="text-align: left;" trbidi="on"> <span style="font-family: Arial, Helvetica, sans-serif;"><b>Suggested Videos</b></span><br /> <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-157-sitemappath-control-in-aspnet.html" style="font-family: Arial, Helvetica, sans-serif;">Part 157 - SiteMapPath control in asp.net</a><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-158-binding-aspnet-menu-control-to.html">Part 158 - Binding menu control to web.sitemap file</a></span> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-159-treeview-control-in-aspnet.html">Part 159 - TreeView control</a></span><br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">In this video, we will discuss <b>binding asp.net TreeView </b>control to an <b>xml file </b>using <b>xmldatasource </b>control. This is continuation to <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-159-treeview-control-in-aspnet.html">Part 159</a>, so please watch <a href="http://csharp-video-tutorials.blogspot.com/2013/10/part-159-treeview-control-in-aspnet.html">Part 159</a> before proceeding. </span><br /> <br /> <script type="text/javascript"><!-- google_ad_client = "ca-pub-6328538092426311"; /* 300 X 250 CS Video Tutorial */ google_ad_slot = "3773608589"; google_ad_width = 300; google_ad_height = 250; //--> </script> <script type="text/javascript" src=" "> </script> <br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;">1. Add an <b>XML file </b>and name it <b>TreeViewData.xml. </b>Copy and paste the following xml.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><?xml version="1.0" encoding="utf-8" ?></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><Items></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/Home.aspx" Text="Home"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/Employee.aspx" Text="Employee"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/UploadResume.aspx" Text="Upload Resume"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/EditResume.aspx" Text="Edit Resume"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/ViewResume.aspx" Text="View Resume"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </TreeViewItem></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/Employer.aspx" Text="Employer"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/UploadJob.aspx" Text="Upload Job"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/EditJob.aspx" Text="Edit Job"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/ViewJob.aspx" Text="View Job"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </TreeViewItem></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/Admin.aspx" Text="Admin"></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/AddUser.aspx" Text="Add User"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/EditUser.aspx" Text="Edit User"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <TreeViewItem NavigateUrl="~/ViewUser.aspx" Text="View User"/></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </TreeViewItem></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"></Items></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>2. </b>Drag and drop an <b>XmlDataSource </b>control on the webform. Set <b>XPath </b>and <b>DataFile </b>attributes as shown below. Notice that <b>DataFile </b>attribute points to the <b>XML file </b>that we added in <b>Step 1</b>.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:XmlDataSource </span><span style="color: red;">ID</span><span style="color: blue;">="XmlDataSource1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server" </span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: red;">XPath</span><span style="color: blue;">="/Items/TreeViewItem"</span> <span style="color: red;">DataFile</span><span style="color: blue;">="~/TreeViewData.xml"></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"></</span><span style="color: #990000;">asp:XmlDataSource</span><span style="color: blue;">></span></span><br /> <br /> <span style="font-family: Arial, Helvetica, sans-serif;"><b>3. </b>Drag and drop a <b>TreeView </b>control and set <b>DataSourceID </b>attribute to the <b>xmldatasource </b>control we created in <b>Step 2. </b>Also, set <b>DataBindings </b>as shown below.</span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"><span style="color: blue;"><</span><span style="color: #990000;">asp:TreeView </span><span style="color: red;">ID</span><span style="color: blue;">="TreeView1"</span> <span style="color: red;">DataSourceID</span><span style="color: blue;">="XmlDataSource1"</span> <span style="color: red;">runat</span><span style="color: blue;">="server"></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;"><</span><span style="color: #990000;">DataBindings</span><span style="color: blue;">></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: blue;"><</span><span style="color: #990000;">asp:TreeNodeBinding </span><span style="color: red;">DataMember</span><span style="color: blue;">="TreeViewItem"</span> <span style="color: red;">TextField</span><span style="color: blue;">="Text"</span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> <span style="color: red;">NavigateUrlField</span><span style="color: blue;">="NavigateUrl"</span> <span style="color: red;">Target</span><span style="color: blue;">="_blank" /></span></span><br /> <span style="font-family: Arial, Helvetica, sans-serif;"> </span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;"></</span><span style="color: #990000; font-family: Arial, Helvetica, sans-serif;">DataBindings</span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">></span><br /> <span style="color: blue; font-family: Arial, Helvetica, sans-serif;"></</span><span style="color: #990000; font-family: Arial, Helvetica, sans-serif;">asp:TreeView</span><span style="color: blue; font-family: Arial, Helvetica, sans-serif;">></span> <br /> <br /> <a href=" "> <img src=" " /></a> </div> bhsofthttp://www.blogger.com/profile/14907981215666381448noreply@blogger.com0