<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4526087644622451460</id><updated>2024-10-04T19:11:35.374-07:00</updated><category term="Asp.Net"/><category term="C#.Net"/><category term="JavaScript"/><category term="Asp.Net MVC"/><category term="MVC"/><category term="Sql Server"/><title type='text'>Asp.Net Assist</title><subtitle type='html'>Make Your Solution Easier</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-2088287922777376793</id><published>2014-12-17T02:57:00.000-08:00</published><updated>2014-12-17T02:57:24.497-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#.Net"/><title type='text'>Tips for Asp.Net</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;How to assign RequiredFiled Validator for DropDownList in Asp.Net&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;span style=&quot;color: red;&quot;&gt;Ans:
&lt;/span&gt;&lt;br /&gt;
&lt;pre class=&quot;codestyle&quot;&gt;      &lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt; &amp;lt;form id=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;form1&quot;&lt;/span&gt; runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt;&amp;gt;
        &amp;lt;div&amp;gt;
            Select Gender :
            &amp;lt;asp:DropDownList runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt; ID=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ddlList&quot;&lt;/span&gt;&amp;gt;
                &amp;lt;asp:ListItem Text=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Select&quot;&lt;/span&gt; Value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;0&quot;&lt;/span&gt;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;
                &amp;lt;asp:ListItem Text=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Male&quot;&lt;/span&gt; Value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;1&quot;&lt;/span&gt;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;
                &amp;lt;asp:ListItem Text=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Female&quot;&lt;/span&gt; Value=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;2&quot;&lt;/span&gt;&amp;gt;&amp;lt;/asp:ListItem&amp;gt;
            &amp;lt;/asp:DropDownList&amp;gt;
            &amp;lt;asp:RequiredFieldValidator runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt; ID=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;rfv&quot;&lt;/span&gt; ControlToValidate=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;ddlList&quot;&lt;/span&gt; ForeColor=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Red&quot;&lt;/span&gt; InitialValue=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;0&quot;&lt;/span&gt; ErrorMessage=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Please Select Gender&quot;&lt;/span&gt;&amp;gt;&amp;lt;/asp:RequiredFieldValidator&amp;gt;&amp;lt;br /&amp;gt;
        &amp;lt;asp:Button  runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt; ID=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;btnsubmit&quot;&lt;/span&gt; Text=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Submit&quot;&lt;/span&gt; /&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;&amp;nbsp;&lt;/pre&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Output:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixHtqBDPCyDSTAJXXGdVcZ0XtOUMrujmYdv3xDGpJ2T4Ra67nrJ7DhpxJsvPg0CT9p481f6YtJTh3NbVc1w9ISFDxnGIttXS1ECfec4PjMQzazXstDbPvxfBYV8SVjzknAHJ7txDkHvoZL/s1600/DropValidate.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixHtqBDPCyDSTAJXXGdVcZ0XtOUMrujmYdv3xDGpJ2T4Ra67nrJ7DhpxJsvPg0CT9p481f6YtJTh3NbVc1w9ISFDxnGIttXS1ECfec4PjMQzazXstDbPvxfBYV8SVjzknAHJ7txDkHvoZL/s1600/DropValidate.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;hr /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;
How to add items to DropDownList through .Cs file&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Ans:&lt;/span&gt; &amp;nbsp;In .aspx file&lt;br /&gt;
&lt;pre class=&quot;codestyle&quot;&gt;  &lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt; &amp;lt;form id=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;form1&quot;&lt;/span&gt; runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt;&amp;gt;
        &amp;lt;div&amp;gt;
            Select Gender :
            &amp;lt;asp:DropDownList runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt; ID=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;DropDownList1&quot;&lt;/span&gt;&amp;gt;             
            &amp;lt;/asp:DropDownList&amp;gt;
            &amp;lt;asp:RequiredFieldValidator runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt; ID=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;RequiredFieldValidator1&quot;&lt;/span&gt; ControlToValidate=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;DropDownList1&quot;&lt;/span&gt; ForeColor=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Red&quot;&lt;/span&gt; InitialValue=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;0&quot;&lt;/span&gt; ErrorMessage=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Please Select Gender&quot;&lt;/span&gt;&amp;gt;&amp;lt;/asp:RequiredFieldValidator&amp;gt;&amp;lt;br /&amp;gt;
        &amp;lt;asp:Button  runat=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;server&quot;&lt;/span&gt; ID=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Button1&quot;&lt;/span&gt; Text=&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Submit&quot;&lt;/span&gt; /&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/form&amp;gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;&lt;/pre&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;In .Cs file&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Page_Load(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (!IsPostBack)
        {
            ListItem item1 = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ListItem(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Select&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;0&quot;&lt;/span&gt;);
            ListItem item2 = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ListItem(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Male&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;1&quot;&lt;/span&gt;);
            ListItem item3 = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ListItem(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Female&quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;2&quot;&lt;/span&gt;);

            DropDownList1.Items.Insert(0, item1);
            DropDownList1.Items.Insert(1, item2);
            DropDownList1.Items.Insert(2, item3);
        }

    }&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Output:&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijEq4_cgSXya13gsOu0b68iAKgZofgh2XGnBfSxTgJXZZB-5xu-7peuzh9AIN98yZXPK7B-qn9ZBV18fenbe8w99vRSMv-cplvGCWpzbrk_7pRq8lc5AM4LJvqYoGzr7oy_lATsx9kyw3t/s1600/DDL2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijEq4_cgSXya13gsOu0b68iAKgZofgh2XGnBfSxTgJXZZB-5xu-7peuzh9AIN98yZXPK7B-qn9ZBV18fenbe8w99vRSMv-cplvGCWpzbrk_7pRq8lc5AM4LJvqYoGzr7oy_lATsx9kyw3t/s1600/DDL2.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;hr /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;How to Get DataKeyNames from GridView using RowUpdating Event and Button Click Event of Gridview&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Ans:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
In &lt;b&gt;RowUpdating Event &lt;/b&gt;of GridView&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;codestyle&quot;&gt;      &lt;code&gt;&lt;span style=&quot;word-wrap: normal;&quot;&gt;
&lt;/span&gt;&lt;pre style=&quot;background-color: white; color: black; margin: 0em; overflow: auto; word-wrap: normal;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Gridview1_RowUpdating(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, GridViewUpdateEventArgs e)
    {
        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if DataKeyName is type Integer&lt;/span&gt;
        Int32 DataKeyInt = Convert.ToInt32(Gridview1.DataKeys[e.RowIndex].Value.ToString());

        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if DataKeyName is type String&lt;/span&gt;

        String DataKeyString = Gridview1.DataKeys[e.RowIndex].Value.ToString();
    }&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;&lt;/pre&gt;
In &lt;b&gt;Button Click Event&lt;/b&gt; in GridView&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;codestyle&quot;&gt;      &lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Button1_Click(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        Button btn = (Button)sender;
        GridViewRow row = (GridViewRow)btn.NamingContainer;
        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if DataKeyName is type Integer&lt;/span&gt;
        Int32 DataKeyInt = Convert.ToInt32(Gridview1.DataKeys[row.RowIndex].Value.ToString());

        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if DataKeyName is type String&lt;/span&gt;

        String DataKeyString = Gridview1.DataKeys[row.RowIndex].Value.ToString();

    }&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;
  &lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;hr /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;
How to find Control in GridView Using RowUpdating Event and RowDataBound Event&lt;/span&gt;&lt;/h3&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Ans:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
In &lt;b&gt;RowUpdating&lt;/b&gt; Event&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;codestyle&quot;&gt;      &lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Gridview1_RowUpdating(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, GridViewUpdateEventArgs e)
    {
        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if we want to find TextBox Control from GridView&lt;/span&gt;
        TextBox txt = (TextBox)Gridview1.Rows[e.RowIndex].FindControl(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;txtboxID&quot;&lt;/span&gt;);
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; textboxvalue = txt.Text;

        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if we want to find Label Control from GridView&lt;/span&gt;
        Label lbl = (Label)Gridview1.Rows[e.RowIndex].FindControl(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;lblID&quot;&lt;/span&gt;);
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; lblvalue = lbl.Text;

       
    }&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;&lt;/pre&gt;
In &lt;b&gt;RowDataBound&lt;/b&gt; Event&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;codestyle&quot;&gt;      &lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Gridview1_RowDataBound(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, GridViewRowEventArgs e)
    {
        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if we want to find TextBox Control from GridView&lt;/span&gt;
        TextBox txt = Gridview1.FindControl(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;txtID&quot;&lt;/span&gt;) &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; TextBox;
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; textboxvalue = txt.Text;

        &lt;span style=&quot;color: green;&quot;&gt;//Suppose if we want to find Label Control from GridView&lt;/span&gt;
        Label lbl = Gridview1.FindControl(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;lblID&quot;&lt;/span&gt;) &lt;span style=&quot;color: blue;&quot;&gt;as&lt;/span&gt; Label;
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; lblvalue = lbl.Text;
    }&lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;
  &lt;/pre&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;pre class=&quot;codestyle&quot;&gt;&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/2088287922777376793/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/12/tips-for-aspnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/2088287922777376793'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/2088287922777376793'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/12/tips-for-aspnet.html' title='Tips for Asp.Net'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEixHtqBDPCyDSTAJXXGdVcZ0XtOUMrujmYdv3xDGpJ2T4Ra67nrJ7DhpxJsvPg0CT9p481f6YtJTh3NbVc1w9ISFDxnGIttXS1ECfec4PjMQzazXstDbPvxfBYV8SVjzknAHJ7txDkHvoZL/s72-c/DropValidate.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-2160604978203343033</id><published>2014-10-30T05:25:00.000-07:00</published><updated>2014-11-03T04:31:17.520-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#.Net"/><title type='text'>Validating CheckBox Selected or Not In Gridview Before Submitting Page.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Validating &lt;span style=&quot;color: red;&quot;&gt;CheckBox &lt;/span&gt;ie Selected Or Not in &lt;span style=&quot;color: red;&quot;&gt;Gridview &lt;/span&gt;before submitting page and if not showing alert message to user using &lt;span style=&quot;color: red;&quot;&gt;javascript&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In Default.aspx&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
In &amp;lt;body&amp;gt; tag&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;form id=&quot;form1&quot; runat=&quot;server&quot;&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;div&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; DataSourceID=&quot;SqlDataSource1&quot;&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;Columns&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;asp:TemplateField&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp;&amp;lt;ItemTemplate&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;asp:CheckBox ID=&quot;CheckBox1&quot; runat=&quot;server&quot; /&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp;&amp;lt;/ItemTemplate&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;/asp:TemplateField&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;asp:BoundField DataField=&quot;StateID&quot; HeaderText=&quot;StateID&quot; SortExpression=&quot;StateID&quot; /&amp;gt; &amp;lt;asp:BoundField DataField=&quot;CountryID&quot; HeaderText=&quot;CountryID&quot; SortExpression=&quot;CountryID&quot; /&amp;gt; &amp;lt;asp:BoundField DataField=&quot;StateName&quot; HeaderText=&quot;StateName&quot; SortExpression=&quot;StateName&quot; /&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;/Columns&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp;&amp;lt;/asp:GridView&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;br /&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;Submit&quot; OnClientClick=&quot;javascript:return ValidateCheckBox();&quot; /&amp;gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot; ConnectionString=&quot;&amp;lt;%$ ConnectionStrings:ExampleConnectionString %&amp;gt;&quot; SelectCommand=&quot;SELECT * FROM [StateMaster] &amp;gt;&amp;lt;/asp:SqlDataSource&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
I created gridview with one checkbox column in that and one Button control and i binded gridview with &lt;span style=&quot;color: red;&quot;&gt;SqlDataSoure property&lt;/span&gt; .&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
After that i created JavaScript Function to validate checkBox Selected or Not in GridView&lt;/div&gt;
&lt;div&gt;
Place below Javascript in &lt;span style=&quot;color: red;&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt; tag as shown in below.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;head runat=&quot;server&quot;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;script type= &quot;text/javascript&quot;&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; function ValidateCheckBox() {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var count = 0;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var gridview = document.getElementById(&#39;&amp;lt;%= GridView1.ClientID %&amp;gt;&#39;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*Get all the controls from gridview*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (var i = 0; i &amp;lt; gridview.getElementsByTagName(&quot;input&quot;).length; i++) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*Get the type of control like input*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var chknode = gridview.getElementsByTagName(&quot;input&quot;)[i];&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*Check weather checkbox is selected or not*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (chknode != null &amp;amp;&amp;amp; chknode.type == &quot;checkbox&quot; &amp;amp;&amp;amp; chknode.checked) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; count = count + 1;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /*Alert message if none of the checkboc is selected*/&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (count == 0) {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(&quot;Select one checkbox atleast from gridview.&quot;);&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else {&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;background-color: #f9cb9c;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
After That execute the application you will get following output&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;OutPut:&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsm7gKzW2WcP9ytzqsfykYBtH1WHDnGoRcAEzZFo5T_wgeeaIt1dwvm8Z8J1TXDqMkjrDTyVr0E7eCEx5LQOf3F4dluY-TWKbxZmAV68ylgZv7VR8U0k6LgMU6yyXVizaM1Hj6fVPYIVH6/s1600/CheckBox.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsm7gKzW2WcP9ytzqsfykYBtH1WHDnGoRcAEzZFo5T_wgeeaIt1dwvm8Z8J1TXDqMkjrDTyVr0E7eCEx5LQOf3F4dluY-TWKbxZmAV68ylgZv7VR8U0k6LgMU6yyXVizaM1Hj6fVPYIVH6/s1600/CheckBox.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/2160604978203343033/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/validating-checkbox-selected-or-not-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/2160604978203343033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/2160604978203343033'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/validating-checkbox-selected-or-not-in.html' title='Validating CheckBox Selected or Not In Gridview Before Submitting Page.'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhsm7gKzW2WcP9ytzqsfykYBtH1WHDnGoRcAEzZFo5T_wgeeaIt1dwvm8Z8J1TXDqMkjrDTyVr0E7eCEx5LQOf3F4dluY-TWKbxZmAV68ylgZv7VR8U0k6LgMU6yyXVizaM1Hj6fVPYIVH6/s72-c/CheckBox.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-259648084907549200</id><published>2014-10-20T04:13:00.000-07:00</published><updated>2014-11-06T04:26:04.296-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#.Net"/><title type='text'>How to pass multiple QueriesString in HyperLink in GridView.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In Example.aspx&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Add following HTML part in &lt;span style=&quot;color: red;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt; Tag&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; &amp;nbsp;Width=&quot;100%&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;lt;Columns&amp;gt;&lt;br /&gt;
&amp;lt;asp:TemplateField HeaderText=&quot;Register Date&quot; ItemStyle-HorizontalAlign=&quot;Center&quot; ItemStyle-Width=&quot;65px&quot;&amp;gt;&lt;br /&gt;
&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;
&amp;lt;asp:Label ID=&quot;lbldate&quot; runat=&quot;server&quot; Text=&#39;&amp;lt;%#Eval(&quot;LoginDate&quot;,&quot;{0:MM/dd/yyyy }&quot;)%&amp;gt;&#39;&amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;
&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;
&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;
&lt;div&gt;
&amp;lt;asp:TemplateField HeaderText=&quot;Edit&quot; ItemStyle-HorizontalAlign=&quot;Center&quot;&amp;gt;&lt;br /&gt;
&amp;lt;ItemTemplate&amp;gt;&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #f4cccc;&quot;&gt;                                &amp;lt;asp:HyperLink ID=&quot;hlEdit&quot; runat=&quot;server&quot; Font-Underline=&quot;true&quot; NavigateUrl=&#39;&amp;lt;%# string.Format(&quot;Example2.aspx?Name={0}&amp;amp;EmailID={1}&amp;amp;Mobile={2}&quot;,&lt;br /&gt;                    HttpUtility.UrlEncode(Eval(&quot;Name&quot;).ToString()), HttpUtility.UrlEncode(Eval(&quot;EmailID&quot;).ToString()),HttpUtility.UrlEncode(Eval(&quot;Mobile&quot;).ToString())) %&amp;gt;&#39;&amp;gt;Edit&amp;lt;/asp:HyperLink&amp;gt;&lt;/span&gt;&lt;br /&gt;
&amp;lt;/ItemTemplate&amp;gt;&lt;br /&gt;
&amp;lt;/asp:TemplateField&amp;gt;&lt;br /&gt;
&amp;lt;/Columns&amp;gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;lt;/asp:GridView&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In Example2.cs&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Access Privious page &lt;span style=&quot;color: red;&quot;&gt;QueryStrings&lt;/span&gt; using&lt;/div&gt;
&lt;/div&gt;
&lt;pre class=&quot;codestyle&quot;&gt;  
      &lt;code style=&quot;color: black; word-wrap: normal;&quot;&gt;   
  &lt;pre style=&quot;background-color: #f0f0f0; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;    &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Page_Load(&lt;span style=&quot;color: blue;&quot;&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; EmailID = HttpUtility.UrlDecode(Request.QueryString[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;EmailID&quot;&lt;/span&gt;]);
        String Mobile = HttpUtility.UrlDecode(Request.QueryString[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Mobile&quot;&lt;/span&gt;]);
    }  &lt;/code&gt;&lt;/pre&gt;
&lt;/code&gt;  
  &lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/259648084907549200/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-pass-multiple-queriesstring-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/259648084907549200'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/259648084907549200'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-pass-multiple-queriesstring-in.html' title='How to pass multiple QueriesString in HyperLink in GridView.'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-1046768114510727186</id><published>2014-10-13T05:11:00.001-07:00</published><updated>2014-11-03T04:32:55.447-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#.Net"/><title type='text'>How to Maintain State of FileUpload Control in Asp.Net</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Generally when we upload any file using &lt;span style=&quot;color: red;&quot;&gt;FileUpload &lt;/span&gt;Control and if their is TextBox with TextChange Event ,When&amp;nbsp;TextChange&amp;nbsp;Event fires the file from &lt;span style=&quot;color: red;&quot;&gt;FileUpload &amp;nbsp;Control will looses file&lt;/span&gt; due to&amp;nbsp;postback,, on PostBack PostedFile property gets initilized with HttpPostedFile 
object for the file. As we know that http request can&#39;t maintain state, 
and PostedFile is initilized with &lt;span style=&quot;color: red;&quot;&gt;HttpPostedFile &lt;/span&gt;Object so it loose it&#39;s
 state.&lt;br /&gt;
&lt;br /&gt;
By using &lt;span style=&quot;color: red;&quot;&gt;State Managment Techniques&lt;/span&gt; we maintain File in &lt;span style=&quot;color: red;&quot;&gt;FileUpload Control&lt;/span&gt;.&lt;br /&gt;
&lt;br /&gt;
Lets Design one Page with FileUpload Control,Label, TextBox and Button.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In Example.aspx&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Add code in form tag&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;table&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Enter Name :&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;asp:TextBox runat=&quot;server&quot; ID=&quot;txtname&quot; OnTextChanged=&quot;txtname_TextChanged&quot;&amp;gt;&amp;lt;/asp:TextBox&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Upload File :&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;asp:FileUpload ID=&quot;FileUpload1&quot; runat=&quot;server&quot; /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;asp:Label runat=&quot;server&quot; ID=&quot;lblFilename&quot; Visible=&quot;false&quot; &amp;gt;&amp;lt;/asp:Label&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/td&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;td colspan=&quot;2&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;asp:Button runat=&quot;server&quot; ID=&quot;btnSubmit&quot; /&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
After Adding following output will be seen&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDG-3SpAyGJsY3zMFau61FUICOEB_8mWfLWi4hzEt_SUfdlt-L8c7uIitltrcEiwy3MDPkiD7qv3BJH8M5zUKTJSUzS8HTdJb8vp6bVmOjKTIoZpN8WCHPVCFj7RunYKGgkY3gdbJWZpl0/s1600/File.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDG-3SpAyGJsY3zMFau61FUICOEB_8mWfLWi4hzEt_SUfdlt-L8c7uIitltrcEiwy3MDPkiD7qv3BJH8M5zUKTJSUzS8HTdJb8vp6bVmOjKTIoZpN8WCHPVCFj7RunYKGgkY3gdbJWZpl0/s1600/File.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
First Upload file using FileUpload Control ,then enter any text in textbox when you come out from textbox the fileupload control looses file because postback occurs as we kept OnTextChanged Event for textbox so its postbacks .So to maintain uploaded file we use session object because session can store any type of object.&lt;br /&gt;
&lt;br /&gt;
So add following code in Example.cs file&lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Web;&lt;br /&gt;
using System.Web.UI;&lt;br /&gt;
using System.Web.UI.WebControls;&lt;br /&gt;
&lt;br /&gt;
public partial class FileUploadExample : System.Web.UI.Page&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //If first time page is submitted and we have file in FileUpload control but not in session&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Store the values to SEssion Object&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (Session[&quot;FileUpload1&quot;] == null &amp;amp;&amp;amp; FileUpload1.HasFile)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Session[&quot;FileUpload1&quot;] = FileUpload1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblFilename.Visible = true;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblFilename.Text = FileUpload1.FileName;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Next time submit and Session has values but FileUpload is Blank&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Return the values from session to FileUpload&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if (Session[&quot;FileUpload1&quot;] != null &amp;amp;&amp;amp; (!FileUpload1.HasFile))&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; FileUpload1 = (FileUpload)Session[&quot;FileUpload1&quot;];&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblFilename.Visible = true;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblFilename.Text = FileUpload1.FileName;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Now there could be another sictution when Session has File but user want to change the file&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // In this case we have to change the file in session object&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else if (FileUpload1.HasFile)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Session[&quot;FileUpload1&quot;] = FileUpload1;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblFilename.Visible = true;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; lblFilename.Text = FileUpload1.FileName;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected void txtname_TextChanged(object sender, EventArgs e)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected void btnSubmit_Click(object sender, EventArgs e)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Here you Can access fileupload control properties for inserting onto folder&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Session.Remove(&quot;FileUpload1&quot;);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Here i took Lable Control to show that file is there to the user so that hw knows file is there.&lt;br /&gt;
Finially Execute application you will see folllowing output&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifChDpwlk-Gvk8SlpLPrNDKjespG18Hh-EM3nx63nbfjBtVIYVjRe6litsdxhOhDDkCDVohOhSE6nXWAz5f76HyvgVp1OBObRjiUKYJTCT0q65YcC2xzvMTv7sTZcuABvuRAMw8sa0xQtC/s1600/file2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifChDpwlk-Gvk8SlpLPrNDKjespG18Hh-EM3nx63nbfjBtVIYVjRe6litsdxhOhDDkCDVohOhSE6nXWAz5f76HyvgVp1OBObRjiUKYJTCT0q65YcC2xzvMTv7sTZcuABvuRAMw8sa0xQtC/s1600/file2.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/1046768114510727186/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-maintain-state-of-fileupload.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/1046768114510727186'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/1046768114510727186'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-maintain-state-of-fileupload.html' title='How to Maintain State of FileUpload Control in Asp.Net'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDG-3SpAyGJsY3zMFau61FUICOEB_8mWfLWi4hzEt_SUfdlt-L8c7uIitltrcEiwy3MDPkiD7qv3BJH8M5zUKTJSUzS8HTdJb8vp6bVmOjKTIoZpN8WCHPVCFj7RunYKGgkY3gdbJWZpl0/s72-c/File.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-1454791050446513208</id><published>2014-10-10T05:56:00.000-07:00</published><updated>2014-11-03T04:33:03.173-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#.Net"/><title type='text'>Difference Between HashTable and Dictionary in C#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Both &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;HashTable &lt;/span&gt;&lt;/b&gt;and &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Dictionary &lt;/span&gt;&lt;/b&gt;stores values in form of &lt;span style=&quot;color: red;&quot;&gt;Key-Value pairs&lt;/span&gt;,To access the values from &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Hash Table&lt;/span&gt;&lt;/b&gt; or from &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Dictionary &lt;/span&gt;&lt;/b&gt;we use Key to get value.But their are other difference between HashTable and Dictionary shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;HashTable :&lt;/span&gt;&lt;/b&gt;&lt;/h3&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Hash table is not a generic type.&lt;/li&gt;
&lt;li&gt;Hashtable is a collection of data structures to hold data as key-value pairs.&lt;/li&gt;
&lt;li&gt;The Hashtable is a weakly typed data structure, so you can add keys and values of any Object Type to the Hashtable.&lt;/li&gt;
&lt;li&gt;In Hashtable boxing/unboxing (valuetypes need boxing) will happened and which may have memory consumption&lt;/li&gt;
&lt;li&gt;When we add values to HashTable the order of values is not maintained while retrieving.&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;u&gt;Declarartion&lt;/u&gt;&lt;/span&gt;:&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Hashtable numbers = new Hashtable();&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;Dictionary:&lt;/span&gt;&lt;/h3&gt;
&lt;div&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Dictionary is  a generic type.&lt;/li&gt;
&lt;li&gt;Dictionary is a collection of data structures to hold data as key-value pairs.&lt;/li&gt;
&lt;li&gt;The Dictionary is a strongly typed data structure, so you should specify the data types for both the key and value &amp;lt; T Key, T Value &amp;gt;.&lt;/li&gt;
&lt;li&gt;In Dictionary boxing/unboxing (valuetypes need boxing) will not happened&amp;nbsp;&lt;/li&gt;
&lt;li&gt;When we add values to Dictionary the order is maintained while retrieving&lt;/li&gt;
&lt;/ul&gt;
&lt;span style=&quot;color: red;&quot;&gt; Declarartion:&lt;/span&gt;&lt;br /&gt;
Dictionary&amp;lt;int, string&amp;gt; dictionary = new Dictionary&amp;lt;int, string &amp;gt;();&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
I will explane clearly with example &lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step1:&lt;/span&gt; Create one page in web application and design page add following code in form tag &amp;nbsp;of page&lt;br /&gt;
&amp;lt;div&amp;gt;&lt;br /&gt;
&amp;lt;table&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; Text=&quot;BindValuesToDropDown&quot; OnClick=&quot;Button1_Click&quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;Bind with HashTable:&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;Bind with Dictionary:&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;asp:DropDownList runat=&quot;server&quot; ID=&quot;ddlHashTable&quot;&amp;gt;&amp;lt;/asp:DropDownList&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&amp;lt;asp:DropDownList runat=&quot;server&quot; ID=&quot;ddlDictionary&quot;&amp;gt;&amp;lt;/asp:DropDownList&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Page looks like shown below&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6Osz6JtUgFYdbONHhojfjzs2NLDj2lP4VCbnkJBJoXFgX7bE0xYSgHchMo_kY9ozAMJPBSJATCysWEfrweKRLwFvo7vhvg2Vbtb6sPbzyi2NgVFCbm6uWaZjCYFlYSYWSejqp7Ak83Y8o/s1600/Hsh.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6Osz6JtUgFYdbONHhojfjzs2NLDj2lP4VCbnkJBJoXFgX7bE0xYSgHchMo_kY9ozAMJPBSJATCysWEfrweKRLwFvo7vhvg2Vbtb6sPbzyi2NgVFCbm6uWaZjCYFlYSYWSejqp7Ak83Y8o/s1600/Hsh.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
.&lt;span style=&quot;color: red;&quot;&gt;Step2:&lt;/span&gt; Add following code in Button Click Event .cs page&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
&amp;nbsp;protected void Button1_Click(object sender, EventArgs e)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Hashtable hashtable = new Hashtable();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hashtable.Add(1, &quot;one&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hashtable.Add(2, &quot;two&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hashtable.Add(3, &quot;three&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hashtable.Add(4, &quot;four&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; hashtable.Add(5, &quot;five&quot;);&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlHashTable.DataSource = hashtable;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlHashTable.DataTextField = &quot;key&quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlHashTable.DataValueField = &quot;value&quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlHashTable.DataBind();&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Dictionary&amp;lt;int, string&amp;gt; dictionary = new Dictionary&amp;lt;int, string&amp;gt;();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dictionary.Add(1, &quot;one&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dictionary.Add(2, &quot;two&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dictionary.Add(3, &quot;three&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dictionary.Add(4, &quot;four&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dictionary.Add(5, &quot;five&quot;);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlDictionary.DataSource = dictionary;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlDictionary.DataTextField = &quot;key&quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlDictionary.DataValueField = &quot;value&quot;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ddlDictionary.DataBind();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step 3:&lt;/span&gt; Final Output get like these&lt;br /&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5VIWFLcOtv4sGpHdKbzBXg2Hb43J7cGXHy2dAukCaU5KydeHQgUQH7jJPWa61yXLrLwzvdJKLA7zvXg5-r57jmimc8Rh5VdEPru4eOcPWcUvZRKNTn2JxAx1BggA134srvO3AZlfYCWkY/s1600/Final.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5VIWFLcOtv4sGpHdKbzBXg2Hb43J7cGXHy2dAukCaU5KydeHQgUQH7jJPWa61yXLrLwzvdJKLA7zvXg5-r57jmimc8Rh5VdEPru4eOcPWcUvZRKNTn2JxAx1BggA134srvO3AZlfYCWkY/s1600/Final.png&quot; /&gt;&lt;/a&gt;&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: verdana;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/1454791050446513208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/difference-between-hashtable-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/1454791050446513208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/1454791050446513208'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/difference-between-hashtable-and.html' title='Difference Between HashTable and Dictionary in C#'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi6Osz6JtUgFYdbONHhojfjzs2NLDj2lP4VCbnkJBJoXFgX7bE0xYSgHchMo_kY9ozAMJPBSJATCysWEfrweKRLwFvo7vhvg2Vbtb6sPbzyi2NgVFCbm6uWaZjCYFlYSYWSejqp7Ak83Y8o/s72-c/Hsh.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-6323158303148049802</id><published>2014-10-06T04:23:00.000-07:00</published><updated>2014-11-03T04:33:28.668-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#.Net"/><title type='text'>How to Bind 2 or more columns data from database table to DropDownList in asp.net</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
In &lt;span style=&quot;color: red;&quot;&gt;DropDownList&lt;/span&gt; everyone knows that there is &lt;span style=&quot;color: red;&quot;&gt;DataTextField &lt;/span&gt;and &lt;span style=&quot;color: red;&quot;&gt;DataValueField &lt;/span&gt;commonly we bind one column to&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;DataTextField&amp;nbsp;&lt;/span&gt;and one column to&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;DataValueField&amp;nbsp;&lt;/span&gt;from &lt;span style=&quot;color: red;&quot;&gt;DataTable &lt;/span&gt;or any &lt;span style=&quot;color: red;&quot;&gt;DataReaders &lt;/span&gt;etc.&lt;br /&gt;
If we want to bind 2 or more columns to &lt;span style=&quot;color: red;&quot;&gt;DataTextField &lt;/span&gt;of &lt;span style=&quot;color: red;&quot;&gt;DropDownList &lt;/span&gt;we use &lt;span style=&quot;color: red;&quot;&gt;Dictionary &lt;/span&gt;Class and by using that we bind to dropdownlist.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In Default5.aspx Page&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Add one &lt;span style=&quot;color: red;&quot;&gt;DropDownlist &lt;/span&gt;to a page as shown in below.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default5.aspx.cs&quot; Inherits=&quot;Default5&quot; %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!DOCTYPE html&amp;gt;&lt;br /&gt;
&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&amp;gt;&lt;br /&gt;
&amp;lt;head runat=&quot;server&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;form id=&quot;form1&quot; runat=&quot;server&quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;asp:DropDownList runat=&quot;server&quot; ID=&quot;ddlStates&quot; Width=&quot;30%&quot;&amp;gt;&amp;lt;/asp:DropDownList&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/form&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In Default5.cs Page&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Create one &lt;span style=&quot;color: red;&quot;&gt;method &lt;/span&gt;that will retrieve records from database as shown below&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; PopulateStates()
    {
        &lt;span style=&quot;color: green;&quot;&gt;//using metod am getting all states from table storing in datatable&lt;/span&gt;
        dt = Acls.selectUSAStateMaster();
        &lt;span style=&quot;color: green;&quot;&gt;//Creating Dictionary with string datatype&lt;/span&gt;
        Dictionary&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt; lst = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Dictionary&amp;lt;&lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;, &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;&amp;gt;();
        &lt;span style=&quot;color: green;&quot;&gt;//Using foreach am adding all rows to dictionary&lt;/span&gt;
        &lt;span style=&quot;color: blue;&quot;&gt;foreach&lt;/span&gt; (DataRow row &lt;span style=&quot;color: blue;&quot;&gt;in&lt;/span&gt; dt.Rows)
        {
            &lt;span style=&quot;color: green;&quot;&gt;//Add values to Dictionary&lt;/span&gt;
            &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; val = row[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;StateID&quot;&lt;/span&gt;].ToString() + &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;( &quot;&lt;/span&gt; + row[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;State&quot;&lt;/span&gt;].ToString() + &lt;span style=&quot;color: #a31515;&quot;&gt;&quot; )&quot;&lt;/span&gt;;
            lst.Add(row[&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;State&quot;&lt;/span&gt;].ToString(), val);
        }
        &lt;span style=&quot;color: green;&quot;&gt;//finnaly am assigning DataSouce to DropDownList as Dicyionary object &lt;/span&gt;
        &lt;span style=&quot;color: green;&quot;&gt;//In Dictionary rows will be stored as &#39;KEY&#39;,&#39;VALUE&#39; pairs so am assigning KEY and VALUE as datatextfiled and datavaluefield&lt;/span&gt;
        ddlstate.DataSource = lst;
        ddlstate.DataTextField = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;value&quot;&lt;/span&gt;;
        ddlstate.DataValueField = &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;key&quot;&lt;/span&gt;;
        ddlstate.DataBind();
        &lt;span style=&quot;color: green;&quot;&gt;//Adding new listitem as Select to droipdownlist&lt;/span&gt;
        ListItem item = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; ListItem(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;Select &quot;&lt;/span&gt;, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;0&quot;&lt;/span&gt;);
        ddlstate.Items.Insert(0, item);

    }&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Call this method in ISPOSTBACK or POSTBACK where ever you want and execute you will get output as shown below&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt8Q-J5rCDIhWjASPiWVM-GmGDfq5wLKZHEUE2I_0-E1qy30JsRIvFHHezHmYairfcO3obj2iwkrfEfXMjFZu8ZB3yRPcMRlZr5-j8UG5LbdWmkCnXJ38VdZZIFgtpC2KntFJjRopmVJ05/s1600/DropDownList.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt8Q-J5rCDIhWjASPiWVM-GmGDfq5wLKZHEUE2I_0-E1qy30JsRIvFHHezHmYairfcO3obj2iwkrfEfXMjFZu8ZB3yRPcMRlZr5-j8UG5LbdWmkCnXJ38VdZZIFgtpC2KntFJjRopmVJ05/s1600/DropDownList.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/6323158303148049802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-bind-2-or-more-columns-data-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/6323158303148049802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/6323158303148049802'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-bind-2-or-more-columns-data-from.html' title='How to Bind 2 or more columns data from database table to DropDownList in asp.net'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgt8Q-J5rCDIhWjASPiWVM-GmGDfq5wLKZHEUE2I_0-E1qy30JsRIvFHHezHmYairfcO3obj2iwkrfEfXMjFZu8ZB3yRPcMRlZr5-j8UG5LbdWmkCnXJ38VdZZIFgtpC2KntFJjRopmVJ05/s72-c/DropDownList.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-4513381514928081112</id><published>2014-10-01T04:14:00.000-07:00</published><updated>2014-11-03T04:34:00.692-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#.Net"/><title type='text'>How to Add Colmns to DataTable and adding Some rows to it and binding to Gridview</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In aspx.cs&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Adding rows using code to &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;DataTable&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Data;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
using System.Web;&lt;br /&gt;
using System.Web.UI;&lt;br /&gt;
using System.Web.UI.WebControls;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
public partial class Example : System.Web.UI.Page&lt;br /&gt;
{&lt;br /&gt;
&amp;nbsp; &amp;nbsp; protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!IsPostBack)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CretaeDatatablewithrows();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp;public void CretaeDatatablewithrows()&lt;br /&gt;
&amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Creating new instance of DataTable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DataTable dt = new DataTable();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Adding columns to datatable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dt.Columns.Add(&quot;ID&quot;, typeof(int));&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dt.Columns.Add(&quot;Emailid&quot;, typeof(string));&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Adding Dummy data to datatable&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for (int i = 1; i &amp;lt;= 10; i++)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; DataRow row;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; row = dt.NewRow();&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; row[&quot;Emailid&quot;] = &quot;dummy&quot; + i + &quot;@gmail.com&quot;;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; row[&quot;ID&quot;] = i;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dt.Rows.Add(row);&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //Bind DataTable to GridView&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GridView1.DataSource = dt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GridView1.DataBind();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
We are creating one method that will add columns to &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;DataTable &lt;/span&gt;&lt;/b&gt;and bind to &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;GridView&lt;/span&gt;&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Compile and execute following Output will Get&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;OutPut&lt;/span&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDx0xAmHahzudG7TWEdqGX4dHO-jn8HWnrAwKr3gqhlKi0FHvFww2HkqHmAlyFlutZoDyblE6xhPHDY_F93peWUu9lZlk5L6nKm5zLBGV98dT71ojoggL_vpUXaQxiFz6M0iaKrRiXfcGy/s1600/Data1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDx0xAmHahzudG7TWEdqGX4dHO-jn8HWnrAwKr3gqhlKi0FHvFww2HkqHmAlyFlutZoDyblE6xhPHDY_F93peWUu9lZlk5L6nKm5zLBGV98dT71ojoggL_vpUXaQxiFz6M0iaKrRiXfcGy/s1600/Data1.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/4513381514928081112/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-add-colmns-to-datatable-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/4513381514928081112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/4513381514928081112'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/10/how-to-add-colmns-to-datatable-and.html' title='How to Add Colmns to DataTable and adding Some rows to it and binding to Gridview'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDx0xAmHahzudG7TWEdqGX4dHO-jn8HWnrAwKr3gqhlKi0FHvFww2HkqHmAlyFlutZoDyblE6xhPHDY_F93peWUu9lZlk5L6nKm5zLBGV98dT71ojoggL_vpUXaQxiFz6M0iaKrRiXfcGy/s72-c/Data1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-3271580983092818838</id><published>2014-09-30T03:28:00.001-07:00</published><updated>2014-11-03T04:34:10.764-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><title type='text'>How to Rewrite URL in Asp.Net (Search Engine Friendly Url)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Here is a simple way to Rewrite URLs in Asp.net Using Global.asax file.&lt;br /&gt;
&lt;br /&gt;
Here I presenting an important aspect &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Search Engine optimization&lt;/span&gt;&lt;/b&gt; technique. &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;URL rewriting&lt;/b&gt;&lt;/span&gt; can be one of the best and quickest ways to improve the usability and search friendliness of your site.&lt;br /&gt;
&lt;br /&gt;
Handling cases where you want to restructure the pages within your web application, and you want to ensure that people who have bookmarked old URLs don&#39;t break when you move pages around.  &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Url-rewriting&lt;/span&gt;&lt;/b&gt; enables you to transparently forward requests to the new page location without breaking browsers.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Normal URL:&lt;/span&gt;&lt;/b&gt; http://site.com/Default2.aspx?Coursename=Asp.net&amp;amp;CourseID=12&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;SEO friendly URL :&lt;/span&gt;&lt;/b&gt;http://site.com/IT-Training/Asp.net/12&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Clearly a much cleaner and shorter URL. It’s much easier to remember, 
and vastly easier to read out. That said, it doesn’t exactly tell anyone
 what it refers.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Its an easy task to converting URLs. Actually, I am working with ASP.NET
 C#. So, I will explaining how to achive this with ASP.NET. I am using 
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Global.asax Application_BeginRequest&lt;/span&gt;&lt;/b&gt; event handler.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;strong&gt;&lt;span style=&quot;color: red;&quot;&gt;Application_BeginRequest:&lt;/span&gt;&lt;/strong&gt; is an event handler. It is 
part of the ASP.NET website system. The Application_BeginRequest method 
is executed on all requests handled by the ASP.NET runtime.&lt;br /&gt;
First, this event handler is declared in a class that derives from 
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;HttpApplication&lt;/span&gt;&lt;/b&gt;. In such classes, the Application_BeginRequest method is
 automatically used when a request is received.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Now Lets Start Doing&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step1:&lt;/span&gt; First we are creating new website in visual studio 2010 for that open
 visual studio 2010. Click on File -&amp;gt; New -&amp;gt; Website&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step2:&lt;/span&gt; &amp;nbsp;Select Visual C# from left and click on ASP.NET Empty Website 
template. In Bottom Web location Select File System and Type path to 
create new website.Give name “Site” to website.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNhtsdoomgYMbo69dY7UhVLNLMSvk9qAAdr-MRengGIx4gucbQ7snesJ7wFvoh5J428JPuXhOhsKLTy0TUGFet9HyXnkebhqKLA_6UhfE5iY12dIAib65VtTH9AT-Yhki0Lr78y-oQH2gO/s1600/url1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNhtsdoomgYMbo69dY7UhVLNLMSvk9qAAdr-MRengGIx4gucbQ7snesJ7wFvoh5J428JPuXhOhsKLTy0TUGFet9HyXnkebhqKLA_6UhfE5iY12dIAib65VtTH9AT-Yhki0Lr78y-oQH2gO/s1600/url1.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step3:&lt;/span&gt;Now empty asp.net website is created there is nothing to display on 
solution so first we create Default.aspx page. To create new page right 
click on solution explorer click Add New Item. Select Webform from 
template and name it &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Default.aspx&lt;/span&gt;&lt;/b&gt; and click on add.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step4 :&lt;/span&gt;Add one new page to solution and name it &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Default2.aspx&lt;/b&gt;&lt;/span&gt;.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step5 :&lt;/span&gt;Now we want to send the &lt;span style=&quot;color: red;&quot;&gt;Coursename &lt;/span&gt;and &lt;span style=&quot;color: red;&quot;&gt;CourseID &lt;/span&gt;from Default.aspx to&amp;nbsp;Default2.aspx So, We are&amp;nbsp;using Query String to pass the values&amp;nbsp;&lt;b&gt; e.g. 
http://site.com/Default2.aspx?Coursename&amp;nbsp;=Asp.net/&amp;amp;CourseID&amp;nbsp;=12&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step6 :&lt;/span&gt;we can access these values on&amp;nbsp;Default2.aspx by 
Request.QueryString[&quot;Coursename&amp;nbsp;&quot;] and Request.QueryString[&quot;CourseID&amp;nbsp;&quot;] 
but this is not a SEO friendly pattern.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;color: red;&quot;&gt;Step7 :&lt;/span&gt; To solve this create menu with list of Courses to Default.aspx and set &lt;b&gt;NavigateUrl=”~/IT-Training/Asp.net/12&lt;/b&gt; to each menu item likewise set &lt;b&gt;NavigateUrls &lt;/b&gt;to remaimng items in menu.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Below Screen will show the screen Shot of &lt;b&gt;Default.aspx &lt;/b&gt;with list of coureses&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYu1hGynbFAVA2tb_72zRAZzS5C8NUa85yRSgwFIYtlDXXf0xVKbVFdV9liCEXcxxQuJlVz_3KPiXGwhuYeZYn6WTwnc5fb7FPxj9U5-q0b3msWuoPhdGWHmIDxGUF0cidKbJPIiL1x7Yr/s1600/url2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYu1hGynbFAVA2tb_72zRAZzS5C8NUa85yRSgwFIYtlDXXf0xVKbVFdV9liCEXcxxQuJlVz_3KPiXGwhuYeZYn6WTwnc5fb7FPxj9U5-q0b3msWuoPhdGWHmIDxGUF0cidKbJPIiL1x7Yr/s1600/url2.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
As you observe above screen shot i have written &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;CSharpDotNet &lt;/span&gt;&lt;/b&gt;behalf of &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;C#.Net&lt;/b&gt;&lt;/span&gt; because the SEO does not supports &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;dot(.),Hash(#),Spaces( )&lt;/span&gt;&lt;/b&gt;. If you want spaces between words you should use &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;iphen(-)&lt;/span&gt;&lt;/b&gt; as i have use in above screen shot &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;.Net-Online-Training-Courses.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Now our goal is if we to see &amp;nbsp;any of course from menu &amp;nbsp;Suppose if you click last item it should redirect and URL should be seo friendly url as show below&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;Normal URL :&lt;/b&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;http://site.com/Default2.aspx?Coursename=.Net-Online-Training-Courses&amp;amp;CourseID=22&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;SEO friendly URL :&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: red;&quot;&gt;http://site.com/IT-Training/.Net-Online-Training-Courses/22&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Step 8:&amp;nbsp; To write our rewrite rule we have to add &lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Global.asax&lt;/b&gt;&lt;/span&gt; file in project. 
To add Global.asax right click on solution and click Add New Item and 
select “Global Application Class” from templates.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtqf5VbsCrGw9qhzBhnq1AyWnYALY1urLXXiSyqGQougzFx-fcw8L6ZbcnjIBHLkgx247a83h5bDVSQ-8BEbxqkcwk_dnMK-py6cadg6vWq7zArW0omU29qb3YM9BF4Pl3zo3Acb16-lS8/s1600/url3.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtqf5VbsCrGw9qhzBhnq1AyWnYALY1urLXXiSyqGQougzFx-fcw8L6ZbcnjIBHLkgx247a83h5bDVSQ-8BEbxqkcwk_dnMK-py6cadg6vWq7zArW0omU29qb3YM9BF4Pl3zo3Acb16-lS8/s1600/url3.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Step 9 :We are creating new Event Handler in Global.asax name it protected void Application_BeginRequest(Object sender, EventArgs e){}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
In that event add following code as shown below&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt; &lt;span style=&quot;color: blue;&quot;&gt;protected&lt;/span&gt; &lt;span style=&quot;color: blue;&quot;&gt;void&lt;/span&gt; Application_BeginRequest(Object sender, EventArgs e)
    {
        &lt;span style=&quot;color: green;&quot;&gt;//Get the URL for matching the pattern. Returns the current URL path.&lt;/span&gt;
        &lt;span style=&quot;color: green;&quot;&gt;//e.g. http://site.com/IT-Training/&lt;/span&gt;&lt;span style=&quot;color: green; font-size: 10pt;&quot;&gt;.Net-Online-Training-Courses&lt;/span&gt;&lt;span style=&quot;color: green; font-size: 10pt;&quot;&gt;/22&lt;/span&gt;&lt;span style=&quot;color: green;&quot;&gt;
&lt;/span&gt;        HttpContext incoming = HttpContext.Current;
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; oldpath = incoming.Request.Path;

        &lt;span style=&quot;color: green;&quot;&gt;//Declare variables for Query Strings.&lt;/span&gt;
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; coursename = &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.Empty;
        &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt; couserid = &lt;span style=&quot;color: blue;&quot;&gt;string&lt;/span&gt;.Empty;
        

        &lt;span style=&quot;color: green;&quot;&gt;// Regular expressions to grab the coursename and couserid to the Default2.aspx because it takes Coursename and CourseID&lt;/span&gt;
        &lt;span style=&quot;color: green;&quot;&gt;//Here I am using regular expression to match the pattern.&lt;/span&gt;
        Regex regex = &lt;span style=&quot;color: blue;&quot;&gt;new&lt;/span&gt; Regex(@&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;IT-Training/(.+)/(\d+)&quot;&lt;/span&gt;, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
        MatchCollection matches = regex.Matches(oldpath);

         &lt;span style=&quot;color: green;&quot;&gt;//If Matches found then Grab the Coursename  and CourseID and rewrite it as our typical query string format.&lt;/span&gt;
        &lt;span style=&quot;color: green;&quot;&gt;//e.g: http://site.com/Default2.aspx?Coursename =.Net-Online-Training-Courses&amp;amp;CourseID=22&lt;/span&gt;
        &lt;span style=&quot;color: blue;&quot;&gt;if&lt;/span&gt; (matches.Count &amp;gt; 0)
        {
            coursename = matches[0].Groups[1].ToString();
            couserid = matches[0].Groups[2].ToString();
            incoming.RewritePath(String.Concat(&lt;span style=&quot;color: #a31515;&quot;&gt;&quot;~/Default2.aspx?coursename=&quot;&lt;/span&gt;, coursename, &lt;span style=&quot;color: #a31515;&quot;&gt;&quot;&amp;amp;couserid=&quot;&lt;/span&gt;, couserid), &lt;span style=&quot;color: blue;&quot;&gt;false&lt;/span&gt;);
        }
        
    }  &lt;/code&gt;&lt;/pre&gt;
&lt;pre style=&quot;background-color: white; margin: 0em; overflow: auto;&quot;&gt;&lt;code style=&quot;color: black; font-family: Consolas,&amp;quot;Courier New&amp;quot;,Courier,Monospace; font-size: 10pt;&quot;&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;The first two lines returns the current URL path.HttpContext incoming = HttpContext.Current;string oldpath = incoming.Request.Path.ToLower();&lt;/li&gt;
&lt;li&gt;By using regular expression we can match the pattern of our requested 
URL with our rewrite URL. Means, when&amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;http://site.com/IT-Training/.Net-Online-Training-Courses/22&lt;/span&gt;&lt;/b&gt;&amp;nbsp;is pattern matched 
with our regular expression and it rewrite the path to&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;http://site.com/Default2.aspx?coursename =.Net-Online-Training-Courses&amp;amp;couserid =22&lt;/b&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
After finishing Global.asax writting complie and execute and click any one of course from &lt;b&gt;Default1.aspx &lt;/b&gt;we get following output.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLjM6ConCQhgXsstXRvzzR-mZi01RLBt1_nWOn3RIi7fmQlHcfnd2pmCEb02AmlPbA0LAZqG4kRDlkQ6GdfZ-MJ1p6G_FPFsIzfsoSIw8imdC37RYZ5aJCWtvmsm_Wn2645lTwmax6kAIe/s1600/url4.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLjM6ConCQhgXsstXRvzzR-mZi01RLBt1_nWOn3RIi7fmQlHcfnd2pmCEb02AmlPbA0LAZqG4kRDlkQ6GdfZ-MJ1p6G_FPFsIzfsoSIw8imdC37RYZ5aJCWtvmsm_Wn2645lTwmax6kAIe/s1600/url4.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
By This we can get SEO frendly URL&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/3271580983092818838/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/how-to-rewrite-url-in-aspnet-search.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/3271580983092818838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/3271580983092818838'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/how-to-rewrite-url-in-aspnet-search.html' title='How to Rewrite URL in Asp.Net (Search Engine Friendly Url)'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgNhtsdoomgYMbo69dY7UhVLNLMSvk9qAAdr-MRengGIx4gucbQ7snesJ7wFvoh5J428JPuXhOhsKLTy0TUGFet9HyXnkebhqKLA_6UhfE5iY12dIAib65VtTH9AT-Yhki0Lr78y-oQH2gO/s72-c/url1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-3185519454278462192</id><published>2014-09-24T04:04:00.000-07:00</published><updated>2014-11-03T04:34:37.463-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="Sql Server"/><title type='text'>How To return String into Delimited String in SqlServer and With Good Example Using  &quot;IN Clause&quot; </title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
As we know sql queries are &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Dynamic &lt;/span&gt;&lt;/b&gt;and &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Nondynamic &lt;/span&gt;&lt;/b&gt;queries.This example is for Non dynamic query.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;For spliting string into delimited string we use Function in sql server .&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Ex&lt;/span&gt;&lt;/b&gt;:     @string nvarchar(max),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;@splitedstring nvarchar(max)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;set @string=&#39;word1,word2 &#39;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Result:&lt;/span&gt;&lt;/b&gt;@splitedstring =&#39;word1&#39;,&#39;word2&#39;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
For this we created function in sql server&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;CREATE FUNCTION [dbo].[StrinToStringList]&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;( @str nVARCHAR (MAX),&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; @delimeter nvarchar(2))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp;RETURNS&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; @result TABLE (&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [ID] nvarchar(max) NULL)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;AS&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;BEGIN&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; DECLARE @x XML&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; SET @x = &#39;&amp;lt;t&amp;gt;&#39; + REPLACE(@str, @delimeter, &#39;&amp;lt;/t&amp;gt;&amp;lt;t&amp;gt;&#39;) + &#39;&amp;lt;/t&amp;gt;&#39;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; INSERT INTO @result&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; SELECT DISTINCT x.i.value(&#39;.&#39;, &#39;nvarchar(max)&#39;) AS token&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; FROM @x.nodes(&#39;//t&#39;) x(i)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&amp;nbsp; &amp;nbsp; ORDER BY 1&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;RETURN&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;END&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
As we created function it returns in the form of Table result set and it takes 2 parametersfrom stored procedures first one is for &quot;string to split&quot; second is for delimited string which should be seperated from string.In our example shown above we pass &quot;,&quot; comma delimeter so function will seperate string where ever comma is appeared in string.
&lt;br /&gt;
Example:&lt;br /&gt;
&lt;br /&gt;
Suppose we have a table as shown in below&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjDw44H7bkgI9XUFDOumB2Ee62RjT7-_HykRPEgP6xVUhkzF4O8FbiJFiKT4Vz5yu1WK34CgA2-eMoPAFQeIsBG2VBZI0Tm1n61Xi3kfbiC-epTC_rvv_q_W3S7zcRdAi9lkqbwkiPS4Ek/s1600/Sql1.PNG&quot; style=&quot;background-color: #b6d7a8;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjDw44H7bkgI9XUFDOumB2Ee62RjT7-_HykRPEgP6xVUhkzF4O8FbiJFiKT4Vz5yu1WK34CgA2-eMoPAFQeIsBG2VBZI0Tm1n61Xi3kfbiC-epTC_rvv_q_W3S7zcRdAi9lkqbwkiPS4Ek/s1600/Sql1.PNG&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If we want specific rows like say &quot;aaa and ffff&quot; using stored procedure as shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;create procedure CompanyFilter&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;@string nvarchar(max)=&#39;aaa,bbb&#39;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;as&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;select * from table where names in(@string)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;&lt;br /&gt;&lt;/span&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After finishing creating stored procedue execute that we get result like this as shown below
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZ5xl3lP8pHw0EVa7FLelBy9uOsmu-0c5pIQ-ZVvka4VBHbjOG5rp2DoahETu5nfg83zvWc7e9p99pm6hiC0Z3C1LreJ0P4L9ll4y3uSro4JcI3OJt8kgWxQ25nbkFzMclw4AycNejmG9/s1600/sql2.PNG&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZ5xl3lP8pHw0EVa7FLelBy9uOsmu-0c5pIQ-ZVvka4VBHbjOG5rp2DoahETu5nfg83zvWc7e9p99pm6hiC0Z3C1LreJ0P4L9ll4y3uSro4JcI3OJt8kgWxQ25nbkFzMclw4AycNejmG9/s1600/sql2.PNG&quot; /&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
In stored procedure &quot;@string&quot; parameter acts as single string for qurey so table does not contains name with &quot;aaa,bbb&quot; thats why table returns nothing.&lt;br /&gt;
&lt;br /&gt;
So &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;re-modify&lt;/span&gt;&lt;/b&gt; the stored procedure as shown below&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;create procedure CompanyFilter&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;(&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;@string nvachar(max)=&#39;aaa,bbb&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;as&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;begin&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;Select * from table where names in (select id from dbo.StrinToStringList(@string,&#39;,&#39;))&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: #ffe599;&quot;&gt;end&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In above SP the query is calling function and passing 2 parameters ie string and delimeter to function.The function as i said it returns table result set to stored procedure so below screen will show result&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifIYpv0JfKU7zcIOasQmroCFrfVTf26jr2Vt0A63xj_Pj3cURvY9NCHhS9_O79IbTXQrnUeRCVu4B-uBB2BAq1zc9c0NJFoJlVpgULeckRjJGg52BYfOeAt2k5vsX8PLefRkGVrBjjdZPD/s1600/sql3.PNG&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifIYpv0JfKU7zcIOasQmroCFrfVTf26jr2Vt0A63xj_Pj3cURvY9NCHhS9_O79IbTXQrnUeRCVu4B-uBB2BAq1zc9c0NJFoJlVpgULeckRjJGg52BYfOeAt2k5vsX8PLefRkGVrBjjdZPD/s1600/sql3.PNG&quot; /&gt;&lt;/a&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;



&lt;!-- Blogger automated replacement: &quot;https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F4.bp.blogspot.com%2F-bhhd_qCwPSo%2FVCKkW7QqBmI%2FAAAAAAAAA8A%2F0qoFRfJwg5U%2Fs1600%2Fsql3.PNG&amp;amp;container=blogger&amp;amp;gadget=a&amp;amp;rewriteMime=image%2F*&quot; with &quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifIYpv0JfKU7zcIOasQmroCFrfVTf26jr2Vt0A63xj_Pj3cURvY9NCHhS9_O79IbTXQrnUeRCVu4B-uBB2BAq1zc9c0NJFoJlVpgULeckRjJGg52BYfOeAt2k5vsX8PLefRkGVrBjjdZPD/s1600/sql3.PNG&quot; --&gt;&lt;!-- Blogger automated replacement: &quot;https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F4.bp.blogspot.com%2F-IGiBZGlxl-o%2FVCKdo_-vMOI%2FAAAAAAAAA7k%2F5zPoWHwzSes%2Fs1600%2FSql1.PNG&amp;amp;container=blogger&amp;amp;gadget=a&amp;amp;rewriteMime=image%2F*&quot; with &quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjDw44H7bkgI9XUFDOumB2Ee62RjT7-_HykRPEgP6xVUhkzF4O8FbiJFiKT4Vz5yu1WK34CgA2-eMoPAFQeIsBG2VBZI0Tm1n61Xi3kfbiC-epTC_rvv_q_W3S7zcRdAi9lkqbwkiPS4Ek/s1600/Sql1.PNG&quot; --&gt;&lt;!-- Blogger automated replacement: &quot;https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F2.bp.blogspot.com%2F-hHMQF-w3rUY%2FVCKflz5r7XI%2FAAAAAAAAA7w%2FXYWc56due_o%2Fs1600%2Fsql2.PNG&amp;amp;container=blogger&amp;amp;gadget=a&amp;amp;rewriteMime=image%2F*&quot; with &quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEieZ5xl3lP8pHw0EVa7FLelBy9uOsmu-0c5pIQ-ZVvka4VBHbjOG5rp2DoahETu5nfg83zvWc7e9p99pm6hiC0Z3C1LreJ0P4L9ll4y3uSro4JcI3OJt8kgWxQ25nbkFzMclw4AycNejmG9/s1600/sql2.PNG&quot; --&gt;</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/3185519454278462192/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/how-to-return-string-into-delimited.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/3185519454278462192'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/3185519454278462192'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/how-to-return-string-into-delimited.html' title='How To return String into Delimited String in SqlServer and With Good Example Using  &quot;IN Clause&quot; '/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjDw44H7bkgI9XUFDOumB2Ee62RjT7-_HykRPEgP6xVUhkzF4O8FbiJFiKT4Vz5yu1WK34CgA2-eMoPAFQeIsBG2VBZI0Tm1n61Xi3kfbiC-epTC_rvv_q_W3S7zcRdAi9lkqbwkiPS4Ek/s72-c/Sql1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-8867476110328481675</id><published>2014-09-20T03:59:00.000-07:00</published><updated>2014-11-03T04:35:04.009-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>How to Retrive Dynamically Generated Textboxes values using JavaScript in Asp.Net</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
After generating texboxes dynamically as shown in my previous artical(&lt;a href=&quot;http://naveenvadakattu.blogspot.in/2014/09/adding-textbox-dynamically-using.html&quot;&gt;ClickHere&lt;/a&gt;&amp;nbsp;to see) it is the time to retrive values of textboxes entered by the user .&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;In .aspx Page&amp;nbsp;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
In continuation of my previous artical (&lt;a href=&quot;http://naveenvadakattu.blogspot.in/2014/09/adding-textbox-dynamically-using.html&quot;&gt;ClickHere&lt;/a&gt;&amp;nbsp;to see) add following html code in your page&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;lt;asp:Button runat=&quot;server&quot; ID=&quot;btnGetValues&quot; Text=&quot;GetValues&quot; OnClick=&quot;btnGetValues_Click&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b style=&quot;color: red;&quot;&gt;In .cs Page&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
Add following code&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzCyR-NIAUPHx49mki4Fl7smNkWNjew8GAK8oN17r8GPGI2PRKaSr9zegbyTo3DJQN4SU3NFPw35Lc4JW39h7nJDL2ERSIZxta8SlduYaWYPzfb8N_l42D9RcRJWnBgaK6KD8faZ73n6C5/s1600/Capture2.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzCyR-NIAUPHx49mki4Fl7smNkWNjew8GAK8oN17r8GPGI2PRKaSr9zegbyTo3DJQN4SU3NFPw35Lc4JW39h7nJDL2ERSIZxta8SlduYaWYPzfb8N_l42D9RcRJWnBgaK6KD8faZ73n6C5/s1600/Capture2.PNG&quot; height=&quot;75&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b style=&quot;color: red;&quot;&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/b&gt;&lt;b style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/b&gt;
In above code &quot;txt1&quot; and &quot;txt2&quot; is the ids of textbox in html code.we are fecting values using From.getValues() and storing it into string array .Complie and execute following figure shows values in string array.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKiEEZ0CUYAxq62pdYpBu2ltnoYrayQQiM6ZbI4N-3q1Ua5ioiicyrTqsMQPSD4HaPQr527G65JZsglUCJRaNkHp-YzHzrX7Bi7D2Vj3zitsjGg4g3vdXWMzEp9x0XaFtbNuMOEvazizQv/s1600/Capture3.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKiEEZ0CUYAxq62pdYpBu2ltnoYrayQQiM6ZbI4N-3q1Ua5ioiicyrTqsMQPSD4HaPQr527G65JZsglUCJRaNkHp-YzHzrX7Bi7D2Vj3zitsjGg4g3vdXWMzEp9x0XaFtbNuMOEvazizQv/s1600/Capture3.PNG&quot; height=&quot;145&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
After entering values in textboxes and click &quot;GetValues&quot; floowing figure shows texbox values in strin array.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0uX9DERCfcT4-lESw10mv28qVzq5hK5v2Pi3rBoiS2M5fdD48UMGRb9pAdGubEMCIO0r3wBL8bJbBq9d487VIqZP5BhCFK5IlNKgJxYJUP20qwwJDZ-NO2g_61CvySw69GLLjtWsgHqpl/s1600/Capture4.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0uX9DERCfcT4-lESw10mv28qVzq5hK5v2Pi3rBoiS2M5fdD48UMGRb9pAdGubEMCIO0r3wBL8bJbBq9d487VIqZP5BhCFK5IlNKgJxYJUP20qwwJDZ-NO2g_61CvySw69GLLjtWsgHqpl/s1600/Capture4.PNG&quot; height=&quot;97&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now you can loop using &quot;for&quot; and &amp;nbsp;insert into database.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/8867476110328481675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/how-to-retrive-dynamically-generated.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/8867476110328481675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/8867476110328481675'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/how-to-retrive-dynamically-generated.html' title='How to Retrive Dynamically Generated Textboxes values using JavaScript in Asp.Net'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzCyR-NIAUPHx49mki4Fl7smNkWNjew8GAK8oN17r8GPGI2PRKaSr9zegbyTo3DJQN4SU3NFPw35Lc4JW39h7nJDL2ERSIZxta8SlduYaWYPzfb8N_l42D9RcRJWnBgaK6KD8faZ73n6C5/s72-c/Capture2.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-1975879135128990039</id><published>2014-09-20T03:47:00.001-07:00</published><updated>2014-11-03T04:35:37.188-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Adding Textbox Dynamically Using JavaScript in  Asp.Net</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;Adding Textboxes&amp;nbsp;Dynamically&amp;nbsp;using Javascript is very easy in Asp.Net&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In .aspx page&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;
&lt;b&gt;Add following javascript in Head Section of your page&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;span style=&quot;color: #b45f06;&quot;&gt;function GetDynamicTextBox()&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return &#39;TextBox1:&amp;lt;input name = &quot;txt1&quot; style=&quot;width:200px&quot; type=&quot;text&quot; /&amp;gt;&#39;+&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;TextBox2:&amp;lt;input name = &quot;txt2&quot; type=&quot;text&quot; style=&quot;width:200px&quot; /&amp;gt;&#39; +&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &#39;&amp;lt;input type=&quot;button&quot; value=&quot;Remove&quot; &amp;nbsp;class=&quot;button&quot; &amp;nbsp;onclick = &quot;RemoveTextBox(this)&quot; /&amp;gt;&#39;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp;}&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The above script creates html part which you want generate dynamically on button click.&lt;br /&gt;
The above Html creates two Textboxes with Remove button.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;function AddTextBox()&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var div = document.createElement(&#39;DIV&#39;);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; div.innerHTML = GetDynamicTextBox();&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; document.getElementById(&quot;TextBoxContainer&quot;).appendChild(div);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The above script is for adding HTML code in a div tag which is in our page and this function will be called using Button.&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp;function RemoveTextBox(div)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp;{&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; document.getElementById(&quot;TextBoxContainer&quot;).removeChild(div.parentNode);&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; }&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
The above function is used for Removing textbox during runtime on page.And this function will be called in dynamically generated html Code as seen in &amp;nbsp;&lt;span style=&quot;color: orange;&quot;&gt;GetDynamicTextBox()&lt;/span&gt;&amp;nbsp;function.&lt;br /&gt;
&lt;br /&gt;
In Body Section:&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;form id=&quot;form1&quot; runat=&quot;server&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div&amp;gt;&amp;lt;input id=&quot;btnAdd&quot; type=&quot;button&quot; value=&quot;Add Manager&quot; class=&quot;button&quot; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; onclick=&quot;AddTextBox()&quot; /&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div id=&quot;TextBoxContainer&quot;&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--Textboxes will be added here --&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: #b45f06;&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
After compile and execute following result will be show&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;color: #274e13;&quot;&gt;OutPut&lt;/span&gt;&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSFZ2JshNuVLWfRl651iS4PvCXtDPilRCbJ_SisquFJb5kUzA6jkV5S9qYCGGB-CvaNJmBS05BPaPO0PZLGlW508LSCJH_jly-r-lWox09XL17S8F_v7dDqiQK-CXEQdLOf2udS6g3eUW6/s1600/Capture1.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSFZ2JshNuVLWfRl651iS4PvCXtDPilRCbJ_SisquFJb5kUzA6jkV5S9qYCGGB-CvaNJmBS05BPaPO0PZLGlW508LSCJH_jly-r-lWox09XL17S8F_v7dDqiQK-CXEQdLOf2udS6g3eUW6/s1600/Capture1.PNG&quot; height=&quot;96&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now you will imagine &quot;How To Retrive Values From these Textboxes&quot; ( &lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;a href=&quot;http://naveenvadakattu.blogspot.in/2014/09/how-to-retrive-dynamically-generated.html&quot;&gt;ClickHere&lt;/a&gt;&amp;nbsp;&lt;/span&gt;to see&lt;/b&gt;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/1975879135128990039/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/adding-textbox-dynamically-using.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/1975879135128990039'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/1975879135128990039'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/adding-textbox-dynamically-using.html' title='Adding Textbox Dynamically Using JavaScript in  Asp.Net'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSFZ2JshNuVLWfRl651iS4PvCXtDPilRCbJ_SisquFJb5kUzA6jkV5S9qYCGGB-CvaNJmBS05BPaPO0PZLGlW508LSCJH_jly-r-lWox09XL17S8F_v7dDqiQK-CXEQdLOf2udS6g3eUW6/s72-c/Capture1.PNG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-754709334233058021</id><published>2014-09-19T04:04:00.001-07:00</published><updated>2014-11-03T04:36:02.760-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><title type='text'>Difference between ViewData and ViewBag In MVC</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: large;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;ViewData ,&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;ViewBag&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;&lt;/span&gt;and&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;TempData&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
When passing information from an action method to a view, you basically have three options:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;1&lt;/b&gt;. Use the ViewDatadictionary&lt;br /&gt;
&lt;b&gt;2&lt;/b&gt;. Use &amp;nbsp;ViewBag(starting in MVC 3)&lt;br /&gt;
&lt;b&gt;3&lt;/b&gt;.&amp;nbsp;Use a strongly typed view with a view model object&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ViewData &lt;/span&gt;and &lt;span style=&quot;color: red;&quot;&gt;ViewBag &lt;/span&gt;allow you to add information (primitive types such as integers or even complex objects) that will later be accessible to the view for generating HTML.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;color: red;&quot;&gt;ViewData &lt;/span&gt;is simply a dictionary that uses the key/value pattern. An example of how to use ViewData is provided in below example code. Note that the information in the ViewData dictionary is simply added by giving it a name and setting its value.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Example for ViewData:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;In Action Method&lt;/b&gt;&lt;br /&gt;
public ActionResult ShowError()&lt;br /&gt;
{&lt;br /&gt;
ViewData[&quot;ErrorCode&quot;] = 12345;&lt;br /&gt;
ViewData[&quot;ErrorDescription&quot;] = &quot;Something bad happened&quot;;&lt;br /&gt;
ViewData[&quot;ErrorDate&quot;] = DateTime.Now;&lt;br /&gt;
ViewData[&quot;Exception&quot;] = new Exception();&lt;br /&gt;
return View();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;In ViewPage&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
@* View *@&lt;br /&gt;
&amp;lt;h1&amp;gt;An error was found&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt;Error Code: @ViewData[&quot;ErrorCode&quot;]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt;Error Date: @ViewData[&quot;ErrorDate&quot;]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt;@ViewData[&quot;ErrorDescription&quot;]&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;span style=&quot;color: red;&quot;&gt;ViewBag&lt;/span&gt;:&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;u&gt;&lt;br /&gt;&lt;/u&gt;&lt;/b&gt;
&lt;span style=&quot;color: red;&quot;&gt;ViewBag &lt;/span&gt;is different from &lt;span style=&quot;color: red;&quot;&gt;ViewData &lt;/span&gt;in the sense that it implements the dynamic features introduced in C# 4. Basically, the difference is that properties can be added to ViewBag dynamically. Following example &amp;nbsp;shows &amp;nbsp;modify to above example using ViewBag.&lt;br /&gt;
&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Example for ViewBag:&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;
&lt;u&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/u&gt;
&lt;b&gt;In Action Method&lt;/b&gt;&lt;br /&gt;
public ActionResult ShowError()&lt;br /&gt;
{&lt;br /&gt;
ViewBag.ErrorCode = 12345;&lt;br /&gt;
ViewBag.ErrorDescription = &quot;Something bad happened&quot;;&lt;br /&gt;
ViewBag.Exception = new Exception();&lt;br /&gt;
return View();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;In View&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&amp;lt;h1&amp;gt;An error was found&amp;lt;/h1&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt;Error Code: @ViewBag.ErrorCode&amp;lt;/h2&amp;gt;&lt;br /&gt;
&amp;lt;h2&amp;gt;@ViewBag.ErrorDescription&amp;lt;/h2&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One last thing to consider when using ViewData and ViewBag is that the information in the dictionary is lost after the view is rendered.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;In this scenario, you will have to use a different object that is designed to have a short&lt;br /&gt;
&amp;nbsp;life but is capable of surviving redirects. The object is &lt;span style=&quot;color: red;&quot;&gt;TempData&lt;/span&gt;, which, as opposed to &lt;span style=&quot;color: red;&quot;&gt;ViewData&lt;/span&gt;, is &amp;nbsp;stored in the current session instead of a dictionary. Use TempData with caution, as the information &amp;nbsp;is promptly discarded once the redirect is complete. If you refresh the page, the information in &amp;nbsp;TempData won’t be available.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/754709334233058021/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/difference-between-viewdata-and-viewbag.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/754709334233058021'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/754709334233058021'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/difference-between-viewdata-and-viewbag.html' title='Difference between ViewData and ViewBag In MVC'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4526087644622451460.post-9057048954864327221</id><published>2014-09-12T04:08:00.002-07:00</published><updated>2014-11-03T04:36:14.092-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Asp.Net"/><title type='text'>Adding FaceBook and other Social Networking  Share Button In Page Using Asp.net</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;In aspx page&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Add following html makup where you want to show facebook share button in your page,not only facebook in below markup their are other social sharing sites are there in which they are added to your webpages.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;lt;div class=&quot;addthis_toolbox addthis_default_style addthis_32x32_style&quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;a class=&quot;addthis_button_facebook&quot;&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;a class=&quot;addthis_button_linkedin&quot;&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;a class=&quot;addthis_button_twitter&quot;&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;a class=&quot;addthis_button_pinterest_share&quot;&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt; &amp;nbsp; &amp;nbsp;var addthis_config = { &quot;data_track_addressbar&quot;: true };&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script type=&quot;text/javascript&quot; src=&quot;//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5253e8bc26e8bcf9&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you add above html code and run the application following screen will be appear&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7L0iGaBfwPSJ54a7EhMbDtLoaWjs3XZUpDeB2sNOGjVxIzIlc_9d7498ASe9D7BaVkF53ueoN8bGaMpPKfXD5BSqyG-JPIcgEIecCa3K_hpHm-SNG_-jE_hPxcM-3zy4w-8e6Kuv_1o7k/s1600/Capture.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7L0iGaBfwPSJ54a7EhMbDtLoaWjs3XZUpDeB2sNOGjVxIzIlc_9d7498ASe9D7BaVkF53ueoN8bGaMpPKfXD5BSqyG-JPIcgEIecCa3K_hpHm-SNG_-jE_hPxcM-3zy4w-8e6Kuv_1o7k/s1600/Capture.PNG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Notes:If you click on facebook ,facebook login page will be open,like wise other social login pages will be open if you click other icons.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://aspdotnetassist.blogspot.com/feeds/9057048954864327221/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/adding-facebook-share-button-in-page.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/9057048954864327221'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4526087644622451460/posts/default/9057048954864327221'/><link rel='alternate' type='text/html' href='http://aspdotnetassist.blogspot.com/2014/09/adding-facebook-share-button-in-page.html' title='Adding FaceBook and other Social Networking  Share Button In Page Using Asp.net'/><author><name>Anonymous</name><uri>http://www.blogger.com/profile/05141511459347783664</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7L0iGaBfwPSJ54a7EhMbDtLoaWjs3XZUpDeB2sNOGjVxIzIlc_9d7498ASe9D7BaVkF53ueoN8bGaMpPKfXD5BSqyG-JPIcgEIecCa3K_hpHm-SNG_-jE_hPxcM-3zy4w-8e6Kuv_1o7k/s72-c/Capture.PNG" height="72" width="72"/><thr:total>0</thr:total></entry></feed>