<?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-4054512041533578749</id><updated>2026-10-08T17:07:46.077+05:30</updated><category term="ASP.NET"/><category term="SQL"/><category term="WSH Scripting"/><title type='text'>Dotnet Codes</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Unknown</name><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>25</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-6356275147479253170</id><published>2013-07-02T12:07:00.000+05:30</published><updated>2013-07-02T12:09:25.615+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Some tricky SQL queries Part 2 (Interview Questions)</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;br /&gt;
&lt;b&gt;1.Update Employee salary Department wise in single query&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;update tblEMP
set salary=
case when dept=&#39;HR&#39; then
salary + (salary*10)/100 
when dept=&#39;IT&#39; then
salary + (salary*20)/100 
when dept=&#39;Admin&#39; then
salary + (salary*5)/100 
when dept=&#39;SAP&#39; then
salary + (salary*2)/100 
end
&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;
2.Get 3 Max salaries ?

&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;select distinct sal from emp a where 3 &amp;gt;= (select count(distinct sal) from emp b where a.sal &amp;lt;= b.sal) order by a.sal desc;
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
3.Get 3 Min salaries ?&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;select distinct sal from emp a where 3 &amp;gt;= (select count(distinct sal) from emp b where a.sal &amp;gt;= b.sal);&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
4. Count of number of employees in department wise&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;select count(EMPNO), b.deptno, dname from emp a, dept b where a.deptno(+)=b.deptno group by b.deptno,dname;

&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
5. Delete duplicate rows in a table&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;delete from emp a where rowid != (select max(rowid) from emp b where a.empno=b.empno);&lt;/pre&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/6356275147479253170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2013/07/some-tricky-sql-queries-part-2.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6356275147479253170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6356275147479253170'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2013/07/some-tricky-sql-queries-part-2.html' title='Some tricky SQL queries Part 2 (Interview Questions)'/><author><name>Unknown</name><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>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-6430062631849274606</id><published>2012-07-29T13:36:00.000+05:30</published><updated>2012-07-29T13:38:29.108+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Drop all the tables, stored procedures, triggers, constriants and all dependencies from SQL Server 2005</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Drop all the tables, stored procedures, triggers, constriants and all dependencies
from SQL Server 2005
&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;strong&gt;Code&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;

/* Drop all non-system stored procs */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = &#39;P&#39; AND category = 0 ORDER BY [name])

WHILE @name is not null
BEGIN
    SELECT @SQL = &#39;DROP PROCEDURE [dbo].[&#39; + RTRIM(@name) +&#39;]&#39;
    EXEC (@SQL)
    PRINT &#39;Dropped Procedure: &#39; + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = &#39;P&#39; AND category = 0 AND [name] &gt; @name ORDER BY [name])
END
GO

/* Drop all views */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = &#39;V&#39; AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL
BEGIN
    SELECT @SQL = &#39;DROP VIEW [dbo].[&#39; + RTRIM(@name) +&#39;]&#39;
    EXEC (@SQL)
    PRINT &#39;Dropped View: &#39; + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = &#39;V&#39; AND category = 0 AND [name] &gt; @name ORDER BY [name])
END
GO

/* Drop all functions */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N&#39;FN&#39;, N&#39;IF&#39;, N&#39;TF&#39;, N&#39;FS&#39;, N&#39;FT&#39;) AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL
BEGIN
    SELECT @SQL = &#39;DROP FUNCTION [dbo].[&#39; + RTRIM(@name) +&#39;]&#39;
    EXEC (@SQL)
    PRINT &#39;Dropped Function: &#39; + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] IN (N&#39;FN&#39;, N&#39;IF&#39;, N&#39;TF&#39;, N&#39;FS&#39;, N&#39;FT&#39;) AND category = 0 AND [name] &gt; @name ORDER BY [name])
END
GO

/* Drop all Foreign Key constraints */
DECLARE @name VARCHAR(128)
DECLARE @constraint VARCHAR(254)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;FOREIGN KEY&#39; ORDER BY TABLE_NAME)

WHILE @name is not null
BEGIN
    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;FOREIGN KEY&#39; AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    WHILE @constraint IS NOT NULL
    BEGIN
        SELECT @SQL = &#39;ALTER TABLE [dbo].[&#39; + RTRIM(@name) +&#39;] DROP CONSTRAINT [&#39; + RTRIM(@constraint) +&#39;]&#39;
        EXEC (@SQL)
        PRINT &#39;Dropped FK Constraint: &#39; + @constraint + &#39; on &#39; + @name
        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;FOREIGN KEY&#39; AND CONSTRAINT_NAME &lt;&gt; @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    END
SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;FOREIGN KEY&#39; ORDER BY TABLE_NAME)
END
GO

/* Drop all Primary Key constraints */
DECLARE @name VARCHAR(128)
DECLARE @constraint VARCHAR(254)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;PRIMARY KEY&#39; ORDER BY TABLE_NAME)

WHILE @name IS NOT NULL
BEGIN
    SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;PRIMARY KEY&#39; AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    WHILE @constraint is not null
    BEGIN
        SELECT @SQL = &#39;ALTER TABLE [dbo].[&#39; + RTRIM(@name) +&#39;] DROP CONSTRAINT [&#39; + RTRIM(@constraint)+&#39;]&#39;
        EXEC (@SQL)
        PRINT &#39;Dropped PK Constraint: &#39; + @constraint + &#39; on &#39; + @name
        SELECT @constraint = (SELECT TOP 1 CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;PRIMARY KEY&#39; AND CONSTRAINT_NAME &lt;&gt; @constraint AND TABLE_NAME = @name ORDER BY CONSTRAINT_NAME)
    END
SELECT @name = (SELECT TOP 1 TABLE_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE constraint_catalog=DB_NAME() AND CONSTRAINT_TYPE = &#39;PRIMARY KEY&#39; ORDER BY TABLE_NAME)
END
GO

/* Drop all tables */
DECLARE @name VARCHAR(128)
DECLARE @SQL VARCHAR(254)

SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = &#39;U&#39; AND category = 0 ORDER BY [name])

WHILE @name IS NOT NULL
BEGIN
    SELECT @SQL = &#39;DROP TABLE [dbo].[&#39; + RTRIM(@name) +&#39;]&#39;
    EXEC (@SQL)
    PRINT &#39;Dropped Table: &#39; + @name
    SELECT @name = (SELECT TOP 1 [name] FROM sysobjects WHERE [type] = &#39;U&#39; AND category = 0 AND [name] &gt; @name ORDER BY [name])
END
GO

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/6430062631849274606/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/07/drop-all-tables-stored-procedures.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6430062631849274606'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6430062631849274606'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/07/drop-all-tables-stored-procedures.html' title='Drop all the tables, stored procedures, triggers, constriants and all dependencies from SQL Server 2005'/><author><name>Unknown</name><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-4054512041533578749.post-2719488238250852041</id><published>2012-04-12T16:59:00.000+05:30</published><updated>2012-04-12T16:59:12.822+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Sorting asp.net Gridview using Jquery</title><content type='html'>Tablesorter is a Jquery pulgin easy to use. Now you can sort your data without postbacking the page.It gives the client side sorting functionality.&lt;br /&gt;
&lt;a href=&quot;http://tablesorter.com/docs&quot; target=&quot;_blank&quot;&gt;Click to check more on Tablesorter&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code&lt;/b&gt;&lt;br&gt;&lt;br /&gt;
&lt;b&gt;Default.aspx&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;%@ Page Title=&quot;Home Page&quot; Language=&quot;C#&quot; MasterPageFile=&quot;~/Site.master&quot; AutoEventWireup=&quot;true&quot;
    CodeBehind=&quot;Default.aspx.cs&quot; Inherits=&quot;jqueryTableSort._Default&quot; %&gt;

&lt;asp:Content ID=&quot;HeaderContent&quot; runat=&quot;server&quot; ContentPlaceHolderID=&quot;HeadContent&quot;&gt;
    &lt;style type=&quot;text/css&quot;&gt;
        th
        {
            cursor: pointer;
            background-color: #dadada;
            color: Black;
            font-weight: bold;
            text-align: left;
        }
        th.headerSortUp
        {
            background-image: url(images/asc.gif);
            background-position: right center;
            background-repeat: no-repeat;
        }
        th.headerSortDown
        {
            background-image: url(images/desc.gif);
            background-position: right center;
            background-repeat: no-repeat;
        }
        td
        {
            border-bottom: solid 1px #dadada;
        }
    &lt;/style&gt;
    &lt;script src=&quot;scripts/jquery-1.4.3.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;scripts/jquery.tablesorter.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        $(document).ready(function () {
            $(&quot;#&lt;%=GridView1.ClientID %&gt;&quot;).tablesorter();
        }); 
    &lt;/script&gt;
&lt;/asp:Content&gt;
&lt;asp:Content ID=&quot;BodyContent&quot; runat=&quot;server&quot; ContentPlaceHolderID=&quot;MainContent&quot;&gt;
    &lt;h2&gt;      Sort gridview using Jquery plugin Table Sorter
    &lt;/h2&gt;  
    &lt;p&gt;       &lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; ForeColor=&quot;#333333&quot;
            Font-Size=&quot;9pt&quot; Font-Names=&quot;Arial&quot; AutoGenerateColumns=&quot;False&quot; 
              BorderColor=&quot;#DADADA&quot; BorderStyle=&quot;Solid&quot; BorderWidth=&quot;1px&quot; Width=&quot;20%&quot;&gt;
            &lt;Columns&gt;
                &lt;asp:BoundField DataField=&quot;Id&quot; HeaderText=&quot;Id&quot; /&gt;
                &lt;asp:BoundField DataField=&quot;CountryName&quot; HeaderText=&quot;Country&quot; /&gt;
            &lt;/Columns&gt;
        &lt;/asp:GridView&gt;
    &lt;/p&gt;    
&lt;/asp:Content&gt;

&lt;/pre&gt;&lt;b&gt;Default.aspx.cs&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace jqueryTableSort
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                BindGrid();
                
            }

        }
        #region BIND GRID
        private void BindGrid() 
        {
            CountryDataData objData = new CountryDataData();
            GridView1.DataSource = objData.GetCountryDataList();
            GridView1.DataBind();
            GridView1.UseAccessibleHeader = true;
            GridView1.HeaderRow.TableSection = TableRowSection.TableHeader; 

        }
        #endregion
    }
}
&lt;/pre&gt;&lt;b&gt;CountryData.cs&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace jqueryTableSort
{
    public class CountryDataData
    {
        public int Id { get; set; }
        public string CountryName { get; set; }
        public List&lt;CountryDataData&gt; GetCountryDataList()
        {
            return new List&lt;CountryDataData&gt;
            {
                new CountryDataData{Id=1,CountryName=&quot;India&quot;},
                new CountryDataData{Id=2,CountryName=&quot;Australia&quot;},
                new CountryDataData{Id=3,CountryName=&quot;UK&quot;},
                new CountryDataData{Id=4,CountryName=&quot;UAE&quot;},
                new CountryDataData{Id=5,CountryName=&quot;Bangladesh&quot;},
                new CountryDataData{Id=6,CountryName=&quot;Austria&quot;},
                new CountryDataData{Id=7,CountryName=&quot;Japan&quot;},
                new CountryDataData{Id=8,CountryName=&quot;China&quot;},
                new CountryDataData{Id=9,CountryName=&quot;Dubai&quot;},
                new CountryDataData{Id=10,CountryName=&quot;South Africa&quot;},
                new CountryDataData{Id=11,CountryName=&quot;Mexcico&quot;},
                new CountryDataData{Id=12,CountryName=&quot;Merryland&quot;},
                new CountryDataData{Id=13,CountryName=&quot;USA&quot;},
                new CountryDataData{Id=14,CountryName=&quot;Peru&quot;},
                new CountryDataData{Id=15,CountryName=&quot;Nepal&quot;},
                new CountryDataData{Id=16,CountryName=&quot;Pakistan&quot;},
                new CountryDataData{Id=17,CountryName=&quot;Srilanka&quot;},
                new CountryDataData{Id=18,CountryName=&quot;Vietnam&quot;},
                new CountryDataData{Id=19,CountryName=&quot;Westindies&quot;},
                new CountryDataData{Id=20,CountryName=&quot;England&quot;},
                new CountryDataData{Id=21,CountryName=&quot;Afganistan&quot;},
                new CountryDataData{Id=22,CountryName=&quot;Russia&quot;},
                new CountryDataData{Id=23,CountryName=&quot;Newzeland&quot;},
                new CountryDataData{Id=24,CountryName=&quot;Timore&quot;},
                new CountryDataData{Id=25,CountryName=&quot;Canada&quot;}

            };

        }

    }
}


&lt;/pre&gt;&lt;/br&gt;&lt;a href=&quot;http://www.box.com/s/df638dc11570245b59c3&quot; target=&quot;_blank&quot;&gt;Download Code&lt;/a&gt;&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/AVvXsEgjeRc4_QjDS87Uz-7kTf22AJtGLUt5y5d6yPTAs2afmpWa2Y0mnUTrqMJc_TnEM0_CIEuwjCMVHRBfCaF4rpiE9mroxsg2lwZ0mVyjO1VAAa2-UGSaeMQ9qjRrWDfo_I5v0D4Wrlh8fVo/s1600/img1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear:left; float:left;margin-right:1em; margin-bottom:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; width=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgjeRc4_QjDS87Uz-7kTf22AJtGLUt5y5d6yPTAs2afmpWa2Y0mnUTrqMJc_TnEM0_CIEuwjCMVHRBfCaF4rpiE9mroxsg2lwZ0mVyjO1VAAa2-UGSaeMQ9qjRrWDfo_I5v0D4Wrlh8fVo/s320/img1.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/br&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/2719488238250852041/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/04/sorting-aspnet-gridview-using-jquery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/2719488238250852041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/2719488238250852041'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/04/sorting-aspnet-gridview-using-jquery.html' title='Sorting asp.net Gridview using Jquery'/><author><name>Unknown</name><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/AVvXsEgjeRc4_QjDS87Uz-7kTf22AJtGLUt5y5d6yPTAs2afmpWa2Y0mnUTrqMJc_TnEM0_CIEuwjCMVHRBfCaF4rpiE9mroxsg2lwZ0mVyjO1VAAa2-UGSaeMQ9qjRrWDfo_I5v0D4Wrlh8fVo/s72-c/img1.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-4557739795315768367</id><published>2012-04-02T12:27:00.000+05:30</published><updated>2012-04-02T12:27:08.348+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Creating ZIP and UNZIP files in ASP.NET using DotNetZip library.</title><content type='html'>&lt;div&gt;&lt;a href=&quot;http://dotnetzip.codeplex.com/&quot; target=&quot;_blank&quot;&gt;DotNetZip&lt;/a&gt; is easy to use free class library for ziping and extracing the zip files.&lt;br /&gt;
Check this &lt;a href=&quot;http://dotnetzip.codeplex.com/&quot; target=&quot;_blank&quot;&gt;DotNetZip&lt;/a&gt; for more information.&lt;br /&gt;
&lt;/div&gt;&lt;/br&gt;&lt;b&gt;Example &lt;/b&gt;&lt;/br&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ionic.Zlib;
using Ionic.Zip;
using System.IO;




namespace ZipFilesAspDotnet
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #region Download ZIP File
        private void DownloadFile()
        {
            if (FileUpload1.HasFile)
            {
                //file upload folder App_Data
                string _fileName = FileuploadUtility.UploadFile(FileUpload1, Server.MapPath(&quot;~/App_Data/&quot;), Session.SessionID);
                string[] _zip_fileName = _fileName.ToString().Split(&#39;.&#39;);
                Response.Clear();
                Response.ContentType = &quot;application/zip&quot;;
                Response.AddHeader(&quot;content-disposition&quot;, &quot;filename=&quot; + &quot;download_&quot; + _zip_fileName.ToString() + &quot;.zip&quot;);

                using (ZipFile zip = new ZipFile())
                {
                    zip.AddEntry(_fileName.ToString(), File.ReadAllBytes(Server.MapPath(&quot;~/App_Data/&quot; + _fileName.ToString())));
                    zip.Save(Response.OutputStream);
                }
            }

        }
        #endregion

        #region EXTRACT THE ZIP FILE
        private void ExtractZipFile() 
        {
            string _fileName = FileuploadUtility.UploadFile(FileUpload1, Server.MapPath(&quot;~/App_Data/&quot;), Session.SessionID);

            using (ZipFile zip1 = ZipFile.Read(Server.MapPath(&quot;~/App_Data/&quot; + _fileName.ToString())))
            {
                
                foreach (ZipEntry e in zip1)
                {
                    //destination folder zipfiles
                    e.Extract(Server.MapPath(&quot;~/ZipFiles/&quot;), ExtractExistingFileAction.OverwriteSilently);
                }
            }

        }
        #endregion

        protected void Button1_Click(object sender, EventArgs e)
        {
            DownloadFile();

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            ExtractZipFile();
        }
    }
}

&lt;/pre&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/AVvXsEiucZDm8Xnzro4KKGnRuZz8yi5QR640JVaYIDYp-ptwXXaLBhvnIc9hA1ptp4LNonkuYqPJDzBUlkUuyxlAfjCKO1V97ykcrE_SywbJPJcBQk1SuY7q16qt971JjZLnREWIuEQTj8ilfBc/s1600/zipfiles.JPG&quot; imageanchor=&quot;1&quot; style=&quot;clear:left; float:left;margin-right:1em; margin-bottom:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; width=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiucZDm8Xnzro4KKGnRuZz8yi5QR640JVaYIDYp-ptwXXaLBhvnIc9hA1ptp4LNonkuYqPJDzBUlkUuyxlAfjCKO1V97ykcrE_SywbJPJcBQk1SuY7q16qt971JjZLnREWIuEQTj8ilfBc/s320/zipfiles.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.box.com/s/c4d7c388a86e3dd6c9f0&quot; target=&quot;_blank&quot;&gt;Download Sample&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/4557739795315768367/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/04/creating-zip-and-unzip-files-in-aspnet.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/4557739795315768367'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/4557739795315768367'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/04/creating-zip-and-unzip-files-in-aspnet.html' title='Creating ZIP and UNZIP files in ASP.NET using DotNetZip library.'/><author><name>Unknown</name><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/AVvXsEiucZDm8Xnzro4KKGnRuZz8yi5QR640JVaYIDYp-ptwXXaLBhvnIc9hA1ptp4LNonkuYqPJDzBUlkUuyxlAfjCKO1V97ykcrE_SywbJPJcBQk1SuY7q16qt971JjZLnREWIuEQTj8ilfBc/s72-c/zipfiles.JPG" height="72" width="72"/><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-4805144306465986594</id><published>2012-02-05T15:21:00.000+05:30</published><updated>2012-02-05T15:21:36.702+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Change DB owner in SQL Server Database</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Change db owner in sql server 2005 database.&lt;/div&gt;&lt;/br&gt;&lt;b&gt;Example &lt;/b&gt;&lt;/br&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;DECLARE @old sysname, @sql varchar(1000)

SELECT

 @old = &#39;oldOwner_CHANGE_THIS&#39;

 , @sql = &#39;

 IF EXISTS (SELECT NULL FROM INFORMATION_SCHEMA.TABLES

 WHERE

     QUOTENAME(TABLE_SCHEMA)+&#39;&#39;.&#39;&#39;+QUOTENAME(TABLE_NAME) = &#39;&#39;?&#39;&#39;

     AND TABLE_SCHEMA = &#39;&#39;&#39; + @old + &#39;&#39;&#39;

 )

 ALTER SCHEMA dbo TRANSFER ?&#39;

EXECUTE sp_MSforeachtable @sql
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/4805144306465986594/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/02/change-db-owner-in-sql-server-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/4805144306465986594'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/4805144306465986594'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/02/change-db-owner-in-sql-server-database.html' title='Change DB owner in SQL Server Database'/><author><name>Unknown</name><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-4054512041533578749.post-8789068821128747565</id><published>2012-02-02T15:55:00.000+05:30</published><updated>2012-02-02T15:55:56.845+05:30</updated><title type='text'>Dotnet Codes</title><content type='html'>&lt;a href=&quot;http://dotnetcodeshelp.blogspot.com/#.TypkVIJmG4Q.blogger&quot;&gt;Dotnet Codes&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/8789068821128747565/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/02/dotnet-codes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/8789068821128747565'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/8789068821128747565'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2012/02/dotnet-codes.html' title='Dotnet Codes'/><author><name>Unknown</name><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-4054512041533578749.post-3019248417459430113</id><published>2011-10-13T11:44:00.000+05:30</published><updated>2011-10-13T11:44:57.702+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Difference between ref and out parameters in c#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;The difference between ref and out parameters is at the language level. In case of ref you must have to assign it as in &quot;Example by ref&quot; string val is assigned.&lt;br /&gt;
In case of out  you don&#39;t need to assign an out parameter before passing it to a method. But the out parameter in that method must assign the parameter before returning.&lt;/div&gt;&lt;/br&gt;&lt;b&gt;Example &lt;/b&gt;&lt;/br&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
        Response.Write(&quot;Example by ref&quot;);
        string val = &quot;hello&quot;;
        ExampleByRef(ref  val);
        Response.Write(val);
        Response.Write(&quot;Example by out&lt;/br&gt;&quot;);
        string vals;
        ExampleByOut(out  vals);

    }
    public static void ExampleByRef(ref string val)
    {
        if (val == &quot;hello&quot;)
        {

            System.Web.HttpContext.Current.Response.Write(&quot;Example by ref case&quot;);
        }
        else
        { System.Web.HttpContext.Current.Response.Write(&quot;Example by ref else response&quot;); }
        val = &quot;hi&quot;;
    }
    public static void ExampleByOut(out string vals)
    {
        vals = &quot;Example by Out case&lt;/br&gt;&quot;;
        System.Web.HttpContext.Current.Response.Write(vals);
    }
     
 }
&lt;/pre&gt;&lt;/br&gt;&lt;br /&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
Example by ref&lt;br /&gt;
Example by ref case&lt;br /&gt;
hi&lt;br /&gt;
Example by out&lt;br /&gt;
Example by Out case</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/3019248417459430113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/10/difference-between-ref-and-out.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3019248417459430113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3019248417459430113'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/10/difference-between-ref-and-out.html' title='Difference between ref and out parameters in c#'/><author><name>Unknown</name><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>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-238742477239961469</id><published>2011-09-14T14:03:00.001+05:30</published><updated>2011-09-14T15:05:27.844+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Track User status if user closes the browser window.</title><content type='html'>This is a sample application of &quot;User Status&quot; tracking in asp.net. When the user is logged in. This will show the user status as online user. If the user click on logout then it automatically logout user and update the user status as off line. But what if the user closes the browser then also you can track the status.&lt;br /&gt;
Here in this example I have used SQL server as database. I have created a table [tbluserlogins] in database with a &quot;userstatus&quot; column as bit datatype. Every time I update the &quot;userstatus&quot; when user logged in and logged out.&lt;br /&gt;
&lt;br /&gt;
Sample Table Structure&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;CREATE TABLE [dbo].[tblUserLogins](
 [sno] [int] IDENTITY(1,1) NOT NULL,
 [username] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
 [password] [nvarchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
 [userStatus] [bit] NOT NULL,
 [lastLogin] [datetime] NOT NULL CONSTRAINT [DF_tblUserLogins_lastLogin]  DEFAULT (getdate()),
 CONSTRAINT [PK_tblUserLogins] PRIMARY KEY CLUSTERED 
(
 [username] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
&lt;/pre&gt;1. We have to maintain the session state like this&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;sessionstate mode=&quot;InProc&quot; timeout=&quot;5&quot;/&gt;&lt;/pre&gt;2. In global.asax there we can update the status.&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        //Update the user status if the application is closed

        try
        {
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, System.Data.CommandType.Text, &quot;update tblUserLogins set userStatus=&#39;false&#39; where sno=&quot; + Session[&quot;userid&quot;].ToString(), null);
        }
        catch (Exception ex)
        {

            throw ex;
        }


    }


&lt;/pre&gt;&lt;pre class=&quot;brush: html&quot;&gt;void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
        //If the user close the browser window or session is end. It will automatically update the staus
        try
        {
            SqlHelper.ExecuteNonQuery(SqlHelper.mainConnectionString, System.Data.CommandType.Text, &quot;update tblUserLogins set userStatus=&#39;false&#39; where sno=&quot; + Session[&quot;userid&quot;].ToString(), null);
        }
        catch (Exception ex)
        {

            throw ex;
        }

    }
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/z3gkfdmlr1yzteqg7ykg&quot; target=&quot;_blank&quot;&gt;Download the sample code&lt;/a&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/AVvXsEiiAr5exzKaZvBhqHOEb3pX5lqRqd2oSAH51aKz15n081dtSsyI7s1_fTKB19YW9d3P2hRZ7dCBn1TgZ3nyQr7TC5O1Xpry5BxHDUWJk8zchpYA92LIolN8WQ5DWZlLBlG3L1qt63SgVzQ/s1600/img1.GIF&quot; imageanchor=&quot;1&quot; style=&quot;clear:left; float:left;margin-right:1em; margin-bottom:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; width=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiiAr5exzKaZvBhqHOEb3pX5lqRqd2oSAH51aKz15n081dtSsyI7s1_fTKB19YW9d3P2hRZ7dCBn1TgZ3nyQr7TC5O1Xpry5BxHDUWJk8zchpYA92LIolN8WQ5DWZlLBlG3L1qt63SgVzQ/s320/img1.GIF&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&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/AVvXsEgb2wjN_wyzcuF7KiG_1pprm-r7deIaZHCwlQRQKgrjbaCR_2FLlU-kcxFHrKAD9lcJ_J59CcpJJTCQcIkuB7kjBZI3ClQJoGU-yFNc1lp9Hjkwkdla2mer9BaooNBM2nulJYXBxYxk6Hs/s1600/img2.GIF&quot; imageanchor=&quot;1&quot; style=&quot;clear:left; float:left;margin-right:1em; margin-bottom:1em&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;180&quot; width=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgb2wjN_wyzcuF7KiG_1pprm-r7deIaZHCwlQRQKgrjbaCR_2FLlU-kcxFHrKAD9lcJ_J59CcpJJTCQcIkuB7kjBZI3ClQJoGU-yFNc1lp9Hjkwkdla2mer9BaooNBM2nulJYXBxYxk6Hs/s320/img2.GIF&quot; /&gt;&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/238742477239961469/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/09/track-user-status-if-user-closes.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/238742477239961469'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/238742477239961469'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/09/track-user-status-if-user-closes.html' title='Track User status if user closes the browser window.'/><author><name>Unknown</name><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/AVvXsEiiAr5exzKaZvBhqHOEb3pX5lqRqd2oSAH51aKz15n081dtSsyI7s1_fTKB19YW9d3P2hRZ7dCBn1TgZ3nyQr7TC5O1Xpry5BxHDUWJk8zchpYA92LIolN8WQ5DWZlLBlG3L1qt63SgVzQ/s72-c/img1.GIF" height="72" width="72"/><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-6054094602025375446</id><published>2011-06-13T13:24:00.001+05:30</published><updated>2011-06-13T13:26:35.994+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Client Callbacks in ASP.NET</title><content type='html'>Some time a situation comes wherein you want to process some server side processing without refreshing the whole page. This can be achived by using Microsoft ajax controls like &quot;UpdatePanel&quot; but some time you want to implement a functionality on your own in that case you can use your own client Callbacks. &lt;br /&gt;
For this first we will implement the System.Web.UI.ICallbackEventHandler. The ICallbackEventHandler has two methods.&lt;br /&gt;
1. GetCallbackResult : This method will return the reslut of server side processing.&lt;br /&gt;
&lt;br /&gt;
2. RaiseCallbackEvent : This method will be called by client and you can use it to get the parameter values from client.&lt;br /&gt;
&lt;br /&gt;
In this example I have used a Textbox and getting the value of that text box value in a lable while typing in textbox.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code&lt;/b&gt;&lt;content contentplaceholderid=&quot;MainContent&quot; id=&quot;BodyContent&quot; runat=&quot;server&quot;&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;script type=&quot;text/javascript&quot;&gt;
        function ClientFunction(args) {
            var label = document.getElementById(&#39;&lt;%=Label1.ClientID%&gt;&#39;);
            label.innerText = args;
        }   
    
&lt;/script&gt; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;h2&gt;Welcome to ASP.NET!
&lt;/h2&gt;&lt;textbox id=&quot;TextBox1&quot; onkeypress=&quot;CallServerCode(this.value)&quot; runat=&quot;server&quot;&gt; 
&lt;/textbox&gt;
    
&lt;label id=&quot;Label1&quot; runat=&quot;server&quot;&gt;&lt;/label&gt;
    
&lt;/content&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CallbackExample
{


    public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
    {
        string _result = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            //callback reference of the client-side function which will be called after the completion of server side processing. 
            string callbackRef = Page.ClientScript.GetCallbackEventReference(this, &quot;args&quot;, &quot;ClientFunction&quot;, &quot;&quot;);
            // Javascript function that will be called from client to call the server
            string callBackFunctionScript = @&quot;function CallServerFunction(args){&quot; + callbackRef + &quot;}&quot;;
            // Now register the script on the page
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), &quot;CallServerFunction&quot;, callBackFunctionScript, true);
        }

        public string GetCallbackResult()
        {
            //throw new NotImplementedException();
            return _result;


        }

        public void RaiseCallbackEvent(string eventArgument)
        {
            _result = eventArgument;
        }

        
    }
}


&lt;/pre&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/AVvXsEjDpcbL1itAeKUmwMKwa0Vx1cyx3yGcWceypD67ND5aBQ5gticW7Sb1-ivDHdScCLO6SL_F8uaYfb_1D-82CZh87ogxT_flvXaBTTh_pzl9PYl1CIbvVhmJ2Dw2WTgQUnjgvjOr5MaA-2A/s1600/callbackIMG.JPG&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; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDpcbL1itAeKUmwMKwa0Vx1cyx3yGcWceypD67ND5aBQ5gticW7Sb1-ivDHdScCLO6SL_F8uaYfb_1D-82CZh87ogxT_flvXaBTTh_pzl9PYl1CIbvVhmJ2Dw2WTgQUnjgvjOr5MaA-2A/s320/callbackIMG.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br&gt;&lt;br&gt;&lt;br /&gt;
 &lt;a href=&quot;http://www.box.net/shared/7n6tkibqbm2ny6pa5g7r&quot; target=&quot;_blank&quot; &gt;Download Code&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/6054094602025375446/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/06/client-callbacks-in-aspnet.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6054094602025375446'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6054094602025375446'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/06/client-callbacks-in-aspnet.html' title='Client Callbacks in ASP.NET'/><author><name>Unknown</name><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/AVvXsEjDpcbL1itAeKUmwMKwa0Vx1cyx3yGcWceypD67ND5aBQ5gticW7Sb1-ivDHdScCLO6SL_F8uaYfb_1D-82CZh87ogxT_flvXaBTTh_pzl9PYl1CIbvVhmJ2Dw2WTgQUnjgvjOr5MaA-2A/s72-c/callbackIMG.JPG" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-2249882468105705918</id><published>2011-03-16T17:08:00.000+05:30</published><updated>2011-03-16T17:08:00.344+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Import gmail address using  asp.net c#</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Import email addresses like in any social networking site.Below example we have used to fetch the gmail address.&lt;br /&gt;
For this we require &lt;a href=&quot;http://code.google.com/p/google-gdata/&quot; target=&quot;_blank&quot;&gt;Google Data API&lt;/a&gt; and install the same to get the required dlls.&lt;br /&gt;
Add these dlls as reference in your project.&lt;br /&gt;
1. Google.GData.Client&lt;br /&gt;
2. Google.GData.Contacts &lt;br /&gt;
3. Google.GData.Extensions&lt;br /&gt;
Use .net framework 3.5 or 4.0&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Default.aspx.cs&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Google.Contacts;
using Google.GData.Client;
using Google.GData.Contacts;
using Google.GData.Extensions;

namespace GmailContacts
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #region FETCH EMAIL IDS
        private List&lt;emaillists&gt; FetchEmailIds(string emailid, string password)
        {
            List&lt;emaillists&gt; emaillist = new List&lt;emaillists&gt;();
            try
            {

                RequestSettings Logindetails = new RequestSettings(&quot;&quot;, emailid, password);
                Logindetails.AutoPaging = true;
                ContactsRequest getRequest = new ContactsRequest(Logindetails);
                Feed&lt;contact&gt; listContacts = getRequest.GetContacts();
                foreach (Contact mailAddress in listContacts.Entries)
                {
                    // Response.Write(mailAddress.Title + &quot;
&quot;);
                    foreach (EMail emails in mailAddress.Emails)
                    {
                        EmailLists emailaddress = new EmailLists();
                        emailaddress.Title = mailAddress.Title;
                        emailaddress.EmailAddress = emails.Address;
                        //Response.Write(emails.Address + &quot;
&quot;);
                        emaillist.Add(emailaddress);
                    }

                }

            }
            catch (Exception)
            {

                Label1.Text = &quot;Sorry your email id  or password does not match.&quot;;
            }
            return emaillist;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            GridView1.DataSource = FetchEmailIds(txtEmailId.Text, txtPassword.Text);
            GridView1.DataBind();

        }


        #endregion
    }

}

&lt;/pre&gt;&lt;b&gt;EmailLists.cs&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace GmailContacts
{
    public class EmailLists
    {
        public string Title { get; set; }
        public string EmailAddress { get; set; }

    }
}
&lt;/pre&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/AVvXsEiqqoCSVCApPISKRGR61pCijCcFuNDDmsWoVR8LwK5SlKPiHZepja6qdjA4r7LoYyuk98LKaZkMEbDKaMTQF2biras4UncIiKPs7rE97fnXG03KSrRDoA8jYAhNyiWOCu2j0WZWK_plEqg/s1600/importGmailIds.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; r6=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqqoCSVCApPISKRGR61pCijCcFuNDDmsWoVR8LwK5SlKPiHZepja6qdjA4r7LoYyuk98LKaZkMEbDKaMTQF2biras4UncIiKPs7rE97fnXG03KSrRDoA8jYAhNyiWOCu2j0WZWK_plEqg/s320/importGmailIds.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/5v9ohj2jlc&quot; target=&quot;_blank&quot;&gt;Download Code&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/2249882468105705918/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/03/import-gmail-address-using-aspnet-c.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/2249882468105705918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/2249882468105705918'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/03/import-gmail-address-using-aspnet-c.html' title='Import gmail address using  asp.net c#'/><author><name>Unknown</name><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/AVvXsEiqqoCSVCApPISKRGR61pCijCcFuNDDmsWoVR8LwK5SlKPiHZepja6qdjA4r7LoYyuk98LKaZkMEbDKaMTQF2biras4UncIiKPs7rE97fnXG03KSrRDoA8jYAhNyiWOCu2j0WZWK_plEqg/s72-c/importGmailIds.JPG" height="72" width="72"/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-3144883100683644915</id><published>2011-02-28T11:31:00.000+05:30</published><updated>2011-02-28T11:31:57.121+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="WSH Scripting"/><title type='text'>Scheduling the task using WSH script</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;Sometimes you need to do some automated task perform by the system itself, for a specific time period. You can do this by WSH script.&lt;br /&gt;
The below code uses to move the file from one folder to another folder at a specific time period&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;Dim OriginFolder, DestinationFolder, sFile, oFSO, oShell  
 Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;) 
 Set oShell = CreateObject(&quot;Wscript.Shell&quot;) 
 OriginFolder = &quot;d:\folder1&quot; 
 DestinationFolder = &quot;d:\folder2&quot; 
 On Error Resume Next  
  
   Call MoveFiles()  
   
 Sub MoveFiles() 
  
     For Each sFile In oFSO.GetFolder(OriginFolder).Files 
       If Not oFSO.FileExists(DestinationFolder &amp;amp; &quot;\&quot; &amp;amp; oFSO.GetFileName(sFile)) Then 
  oFSO.GetFile(sFile).copy DestinationFolder &amp;amp; &quot;\&quot; &amp;amp; oFSO.GetFileName(sFile),True 
  oFSO.deleteFile(OriginFolder &amp;amp; &quot;\&quot; &amp;amp; oFSO.GetFileName(sFile))
     End If 
     Next 
    
 End Sub 
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Steps to install the script in Scheduled Task. Browse your .vbs file in Scheduled Task. &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/AVvXsEh2w28swqAEAedGp5tgwhUR4RZl5BlAbeHl1JxwA1YZSNTK0cWdEjOtRBvmMq-wrWuBiIo6GT9GxmfI3PzQTAFZyhwNmSbQFK54EfmRU8mNlUjBC1LE_ycPfnb-oOjP3-78OjPNE3ITGuw/s1600/step1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; l6=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2w28swqAEAedGp5tgwhUR4RZl5BlAbeHl1JxwA1YZSNTK0cWdEjOtRBvmMq-wrWuBiIo6GT9GxmfI3PzQTAFZyhwNmSbQFK54EfmRU8mNlUjBC1LE_ycPfnb-oOjP3-78OjPNE3ITGuw/s320/step1.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&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/AVvXsEiLAWDGati9yfgiM_euJOps55Lz-7QZVyqOUo1OGULDoRSpkj8eUSNTcyj-JSKQK_ogRieewSPscx75SEnt67CT0xKE3HA6VhKbJIb3Rj-Mcw_Df5h33QsO-aNcIfDiXwvv6AzXYtCSlO8/s1600/step2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; l6=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiLAWDGati9yfgiM_euJOps55Lz-7QZVyqOUo1OGULDoRSpkj8eUSNTcyj-JSKQK_ogRieewSPscx75SEnt67CT0xKE3HA6VhKbJIb3Rj-Mcw_Df5h33QsO-aNcIfDiXwvv6AzXYtCSlO8/s320/step2.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&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/AVvXsEgU4QgPDx2T3RqvAuJoBqDoxle-_suWsuOWhk4oOQcKpjfiF8QoUCeZ5Eq5e6Bu7S5ikCY8QvFYuxTC-nzSgRXOF01d4npb6t61RKcAiclYLCODuyiejgrZFJG-KKK57apoQYHIpbztkXQ/s1600/step3.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;245&quot; l6=&quot;true&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU4QgPDx2T3RqvAuJoBqDoxle-_suWsuOWhk4oOQcKpjfiF8QoUCeZ5Eq5e6Bu7S5ikCY8QvFYuxTC-nzSgRXOF01d4npb6t61RKcAiclYLCODuyiejgrZFJG-KKK57apoQYHIpbztkXQ/s320/step3.JPG&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/r80xixtidu&quot; target=&quot;_blank&quot;&gt;&lt;br /&gt;
Download Code&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/3144883100683644915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/02/scheduling-task-using-wsh-script.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3144883100683644915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3144883100683644915'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/02/scheduling-task-using-wsh-script.html' title='Scheduling the task using WSH script'/><author><name>Unknown</name><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/AVvXsEh2w28swqAEAedGp5tgwhUR4RZl5BlAbeHl1JxwA1YZSNTK0cWdEjOtRBvmMq-wrWuBiIo6GT9GxmfI3PzQTAFZyhwNmSbQFK54EfmRU8mNlUjBC1LE_ycPfnb-oOjP3-78OjPNE3ITGuw/s72-c/step1.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-5826651705985150158</id><published>2011-01-30T15:35:00.005+05:30</published><updated>2011-01-31T10:41:05.104+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>A basic tutorial for WCF: Windows Communication Foundation</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;&lt;strong&gt;What is WCF:&amp;nbsp;&lt;/strong&gt; Windows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a runtime environment for your services, enabling you to expose CLR types as services, and to consume other services as CLR types&lt;br /&gt;
WCF is part of .NET 3.0 and requires .NET 2.0, so it can only run on operation systems that support it.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Why do we need this: &lt;/strong&gt;This is the latest SOA technologies and it combines the features of Web Service,MSMQ,Remoting and COM+.&lt;br /&gt;
It provides a common plateform for all .NET communication. Interoperability is the fundamental characteristics of WCF.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;ABC&#39;s of WCF:&lt;/b&gt; The 3 parts of the WCF. Address, Binding and Contract.&lt;br /&gt;
&lt;b&gt;Address:&lt;/b&gt; Address is the address of the service. like (http://localhost:61685/Service1.svc)&lt;br /&gt;
&lt;b&gt;Binding:&lt;/b&gt; It has number of binding models. It specifies the protocol to communicate.&lt;br /&gt;
&lt;b&gt;Contract:&lt;/b&gt; Contract is the method exposed to the client. It gives the Data member serialization this is the main reason that it is faster than Webservice. &lt;br /&gt;
&lt;br /&gt;
It includes Service Contract, Operation Contract and Data Contract&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;[Service Contract]:&lt;/b&gt; This attribute define saying which application interface will be exposed as service.&lt;br /&gt;
&lt;b&gt;[Operation Contract]:&lt;/b&gt; It defines which method should be exposed to the external client, using this service.&lt;br /&gt;
&lt;b&gt;[Data Contract]: &lt;/b&gt;Data Contract&amp;nbsp; defines which type of complex data will be exchanged between the client and server. &lt;br /&gt;
&lt;br /&gt;
The sample code is not a simple &quot;Hello World&quot; application. The sample includes a login system application.&lt;br /&gt;
It includes&amp;nbsp; WCF host and one client. The host authenticate the user against a username and password, checked by WCF host and returns a boolean variable.The client includes a username and password screen, where user can put the username and password to authenticate the client application.&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/AVvXsEh5W_D08NlfHgguMhma8_hgCDw7TR0c9cNtxyh6CvRkPvNd65Jbtweb7F7RBfwntH_2FkhZnsxMezpOem16kohf4oxoWk9jLVIc_J1BdABrmW4EWGDqaGlNfAvv0e46N2CJwKb1p_fcj18/s1600/servicereference.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;/a&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/AVvXsEj6KEpWmstDfJN3KVfYICFc1FJiTb1MbG_IQDlwpI9PC7C026gz4Bhn3nc41a2B1I1smWIBPvz8PUkI0D94muW_u6P-_Wy83QiE03OVXkpdrIzgE5mMug_B8Nl9ojPN1HLklBdR-o2fY2o/s1600/servicecontracts.jpg&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; height=&quot;149&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6KEpWmstDfJN3KVfYICFc1FJiTb1MbG_IQDlwpI9PC7C026gz4Bhn3nc41a2B1I1smWIBPvz8PUkI0D94muW_u6P-_Wy83QiE03OVXkpdrIzgE5mMug_B8Nl9ojPN1HLklBdR-o2fY2o/s320/servicecontracts.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&amp;nbsp;&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/AVvXsEjnLzc5g6kmM6iuA4OsU8U7dlxRDy2SD41xlc7YguM0LIpBlh5ew9sFiYqU9Qe2pbSvHjhZ_BaeFubn26HbL7rK2ZBdK4i5M9_OdrfiJGt8cQudy_BYR60S4CQSUl_ePyl5LUk2Ye-nup4/s1600/datamember.jpg&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; height=&quot;174&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnLzc5g6kmM6iuA4OsU8U7dlxRDy2SD41xlc7YguM0LIpBlh5ew9sFiYqU9Qe2pbSvHjhZ_BaeFubn26HbL7rK2ZBdK4i5M9_OdrfiJGt8cQudy_BYR60S4CQSUl_ePyl5LUk2Ye-nup4/s320/datamember.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5W_D08NlfHgguMhma8_hgCDw7TR0c9cNtxyh6CvRkPvNd65Jbtweb7F7RBfwntH_2FkhZnsxMezpOem16kohf4oxoWk9jLVIc_J1BdABrmW4EWGDqaGlNfAvv0e46N2CJwKb1p_fcj18/s1600/servicereference.jpg&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;264&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5W_D08NlfHgguMhma8_hgCDw7TR0c9cNtxyh6CvRkPvNd65Jbtweb7F7RBfwntH_2FkhZnsxMezpOem16kohf4oxoWk9jLVIc_J1BdABrmW4EWGDqaGlNfAvv0e46N2CJwKb1p_fcj18/s320/servicereference.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/86hi6l6k11&quot; target=&quot;_blank&quot;&gt;Download Code &lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/5826651705985150158/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/01/basic-tutorial-for-wcf-windows.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/5826651705985150158'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/5826651705985150158'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2011/01/basic-tutorial-for-wcf-windows.html' title='A basic tutorial for WCF: Windows Communication Foundation'/><author><name>Unknown</name><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/AVvXsEj6KEpWmstDfJN3KVfYICFc1FJiTb1MbG_IQDlwpI9PC7C026gz4Bhn3nc41a2B1I1smWIBPvz8PUkI0D94muW_u6P-_Wy83QiE03OVXkpdrIzgE5mMug_B8Nl9ojPN1HLklBdR-o2fY2o/s72-c/servicecontracts.jpg" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-3833135594644274197</id><published>2010-12-21T17:45:00.000+05:30</published><updated>2010-12-21T17:45:01.992+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Inline Table-valued Function in SQL server for optimized result.</title><content type='html'>Sometime we want to parameterize our view for getting the optimized result, but we cannot pass the parameter to view. In this case we can use inline table valued parameterize function which will return the &quot;Table&quot;. We can use this table in joins, sql queries, stored procedures and anywhere like as normal table.&lt;br /&gt;
First we will create view and see the result and time taken by view. Then after we will create the function which returns table with a parameter.&lt;br /&gt;
Code&lt;br /&gt;
&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;View&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;create view GetAllDatabyCountry
as
select product.productid,product.productname,product.code,product.productPrice
   ,country.countryname,city.cityname
   from product
   left outer join
   country on product.countryid=country.countryid
   left outer join
   city on product.cityId=city.cityId
   &lt;/pre&gt;&lt;br/&gt;&lt;br /&gt;
 &lt;br /&gt;
&lt;b&gt;Function&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;Create function GetDatabyCountryId(@countryId int)
returns table
as
return (
   select product.productid,product.productname,product.code,product.productPrice
   ,country.countryname,city.cityname
   from product 
   left outer join
   country on product.countryid=country.countryid
   left outer join
   city on product.cityId=city.cityId
   where country.countryid=@countryId
  )
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;Using Function in Query&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;create procedure getDataByCountryId
@countryId int
as
begin
select getDataBycountry.* from  dbo.GetDatabyCountryId(@countryId) as getDataBycountry
end
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/3833135594644274197/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/12/inline-table-valued-function-in-sql.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3833135594644274197'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3833135594644274197'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/12/inline-table-valued-function-in-sql.html' title='Inline Table-valued Function in SQL server for optimized result.'/><author><name>Unknown</name><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-4054512041533578749.post-5835414228803387422</id><published>2010-12-15T15:02:00.001+05:30</published><updated>2010-12-15T15:02:05.313+05:30</updated><title type='text'>Validate checkbox in ASP.NET</title><content type='html'>You can validate check box or any custom control by using &quot;CustomValidator&quot; and javascript.&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt; &lt;script language=&quot;javascript&quot;&gt;

         function validateCheckbox(sender, args) {
            var chkControlId = &#39;&lt;%=CheckBox1.ClientID%&gt;&#39;
            var options = document.getElementById(chkControlId);
            var ischecked = false;
            args.IsValid = false;
            if (options.checked) {
                  ischecked = true;
                 args.IsValid = true;
             }
    &lt;/script&gt;
 Check box in your aspx page
  
   &lt;asp:CheckBox ID=&quot;CheckBox1&quot; runat=&quot;server&quot; Checked=&quot;True&quot; /&gt;
   
     &lt;asp:CustomValidator ID=&quot;CustomValidator2&quot; Display=&quot;Dynamic&quot; runat=&quot;server&quot; EnableClientScript=&quot;true&quot;
                        ClientValidationFunction=&quot;validateCheckbox&quot; ErrorMessage=&quot;Please check terms and conditions..&quot;
                        ValidationGroup=&quot;payment&quot;&gt;*&lt;/asp:CustomValidator&gt;
 &lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/5835414228803387422/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/12/validate-checkbox-in-aspnet_939.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/5835414228803387422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/5835414228803387422'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/12/validate-checkbox-in-aspnet_939.html' title='Validate checkbox in ASP.NET'/><author><name>Unknown</name><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-4054512041533578749.post-9189218255783374952</id><published>2010-12-03T14:27:00.001+05:30</published><updated>2010-12-03T14:50:58.002+05:30</updated><title type='text'>Sharing settings specified in appSettings element across multiple projects in .NET.</title><content type='html'>When you are developing multiple .NET projects and want to share common custom configuration settings specified in the &lt;appsettings&gt;&lt;br /&gt;
element, for this you can create a common setting file for your all .NET projects. &lt;br /&gt;
In web.config file in &lt;appsettings&gt; you can use file attribute like this.&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;appsettings file=&quot;settings.config&quot;&gt;
  &lt;/appSettings&gt;
  &lt;/pre&gt;&lt;b&gt; Code&lt;br /&gt;
Web.config file&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;?xml version=&quot;1.0&quot;?&gt;
 
&lt;configuration&gt;

  &lt;appsettings file=&quot;settings.config&quot;&gt;
  &lt;/appSettings&gt;
    &lt;connectionStrings/&gt;
    &lt;system.web&gt;

    &lt;/system.web&gt;
&lt;/configuration&gt;
&lt;/pre&gt;&lt;b&gt;settings.config file&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;appsettings&gt;
  &lt;add key=&quot;sitebaseURL&quot; value=&quot;http://www.abcde.com&quot;/&gt;
  &lt;add key=&quot;imageURL&quot; value=&quot;http://www.abc.com/images/search/&quot;/&gt;
   &lt;add key=&quot;fromEmailId&quot; value=&quot;test12@testy.com&quot;/&gt;
 &lt;/appSettings&gt;
 &lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/9189218255783374952/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/12/sharing-settings-specified-in-element.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/9189218255783374952'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/9189218255783374952'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/12/sharing-settings-specified-in-element.html' title='Sharing settings specified in appSettings element across multiple projects in .NET.'/><author><name>Unknown</name><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-4054512041533578749.post-6088793288937372729</id><published>2010-11-24T12:39:00.003+05:30</published><updated>2011-01-14T10:30:59.714+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Accessing Master Page User Control (ascx) event and value in content page.</title><content type='html'>Sometimes a situation comes wherein you want to do some action on any event fired by master page user control in to a content page.&lt;br /&gt;
We can do this by the help of &quot;Delegates&quot;.&lt;br /&gt;
&lt;br /&gt;
The situation is I have a user control with a dropdown in header.ascx file, which I have integrated in my masterpage.master.&lt;br /&gt;
Now I want to access the event of that dropdownbox (SelectedIndexChanged ) in my content page default2.aspx and the value of the drop down box.&lt;/p&gt;&lt;p&gt;&lt;strong&gt; How to do that ?&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;1. Create a Delegate and event Handler in your usercontrol.ascx.&lt;br /&gt;
      &lt;br /&gt;
&lt;span class=&quot;style2&quot;&gt;//Creating delegate for dropdownlist      &lt;/span&gt;&lt;br /&gt;
public delegate void OnSelectedIndex(object sender, EventArgs e);&lt;br /&gt;
      &lt;br /&gt;
public event OnSelectedIndex ddl_selectedIndexChanged;    &lt;/p&gt;&lt;p&gt;2. Create a Delegate and Eventhandler in your Master page, which we will access in Content Page. &lt;br /&gt;
&lt;span class=&quot;style2&quot;&gt;//Creating Delegates and Event handler &lt;/span&gt;&lt;br /&gt;
public delegate void MasterDropDown(object sender, EventArgs e); &lt;br /&gt;
public event MasterDropDown Header_DropDown; &lt;/p&gt;&lt;br /&gt;
3. Now access the same on content page&lt;br /&gt;
      For this first call the master page like &lt;br /&gt;
&amp;lt;%@ MasterType VirtualPath=&amp;quot;~/MasterPage.master&amp;quot;%&amp;gt;&lt;br /&gt;
&lt;span class=&quot;style2&quot;&gt;//And then  in your content page load method &lt;/span&gt;&lt;br /&gt;
protected void Page_Load(object sender, EventArgs e)&lt;br /&gt;
{&lt;br /&gt;
Master.Header_DropDown += new MasterPage.MasterDropDown(Master_Header_DropDown);&lt;br /&gt;
} &lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;&lt;b&gt;For Accessing the value&lt;/b&gt;&lt;/p&gt;1. Define a property in ascx control&lt;br /&gt;
    &lt;br /&gt;
&lt;span class=&quot;style1&quot;&gt;//Geting the Drop Down Value    &lt;/span&gt;&lt;br /&gt;
public string DropDownValue&lt;br /&gt;
    {&lt;br /&gt;
    get { return DropDownList1.SelectedValue; }&lt;br /&gt;
  }&lt;br /&gt;
2.  Access the value in master page&lt;br /&gt;
    &lt;br /&gt;
&lt;span class=&quot;style2&quot;&gt;//Geting the User Control value&lt;/span&gt;&lt;br /&gt;
public string UserControlValue &lt;br /&gt;
    {&lt;br /&gt;
    get { return uc_usercontrol1.DropDownValue; }&lt;br /&gt;
  } &lt;br /&gt;
3. Now access the value in Content page in a lable&lt;br /&gt;
    &lt;br /&gt;
Label1.Text =Label1.Text+&quot; &quot;+ Master.UserControlValue; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;p&gt;&lt;b&gt;    Complete Code&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;User Control&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;b&gt;uc_usercontrol.ascx&lt;/b&gt;
&amp;lt;%@ Control Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;uc_usercontrol.ascx.cs&amp;quot;
Inherits=&amp;quot;uc_Usercontrols&amp;quot; %&amp;gt;
&amp;lt;asp:DropDownList ID=&amp;quot;DropDownList1&amp;quot; runat=&amp;quot;server&amp;quot; AutoPostBack=&amp;quot;True&amp;quot; 
onselectedindexchanged=&amp;quot;DropDownList1_SelectedIndexChanged&amp;quot;&amp;gt;
&amp;lt;asp:ListItem&amp;gt;1&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;asp:ListItem&amp;gt;2&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;asp:ListItem&amp;gt;3&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;asp:ListItem&amp;gt;4&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;asp:ListItem&amp;gt;5&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;asp:ListItem&amp;gt;6&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;asp:ListItem&amp;gt;&amp;lt;/asp:ListItem&amp;gt;
&amp;lt;/asp:DropDownList&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;uc_usercontrol.ascx&lt;/b&gt;.&lt;strong&gt;cs&lt;/strong&gt;
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Collections.Specialized;
public partial class uc_Usercontrols : System.Web.UI.UserControl
{
//Geting the Drop Down Value
public string DropDownValue
{
get { return DropDownList1.SelectedValue; }
}
&lt;/p&gt;&lt;p&gt;&lt;span class=&quot;style2&quot;&gt;//Creating delegate for dropdownlist&lt;/span&gt;
public delegate void OnSelectedIndex(object sender, EventArgs e);
public event OnSelectedIndex ddl_selectedIndexChanged;
protected void Page_Load(object sender, EventArgs e)
{
}&lt;/p&gt;&lt;p&gt;protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.ddl_selectedIndexChanged(sender, e);&lt;/p&gt;&lt;p&gt;}
}
&lt;/p&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Master Page  &lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&lt;strong&gt;MasterPage.master&lt;/strong&gt;
&amp;lt;%@ Master Language=&amp;quot;C#&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;MasterPage.master.cs&amp;quot; Inherits=&amp;quot;MasterPage&amp;quot; %&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;%@ Register Src=&amp;quot;uc_usercontrol.ascx&amp;quot; TagName=&amp;quot;uc_usercontrol&amp;quot; TagPrefix=&amp;quot;uc1&amp;quot; %&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&amp;gt;
&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&amp;gt;
&amp;lt;head runat=&amp;quot;server&amp;quot;&amp;gt;
&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
&amp;lt;asp:ContentPlaceHolder ID=&amp;quot;head&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&amp;lt;/asp:ContentPlaceHolder&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;form id=&amp;quot;form1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&amp;lt;div&amp;gt;
&amp;lt;uc1:uc_usercontrol ID=&amp;quot;uc_usercontrol1&amp;quot; runat=&amp;quot;server&amp;quot; /&amp;gt;
&amp;lt;asp:ContentPlaceHolder ID=&amp;quot;ContentPlaceHolder1&amp;quot; runat=&amp;quot;server&amp;quot;&amp;gt;
&amp;lt;/asp:ContentPlaceHolder&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;strong&gt;MasterPage.master&lt;/strong&gt;.&lt;strong&gt;cs&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;&lt;/p&gt;&lt;p&gt;public partial class MasterPage : System.Web.UI.MasterPage
{
//Geting the User Control value
public string UserControlValue 
{
get { return uc_usercontrol1.DropDownValue; }
}
//Creating Delegates and Event handler
public delegate void MasterDropDown(object sender, EventArgs e);
public event MasterDropDown Header_DropDown;

protected void Page_Load(object sender, EventArgs e)
{
this.uc_usercontrol1.ddl_selectedIndexChanged += new uc_Usercontrols.OnSelectedIndex(uc_usercontrol1_ddl_selectedIndexChanged);
}&lt;/p&gt;&lt;p&gt;void uc_usercontrol1_ddl_selectedIndexChanged(object sender, EventArgs e)
{
this.Header_DropDown(sender, e);

}
}
&lt;/p&gt;&lt;/pre&gt;&lt;pre class=&quot;brush: html&quot;&gt;&lt;p&gt;&lt;strong&gt;Default2.aspx&lt;/strong&gt;
&amp;lt;%@ Page Title=&amp;quot;&amp;quot; Language=&amp;quot;C#&amp;quot; MasterPageFile=&amp;quot;~/MasterPage.master&amp;quot; AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;Default2.aspx.cs&amp;quot; Inherits=&amp;quot;Default2&amp;quot; %&amp;gt;
&amp;lt;%@ MasterType VirtualPath=&amp;quot;~/MasterPage.master&amp;quot;%&amp;gt;

&amp;lt;asp:Content ID=&amp;quot;Content1&amp;quot; ContentPlaceHolderID=&amp;quot;head&amp;quot; Runat=&amp;quot;Server&amp;quot;&amp;gt;
&amp;lt;/asp:Content&amp;gt;
&amp;lt;asp:Content ID=&amp;quot;Content2&amp;quot; ContentPlaceHolderID=&amp;quot;ContentPlaceHolder1&amp;quot; Runat=&amp;quot;Server&amp;quot;&amp;gt;
&amp;lt;asp:Label ID=&amp;quot;Label1&amp;quot; runat=&amp;quot;server&amp;quot; Text=&amp;quot;Hi I m visible now&amp;quot; Visible=&amp;quot;false&amp;quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;
&amp;lt;/asp:Content&amp;gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Default2.aspx&lt;/strong&gt;.&lt;strong&gt;cs&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;&lt;/p&gt;&lt;p&gt;public partial class Default2 : System.Web.UI.Page
{&lt;/p&gt;&lt;p&gt;protected void Page_Load(object sender, EventArgs e)
{
Master.Header_DropDown += new MasterPage.MasterDropDown(Master_Header_DropDown);
}&lt;/p&gt;&lt;p&gt;void Master_Header_DropDown(object sender, EventArgs e)
{
//Here you can do any activity on change dropdown list
Label1.Visible = true; 
//Accessing the Master page User Control Value in content Page
Label1.Text =Label1.Text+&amp;quot; &amp;quot;+ Master.UserControlValue;
}
}
&lt;/p&gt;&lt;/pre&gt;&lt;p&gt;&lt;a href=&quot;http://www.box.net/shared/xuu5cpc1xt&quot; target=&quot;_blank&quot;&gt;Download Code&lt;/a&gt;  &lt;/p&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/6088793288937372729/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/11/accessing-master-page-user-control-ascx_7809.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6088793288937372729'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6088793288937372729'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/11/accessing-master-page-user-control-ascx_7809.html' title='Accessing Master Page User Control (ascx) event and value in content page.'/><author><name>Unknown</name><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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-3891820103742441480</id><published>2010-11-19T10:40:00.000+05:30</published><updated>2010-11-19T10:40:28.262+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Dynamic SQL Query</title><content type='html'>Dynamic Sql query means genrating sql query at run time according to need. Some times a situation comes where we have to genrate the dynamic query. Below is the example of a search condition in stored procedure, where I am genrating dynamic query, according to parameter passed in Stored Procedure.&lt;br /&gt;
It has demerits too. It will loose the performance boost, what we usually get in stored procedures and most importantly stored procedure can not cache the execution plan for this dynamic query.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Stored Procedure&lt;/strong&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;CREATE proc usp_Getsearchresult  
@countryid int,  
@cityid int,  
@categoryid int,  
@keywords varchar(255)  
as  
--TO HOLD THE QUERY
Declare @setQuery nvarchar(2200)      
--TO HOLD THE WHERE CONDITION VALUES
declare @whereTosearch nvarchar (2000)      
--TO HOLD THE CONDITION
declare @condition int      
set @setQuery=&#39;select * from product with (NOLOCK) where &#39;  
 --Condition for country ID  . WHERE COUNTRY ID IS MANDATORY IN CODE
  if (@countryid is not Null)      
 begin      
   set @condition=1      
   set @whereTosearch=&#39;countryId=&#39;+cast(@countryid as varchar(5))      
 --print &#39;1&#39;  
 end     
 -- Condition for city   
  if (@cityid is not Null and @condition&gt;0)      
 begin      
   set @condition=1      
   set @whereTosearch=@whereTosearch+&#39; and cityId=&#39;+ cast(@cityid as varchar(5))  
 --print &#39;2&#39;  
 end     
 --Condition if catetory is selected  
  if (@categoryid is not Null and @condition&gt;0)      
 begin      
   set @condition=1    
   set @setQuery=&#39;select product.*,product_category.product_category_type_id from product with (NOLOCK)  
   left  outer join product_category on  product.service_id=product_category.service_id where product_category.product_category_type_id is not null and &#39;  
   set @whereTosearch=@whereTosearch+&#39; and product_category.product_category_type_id=&#39;+cast(@categoryid as varchar(5))  
 --print &#39;3&#39;  
 end     
 -- Condition for Keywords   
  if (@keywords is not Null and @condition&gt;0)      
 begin      
   set @condition=1      
   set @whereTosearch=@whereTosearch+&#39; and (productname like &#39;&#39;%&#39;+@keywords+&#39;%&#39;&#39; or product_keyword like &#39;&#39;%&#39;+@keywords+&#39;%&#39;&#39;)&#39;  
 --print &#39;4&#39;  
 end   
  
set @setQuery=@setQuery+@whereTosearch      
--print @setQuery  
exec(@setQuery) 

&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/3891820103742441480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/11/dynamic-sql-query.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3891820103742441480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/3891820103742441480'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/11/dynamic-sql-query.html' title='Dynamic SQL Query'/><author><name>Unknown</name><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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-6577814688434574454</id><published>2010-11-03T11:19:00.000+05:30</published><updated>2010-11-03T11:19:24.038+05:30</updated><title type='text'>Hiding datagrid column at runtime in asp.net</title><content type='html'>Sometimes  you want to hide the column at runtime in datagrid. Below is the code. You can do this on RowCreated event of datagrid.&lt;br /&gt;
&lt;/br&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;protected void gvreport_RowCreated(object sender, GridViewRowEventArgs e)
    {
       

        if (username==&quot;Admin&quot;)// Your Condition for hiding the column
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[4].Visible = false;

            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                e.Row.Cells[4].Visible = false;
            }
        }
    }
&lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/6577814688434574454/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/11/hiding-datagrid-column-at-runtime-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6577814688434574454'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/6577814688434574454'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/11/hiding-datagrid-column-at-runtime-in.html' title='Hiding datagrid column at runtime in asp.net'/><author><name>Unknown</name><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-4054512041533578749.post-2737786894614224818</id><published>2010-10-30T17:58:00.000+05:30</published><updated>2010-10-30T17:58:40.086+05:30</updated><title type='text'>Formatted Dropdown List and Listbox control in ASP.NET</title><content type='html'>Formatted Dropdown List and Listbox control in ASP.NET&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://dotnetcodehelp.wordpress.com/2010/10/30/formatted-dropdown-list-and-listbox-control-in-asp-net/&quot;&gt;Code&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/2737786894614224818/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/10/formatted-dropdown-list-and-listbox.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/2737786894614224818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/2737786894614224818'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/10/formatted-dropdown-list-and-listbox.html' title='Formatted Dropdown List and Listbox control in ASP.NET'/><author><name>Unknown</name><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-4054512041533578749.post-7294628037944577928</id><published>2010-10-08T14:05:00.000+05:30</published><updated>2010-10-22T12:45:27.682+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="SQL"/><title type='text'>Some tricky SQL queries (Interview Questions)</title><content type='html'>&lt;b&gt;1.Select nth highest salary and name from emp table&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;SELECT DISTINCT (a.empsalary),a.Employee_Name FROM empData A WHERE  N =(SELECT COUNT (DISTINCT (b.empsalary)) FROM empData B WHERE a.empsalary&amp;lt;=b.empsalary);
--where N is your number (2nd or 5th)
e.g SELECT DISTINCT (a.empsalary),a.Employee_Name FROM empData A WHERE  5 =(SELECT COUNT (DISTINCT (b.empsalary)) FROM empData B WHERE a.empsalary&amp;lt;=b.empsalary);
&lt;/pre&gt;&lt;b&gt;&lt;br /&gt;
2.Select query without using &quot;Like&quot; operator . For eg select employee name start with &#39;j&#39; and city is &#39;Noida&#39; in company_name&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;select * from empdata where CHARINDEX(&#39;j&#39;,Employee_name)=1 and CHARINDEX(&#39;Noida&#39;,company_name)&amp;gt;0
&lt;/pre&gt;&lt;a href=&quot;http://dotnetcodehelp.files.wordpress.com/2010/10/withoutusinglike.jpg&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;alignleft size-medium wp-image-60&quot; height=&quot;300&quot; src=&quot;http://dotnetcodehelp.files.wordpress.com/2010/10/withoutusinglike.jpg?w=298&quot; title=&quot;withoutusingLike&quot; width=&quot;298&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://dotnetcodehelp.files.wordpress.com/2010/10/screensql.jpg&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
3.Select query for grouping 2 coulmns in one column using Case statement&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;select result=case when p1 is not null then p1 when p2 is not null then p2 end from tbltest&lt;/pre&gt;&lt;a href=&quot;http://dotnetcodehelp.files.wordpress.com/2010/10/screensql.jpg&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;alignleft size-medium wp-image-61&quot; height=&quot;242&quot; src=&quot;http://dotnetcodehelp.files.wordpress.com/2010/10/screensql.jpg?w=300&quot; title=&quot;screensql&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;&lt;br /&gt;
 &lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
4.Create identity like coulmn in query&lt;/b&gt;&lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;select row_number () over( order by p1) as sno, result=case when p1 is not null then p1 when p2 is not null then p2 end from tbltest

&lt;/pre&gt;&lt;a href=&quot;http://dotnetcodehelp.files.wordpress.com/2010/10/rownumber-in-query.jpg&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;alignleft size-medium wp-image-62&quot; height=&quot;225&quot; src=&quot;http://dotnetcodehelp.files.wordpress.com/2010/10/rownumber-in-query.jpg?w=300&quot; title=&quot;rownumber in query&quot; width=&quot;300&quot; /&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/7294628037944577928/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/10/some-tricky-sql-queries-interview.html#comment-form' title='38 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/7294628037944577928'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/7294628037944577928'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/10/some-tricky-sql-queries-interview.html' title='Some tricky SQL queries (Interview Questions)'/><author><name>Unknown</name><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>38</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-8803096107339630418</id><published>2010-09-30T17:48:00.000+05:30</published><updated>2010-10-20T12:13:20.113+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>ELMAH: Error Logging Modules and Handlers for ASP.NET</title><content type='html'>A very good open source project for handling and loging .net errors. It logs nearly all the unhandled errors. You can view full details of your error log using http://www.yoursite.com/elmah.axd . An e-mail notification of each error at the time it occurs. For Download and more information on &lt;a href=&quot;http://code.google.com/p/elmah/&quot; target=&quot;_blank&quot;&gt;ELMAH&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/qj8304nn26&quot; target=&quot;_blank&quot;&gt;&lt;br /&gt;
Download Sample Code &lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/8803096107339630418/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/elmah-error-logging-modules-and.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/8803096107339630418'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/8803096107339630418'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/elmah-error-logging-modules-and.html' title='ELMAH: Error Logging Modules and Handlers for ASP.NET'/><author><name>Unknown</name><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>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-270659149128080687</id><published>2010-09-28T12:56:00.000+05:30</published><updated>2010-10-22T12:38:10.163+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>A basic example of LINQ</title><content type='html'>LINQ stands for Language-Integrated Query.It return results of type: IEnumerable&amp;lt;T&amp;gt; where &amp;lt;T&amp;gt; is determined by the object type of the “select” clause.&lt;br /&gt;
&lt;br /&gt;
And asp.net controls support databinding to any IEnumerable collection so we can easily bind the datagrid,reapter,datalist and dropdownlist with Linq query. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;default.aspx&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&amp;lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&amp;gt;
&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;

&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&amp;gt;

&amp;lt;head runat=&quot;server&quot;&amp;gt;

&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;

&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;

&amp;lt;form id=&quot;form1&quot; runat=&quot;server&quot;&amp;gt;

&amp;lt;div&amp;gt;

&amp;lt;asp:GridView ID=&quot;grdCountryList&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; BackColor=&quot;LightGoldenrodYellow&quot;

BorderColor=&quot;Tan&quot; BorderWidth=&quot;1px&quot; CellPadding=&quot;2&quot; ForeColor=&quot;Black&quot;

GridLines=&quot;None&quot; AllowPaging=&quot;True&quot;&amp;gt;

&amp;lt;Columns&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryId&quot; HeaderText=&quot;CountryId&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryName&quot; HeaderText=&quot;Country Name&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryCode&quot; HeaderText=&quot;Country Code&quot; /&amp;gt;

&amp;lt;/Columns&amp;gt;

&amp;lt;FooterStyle BackColor=&quot;Tan&quot; /&amp;gt;

&amp;lt;PagerStyle BackColor=&quot;PaleGoldenrod&quot; ForeColor=&quot;DarkSlateBlue&quot; HorizontalAlign=&quot;Center&quot; /&amp;gt;

&amp;lt;SelectedRowStyle BackColor=&quot;DarkSlateBlue&quot; ForeColor=&quot;GhostWhite&quot; /&amp;gt;

&amp;lt;HeaderStyle BackColor=&quot;Tan&quot; Font-Bold=&quot;True&quot; /&amp;gt;

&amp;lt;AlternatingRowStyle BackColor=&quot;PaleGoldenrod&quot; /&amp;gt;

&amp;lt;/asp:GridView&amp;gt;

&amp;lt;br /&amp;gt;

Linq Where country code lenght is less than 3

&amp;lt;br /&amp;gt;

&amp;lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; BackColor=&quot;LightGoldenrodYellow&quot;

BorderColor=&quot;Tan&quot; BorderWidth=&quot;1px&quot; CellPadding=&quot;2&quot; ForeColor=&quot;Black&quot; GridLines=&quot;None&quot;&amp;gt;

&amp;lt;Columns&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryId&quot; HeaderText=&quot;CountryId&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryName&quot; HeaderText=&quot;Country Name&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryCode&quot; HeaderText=&quot;Country Code&quot; /&amp;gt;

&amp;lt;/Columns&amp;gt;

&amp;lt;FooterStyle BackColor=&quot;Tan&quot; /&amp;gt;

&amp;lt;PagerStyle BackColor=&quot;PaleGoldenrod&quot; ForeColor=&quot;DarkSlateBlue&quot; HorizontalAlign=&quot;Center&quot; /&amp;gt;

&amp;lt;SelectedRowStyle BackColor=&quot;DarkSlateBlue&quot; ForeColor=&quot;GhostWhite&quot; /&amp;gt;

&amp;lt;HeaderStyle BackColor=&quot;Tan&quot; Font-Bold=&quot;True&quot; /&amp;gt;

&amp;lt;AlternatingRowStyle BackColor=&quot;PaleGoldenrod&quot; /&amp;gt;

&amp;lt;/asp:GridView&amp;gt;

&amp;lt;br /&amp;gt;

Linq Where country id between 31 to 70

&amp;lt;br /&amp;gt;

&amp;lt;asp:GridView ID=&quot;GridView2&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; BackColor=&quot;LightGoldenrodYellow&quot;

BorderColor=&quot;Tan&quot; BorderWidth=&quot;1px&quot; CellPadding=&quot;2&quot; ForeColor=&quot;Black&quot; GridLines=&quot;None&quot;&amp;gt;

&amp;lt;Columns&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryId&quot; HeaderText=&quot;CountryId&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryName&quot; HeaderText=&quot;Country Name&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryCode&quot; HeaderText=&quot;Country Code&quot; /&amp;gt;

&amp;lt;/Columns&amp;gt;

&amp;lt;FooterStyle BackColor=&quot;Tan&quot; /&amp;gt;

&amp;lt;PagerStyle BackColor=&quot;PaleGoldenrod&quot; ForeColor=&quot;DarkSlateBlue&quot; HorizontalAlign=&quot;Center&quot; /&amp;gt;

&amp;lt;SelectedRowStyle BackColor=&quot;DarkSlateBlue&quot; ForeColor=&quot;GhostWhite&quot; /&amp;gt;

&amp;lt;HeaderStyle BackColor=&quot;Tan&quot; Font-Bold=&quot;True&quot; /&amp;gt;

&amp;lt;AlternatingRowStyle BackColor=&quot;PaleGoldenrod&quot; /&amp;gt;

&amp;lt;/asp:GridView&amp;gt;

&amp;lt;br /&amp;gt;

Linq Where country started from &quot;A&quot;

&amp;lt;br /&amp;gt;

&amp;lt;asp:GridView ID=&quot;GridView3&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; BackColor=&quot;LightGoldenrodYellow&quot;

BorderColor=&quot;Tan&quot; BorderWidth=&quot;1px&quot; CellPadding=&quot;2&quot; ForeColor=&quot;Black&quot; GridLines=&quot;None&quot;&amp;gt;

&amp;lt;Columns&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryId&quot; HeaderText=&quot;CountryId&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryName&quot; HeaderText=&quot;Country Name&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryCode&quot; HeaderText=&quot;Country Code&quot; /&amp;gt;

&amp;lt;/Columns&amp;gt;

&amp;lt;FooterStyle BackColor=&quot;Tan&quot; /&amp;gt;

&amp;lt;PagerStyle BackColor=&quot;PaleGoldenrod&quot; ForeColor=&quot;DarkSlateBlue&quot; HorizontalAlign=&quot;Center&quot; /&amp;gt;

&amp;lt;SelectedRowStyle BackColor=&quot;DarkSlateBlue&quot; ForeColor=&quot;GhostWhite&quot; /&amp;gt;

&amp;lt;HeaderStyle BackColor=&quot;Tan&quot; Font-Bold=&quot;True&quot; /&amp;gt;

&amp;lt;AlternatingRowStyle BackColor=&quot;PaleGoldenrod&quot; /&amp;gt;

&amp;lt;/asp:GridView&amp;gt;

&amp;lt;br /&amp;gt;

Linq Where country with like query

&amp;lt;br /&amp;gt;

&amp;lt;asp:GridView ID=&quot;GridView4&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot; BackColor=&quot;LightGoldenrodYellow&quot;

BorderColor=&quot;Tan&quot; BorderWidth=&quot;1px&quot; CellPadding=&quot;2&quot; ForeColor=&quot;Black&quot; GridLines=&quot;None&quot;&amp;gt;

&amp;lt;Columns&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryId&quot; HeaderText=&quot;CountryId&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryName&quot; HeaderText=&quot;Country Name&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;CountryCode&quot; HeaderText=&quot;Country Code&quot; /&amp;gt;

&amp;lt;/Columns&amp;gt;

&amp;lt;FooterStyle BackColor=&quot;Tan&quot; /&amp;gt;

&amp;lt;PagerStyle BackColor=&quot;PaleGoldenrod&quot; ForeColor=&quot;DarkSlateBlue&quot; HorizontalAlign=&quot;Center&quot; /&amp;gt;

&amp;lt;SelectedRowStyle BackColor=&quot;DarkSlateBlue&quot; ForeColor=&quot;GhostWhite&quot; /&amp;gt;

&amp;lt;HeaderStyle BackColor=&quot;Tan&quot; Font-Bold=&quot;True&quot; /&amp;gt;

&amp;lt;AlternatingRowStyle BackColor=&quot;PaleGoldenrod&quot; /&amp;gt;

&amp;lt;/asp:GridView&amp;gt;

&amp;lt;/div&amp;gt;

&amp;lt;/form&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt; 
&lt;/pre&gt;&lt;b&gt;default.aspx.cs&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

BindGrid();

}

}

#region BIND GRID

private void BindGrid()

{

List&amp;lt;CountryEntity&amp;gt; countryList = new List&amp;lt;CountryEntity&amp;gt;();

CountryPersistence objCountry = new CountryPersistence();

countryList = objCountry.GetCountryList();

&lt;span style=&quot;color: green;&quot;&gt;//Simple binding of grid using LIST &lt;/span&gt;

grdCountryList.DataSource = countryList;

grdCountryList.DataBind();

&lt;span style=&quot;color: green;&quot;&gt; //Now we will start Linq. It will fetch all the data where country code length is less than 3&lt;/span&gt;

GridView1.DataSource = from country in countryList where country.CountryCode.Length &amp;lt; 3 orderby country.CountryName select country;

GridView1.DataBind();

&lt;span style=&quot;color: green;&quot;&gt; //Where country ID between 31 to 70&lt;/span&gt;

GridView2.DataSource = from country in countryList where (country.CountryId &amp;gt;= 31 &amp;amp;&amp;amp; country.CountryId &amp;lt;= 70) orderby country.CountryId select country;

GridView2.DataBind();

&lt;span style=&quot;color: green;&quot;&gt;//Where country name Starts with &quot;A&quot;&lt;/span&gt;

GridView3.DataSource = from country in countryList where country.CountryName.StartsWith(&quot;A&quot;) select country;

GridView3.DataBind();

&lt;span style=&quot;color: green;&quot;&gt; //Where country name with like query&lt;/span&gt;

GridView4.DataSource = from country in countryList where country.CountryName.Contains(&#39;z&#39;) orderby country.CountryName descending select country;

GridView4.DataBind();

}

#endregion

} 
&lt;/pre&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/5avo9kjm2q&quot; target=&quot;_blank&quot;&gt;Download Code &lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/270659149128080687/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/basic-example-of-linq.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/270659149128080687'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/270659149128080687'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/basic-example-of-linq.html' title='A basic example of LINQ'/><author><name>Unknown</name><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-4054512041533578749.post-4503472038538068912</id><published>2010-09-25T12:43:00.000+05:30</published><updated>2010-10-22T12:39:05.940+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Import Excel Sheet data in SQL server</title><content type='html'>Upload Excel file data to SQL server using SqlBulkCopy. A new feature in ADO.NET 2.0 . In this example we will import the Excel Sheet data in to SQL server. &lt;br /&gt;
Following are the connection strings for different version of Excel sheet. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;FOR xls files:&lt;/b&gt; Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[FilePath];Extended Properties=”Excel 8.0;HDR=YES;IMEX=1 &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;FOR xlsx files&lt;/b&gt;:  Provider=Microsoft.ACE.OLEDB.12.0;Data Source=[FilePath];Extended Properties=Excel 12.0 Xml;HDR=YES;IMEX=1 &lt;br /&gt;
&lt;br /&gt;
Where &lt;b&gt;HDR=YES&lt;/b&gt; specifies first row of column is header column and&lt;br /&gt;
&lt;b&gt;IMEX=1&lt;/b&gt; specifies that the driver should always read the “intermixed”&lt;br /&gt;
data columns as text &lt;br /&gt;
&lt;br /&gt;
By SqlBulkCopy you can upload complete excel sheet data in a single instance, quick and easy. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Files&lt;/b&gt; &lt;br /&gt;
&lt;b&gt;Default.aspx&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&amp;lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&amp;gt;

&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;

&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&amp;gt;

&amp;lt;head runat=&quot;server&quot;&amp;gt;

&amp;lt;title&amp;gt;Excel File Uploading Demo&amp;lt;/title&amp;gt;

&amp;lt;style type=&quot;text/css&quot;&amp;gt;

.style1

{

font-family: Verdana, Arial, Helvetica, sans-serif;

font-size: 12px;

}

&amp;lt;/style&amp;gt;

&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;

&amp;lt;form id=&quot;form1&quot; runat=&quot;server&quot;&amp;gt;

&amp;lt;div&amp;gt;

&amp;lt;table width=&quot;52%&quot; border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;2&quot; class=&quot;style1&quot; style=&quot;border: #666666 1px solid&quot;&amp;gt;

&amp;lt;tr&amp;gt;

&amp;lt;td width=&quot;24%&quot; nowrap=&quot;nowrap&quot;&amp;gt;

&amp;lt;strong&amp;gt;Excel Upload Example&amp;lt;/strong&amp;gt;

&amp;lt;/td&amp;gt;

&amp;lt;td width=&quot;76%&quot; nowrap=&quot;nowrap&quot;&amp;gt;

&amp;amp;nbsp;

&amp;lt;/td&amp;gt;

&amp;lt;/tr&amp;gt;

&amp;lt;tr&amp;gt;

&amp;lt;td nowrap=&quot;nowrap&quot;&amp;gt;

&amp;lt;strong&amp;gt;Select your file &amp;lt;/strong&amp;gt;

&amp;lt;/td&amp;gt;

&amp;lt;td nowrap=&quot;nowrap&quot;&amp;gt;

&amp;amp;nbsp;

&amp;lt;asp:FileUpload ID=&quot;FileUpload1&quot; runat=&quot;server&quot; CssClass=&quot;style1&quot; /&amp;gt;

&amp;amp;nbsp;&amp;lt;asp:RequiredFieldValidator ID=&quot;RequiredFieldValidator1&quot; runat=&quot;server&quot; ControlToValidate=&quot;FileUpload1&quot;

CssClass=&quot;style1&quot; Display=&quot;Dynamic&quot; ErrorMessage=&quot;Please select your file.&quot;&amp;gt;&amp;lt;/asp:RequiredFieldValidator&amp;gt;

&amp;lt;/td&amp;gt;

&amp;lt;/tr&amp;gt;

&amp;lt;tr&amp;gt;

&amp;lt;td nowrap=&quot;nowrap&quot;&amp;gt;

&amp;amp;nbsp;

&amp;lt;/td&amp;gt;

&amp;lt;td nowrap=&quot;nowrap&quot;&amp;gt;

&amp;amp;nbsp;

&amp;lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; CssClass=&quot;style1&quot; OnClick=&quot;Button1_Click&quot;

Text=&quot;Upload Data&quot; /&amp;gt;

&amp;lt;br /&amp;gt;

&amp;lt;/td&amp;gt;

&amp;lt;/tr&amp;gt;

&amp;lt;tr&amp;gt;

&amp;lt;td nowrap=&quot;nowrap&quot;&amp;gt;

&amp;amp;nbsp;

&amp;lt;/td&amp;gt;

&amp;lt;td nowrap=&quot;nowrap&quot;&amp;gt;

&amp;amp;nbsp;

&amp;lt;asp:Label ID=&quot;lblMsg&quot; runat=&quot;server&quot; Font-Bold=&quot;True&quot;&amp;gt;&amp;lt;/asp:Label&amp;gt;

&amp;lt;/td&amp;gt;

&amp;lt;/tr&amp;gt;

&amp;lt;/table&amp;gt;

&amp;lt;/div&amp;gt;

&amp;lt;/form&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt; 
&lt;/pre&gt;&lt;b&gt;Default.aspx.cs&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.IO;

using System.Data.OleDb;

using System.Data.Common;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

string excelConnectionString = string.Empty;

protected void Page_Load(object sender, EventArgs e)

{

}

protected void Button1_Click(object sender, EventArgs e)

{

UploadExclData();

}

#region UPLOAD DATA  TO SQL SERVER

private void UploadExclData()

{

try

{

&lt;span style=&quot;color: olive;&quot;&gt; //First we will upload the file to our hard drive&lt;/span&gt;

//Now check if control has file

if (FileUpload1.HasFile)

{

&lt;span style=&quot;color: olive;&quot;&gt; ///execlData folder must have read and write permission&lt;/span&gt;

string excelFile = FileUploadToServer.UploadFile(FileUpload1, Server.MapPath(&quot;~/execlData/&quot;));

&lt;span style=&quot;color: olive;&quot;&gt; //Now Create the Connection to excel File&lt;/span&gt;

////CONNECTION STRING FOR DIFFRENT EXCEL VERSIONS

&lt;span style=&quot;color: olive;&quot;&gt; //FOR xls Provider=Microsoft.Jet.OLEDB.4.0;Data Source=[FilePath];Extended Properties=”Excel 8.0;HDR=YES;IMEX=1”&lt;/span&gt;

//FOR xlsx Provider=Microsoft.ACE.OLEDB.12.0;Data Source=[FilePath];Extended Properties=Excel 12.0 Xml;HDR=YES;IMEX=1

&lt;span style=&quot;color: olive;&quot;&gt; //HDR=Yes specifies that the first row of the data contains column names and not data.&lt;/span&gt;

//If you don’t want the first row to be skipped, change this to No.

//IMEX=1  specifies that the driver should always read the “intermixed” data columns as text.

&lt;span style=&quot;color: olive;&quot;&gt; //Create connection string to Excel work book&lt;/span&gt;

excelConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; + Server.MapPath(&quot;~/execlData/&quot; + excelFile) + &quot;;Extended Properties=&#39;Excel 8.0;HDR=YES;IMEX=1&#39;&quot;;

OleDbConnection exclConnection = new OleDbConnection(excelConnectionString);

&lt;span style=&quot;color: olive;&quot;&gt; //NOW FETCH DATA FROM EXCEL SHEET USING OLEDB &lt;/span&gt;

OleDbCommand exclCmd = new OleDbCommand(&quot;select * from [Sheet1$]&quot;, exclConnection);

exclConnection.Open();

OleDbDataReader exclReader = exclCmd.ExecuteReader();

&lt;span style=&quot;color: olive;&quot;&gt; //NOW CONNECT THE DESTINATION DATABASE CONNECTION AND TABLE NAME&lt;/span&gt;

SqlBulkCopy sqlBulk = new SqlBulkCopy(SqlHelper.mainConnectionString);

sqlBulk.DestinationTableName = &quot;empData&quot;;

&lt;span style=&quot;color: olive;&quot;&gt; //NOW MAP THE DESTINATION AND SOURCE TABLE COLUMN MAPPING&lt;/span&gt;

sqlBulk.ColumnMappings.Add(&quot;company_name&quot;, &quot;company_name&quot;);

sqlBulk.ColumnMappings.Add(&quot;Employee_Name&quot;, &quot;Employee_Name&quot;);

sqlBulk.ColumnMappings.Add(&quot;Emp_Code&quot;, &quot;Emp_Code&quot;);

sqlBulk.ColumnMappings.Add(&quot;Date_Of_Joining&quot;, &quot;Date_Of_Joining&quot;);

&lt;span style=&quot;color: olive;&quot;&gt; //WRITE THE DATA TO TABLE&lt;/span&gt;

sqlBulk.WriteToServer(exclReader);

lblMsg.Text = &quot;Your data uploaded successfuly.&quot;;

}

}

catch (Exception ex)

{

throw (ex);

}

}

#endregion

} 
&lt;/pre&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/vq1ottxr5m&quot; target=&quot;_blank&quot;&gt;Download Code Files&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/4503472038538068912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/import-excel-sheet-data-in-sql-server.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/4503472038538068912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/4503472038538068912'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/import-excel-sheet-data-in-sql-server.html' title='Import Excel Sheet data in SQL server'/><author><name>Unknown</name><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>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4054512041533578749.post-495499926744371859</id><published>2010-09-15T22:28:00.000+05:30</published><updated>2010-10-16T10:11:53.019+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Extension Method in ASP.NET</title><content type='html'>Extension method is new to C#. It  allow   you to add new method to the existing class.&lt;br/&gt;Extension method are   special kind of static method but they are called using instance method   syntax.&lt;br/&gt;The first parameter specify which type the method operate on,   and the parameter is precede by &quot;this&quot; modifier.&lt;br/&gt;&lt;br/&gt;&lt;a href=&quot;http://www.box.net/shared/15bqxe4eoc&quot; target=&quot;_blank&quot;&gt;Download Code&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/495499926744371859/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/extension-method-in-aspnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/495499926744371859'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/495499926744371859'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/extension-method-in-aspnet.html' title='Extension Method in ASP.NET'/><author><name>Unknown</name><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-4054512041533578749.post-779799650116280434</id><published>2010-09-14T11:10:00.000+05:30</published><updated>2014-02-05T13:36:42.100+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET"/><title type='text'>Creating PDF with ASP.NET on fly</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Last day I have given a situation where I have to create an HTML Invoice from database and send it through  email with PDF of invoice as attachment. I found a very interesting and easy solution for this &lt;a href=&quot;http://www.itextpdf.com/&quot; target=&quot;_blank&quot;&gt;iTextPDF.&lt;/a&gt; A pdf library for creating pdf documents in c#.&lt;br /&gt;
In this example we will export &amp;nbsp;grid data in PDF format and send the same by mail as PDF attachment.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;default.aspx&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;&amp;lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot;  CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&amp;gt;

&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&amp;gt;

&amp;lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&amp;gt;

&amp;lt;head runat=&quot;server&quot;&amp;gt;

&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;

&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;

&amp;lt;form id=&quot;form1&quot; runat=&quot;server&quot;&amp;gt;

&amp;lt;div&amp;gt;

&amp;lt;asp:Button ID=&quot;Button1&quot; runat=&quot;server&quot; onclick=&quot;Button1_Click&quot;

Text=&quot;Export To PDF&quot; /&amp;gt;

&amp;lt;asp:GridView ID=&quot;GridView1&quot; runat=&quot;server&quot; AutoGenerateColumns=&quot;False&quot;

BackColor=&quot;LightGoldenrodYellow&quot; BorderColor=&quot;Tan&quot; BorderWidth=&quot;1px&quot;

CellPadding=&quot;2&quot; ForeColor=&quot;Black&quot; GridLines=&quot;None&quot;&amp;gt;

&amp;lt;Columns&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;country_id&quot; HeaderText=&quot;Country ID&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;country_code&quot; HeaderText=&quot;Country Code&quot; /&amp;gt;

&amp;lt;asp:BoundField DataField=&quot;country_name&quot; HeaderText=&quot;Country Name&quot; /&amp;gt;

&amp;lt;/Columns&amp;gt;

&amp;lt;FooterStyle BackColor=&quot;Tan&quot; /&amp;gt;

&amp;lt;PagerStyle BackColor=&quot;PaleGoldenrod&quot; ForeColor=&quot;DarkSlateBlue&quot;

HorizontalAlign=&quot;Center&quot; /&amp;gt;

&amp;lt;SelectedRowStyle BackColor=&quot;DarkSlateBlue&quot; ForeColor=&quot;GhostWhite&quot; /&amp;gt;

&amp;lt;HeaderStyle BackColor=&quot;Tan&quot; Font-Bold=&quot;True&quot; /&amp;gt;

&amp;lt;AlternatingRowStyle BackColor=&quot;PaleGoldenrod&quot; /&amp;gt;

&amp;lt;/asp:GridView&amp;gt;

&amp;lt;/div&amp;gt;

&amp;lt;/form&amp;gt;

&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt; 
&lt;/pre&gt;
&lt;b&gt;default.aspx.cs&lt;/b&gt; &lt;br /&gt;
&lt;pre class=&quot;brush: html&quot;&gt;using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Data.SqlClient;

using System.Text;

using iTextSharp.text;

using iTextSharp.text.pdf;

using iTextSharp.text.html;

using iTextSharp.text.html.simpleparser;

using System.IO;

using System.Collections;

public partial class _Default : System.Web.UI.Page

{

#region BIND GRID

private void BindGrid()

{

&lt;span class=&quot;style1&quot;&gt;//GETING DATA FROM SQL SERVER&lt;/span&gt;

string sql = &quot;select country_id,country_code,country_name from country order by country_name&quot;;

GridView1.DataSource = SqlHelper.GetDataSet(SqlHelper.mainConnectionString, CommandType.Text, sql, null);

GridView1.DataBind();

}

#endregion

#region EVENTS

protected void Button1_Click(object sender, EventArgs e)

{

WritePdf();

}

public override void VerifyRenderingInServerForm(Control control)

{

//don&#39;t throw any exception!

}

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack) { BindGrid(); }

}

#endregion

#region WRITE PDF

private void WritePdf()

{

StringBuilder _strRepeater = new StringBuilder();

Html32TextWriter _ObjHtm = new Html32TextWriter(new System.IO.StringWriter(_strRepeater));

GridView1.RenderControl(_ObjHtm);

string _str = _strRepeater.ToString();

&lt;span class=&quot;style1&quot;&gt;//CREATE A UNIQUE NUMBER FOR PDF FILE NAMING USING DATE TIME STAMP&lt;/span&gt;

string filename = string.Format(&quot;{0:d7}&quot;, (DateTime.Now.Ticks / 10) % 10000000);

&lt;span class=&quot;style1&quot;&gt;//CREATE DOCUMENT&lt;/span&gt;

Document document = new Document(new Rectangle(500f, 700f));

//SAVE DOCUMENT. CHECK IF YOU HAVE WRITE PERMISSION OR NOT

PdfWriter.GetInstance(document, new FileStream(Server.MapPath(&quot;~/pdfs/&quot; + filename + &quot;.pdf&quot;), FileMode.Create));

document.Open();

List&amp;lt;IElement&amp;gt; htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(_str), null);

//add the collection to the document

for (int k = 0; k &amp;lt; htmlarraylist.Count; k++)

{

document.Add((IElement)htmlarraylist[k]);

}

document.Close();

&lt;span class=&quot;style1&quot;&gt;//NOW SEND EMAIL TO USER WITH ATTACHMENT&lt;/span&gt;

string msg = &quot;Hi this is test message&quot;;

email.SendMailAsHTML(&quot;Mail With PDF&quot;, &quot;test@test.com&quot;, &quot;abc@test.com&quot;, msg, Server.MapPath(&quot;~/pdfs/&quot; + filename + &quot;.pdf&quot;).ToString());

}

#endregion

} &lt;/pre&gt;
&lt;div class=&quot;brush: html&quot;&gt;
I have used this code in one of my online shopping cart, Manmeet Singh CEO of    &lt;a href=&quot;http://yoginetindia.com/&quot; target=&quot;_blank&quot;&gt;Yoginet Web solutions&lt;/a&gt; offering &lt;a href=&quot;http://yoginetindia.com/web-design.html&quot; target=&quot;_blank&quot;&gt;web designing&lt;/a&gt; , &lt;a href=&quot;http://yoginetindia.com/web-development.html&quot; target=&quot;_blank&quot;&gt;web development&lt;/a&gt; and &lt;a href=&quot;http://yoginetindia.com/seo.html&quot; target=&quot;_blank&quot;&gt;SEO services &lt;/a&gt;for Individuals , small businesses and Corporates. Specialized in developing websites using  latest HTML5 and designing Responsive websites.For more information about web solution  please &lt;a href=&quot;http://yoginetindia.com/enquiry.html&quot; target=&quot;_blank&quot;&gt;click here&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;a href=&quot;http://www.box.net/shared/kxq3jqsfam&quot; target=&quot;_blank&quot;&gt;Download Code&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://dotnetcodeshelp.blogspot.com/feeds/779799650116280434/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/creating-pdf-with-aspnet-on-fly.html#comment-form' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/779799650116280434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4054512041533578749/posts/default/779799650116280434'/><link rel='alternate' type='text/html' href='http://dotnetcodeshelp.blogspot.com/2010/09/creating-pdf-with-aspnet-on-fly.html' title='Creating PDF with ASP.NET on fly'/><author><name>Unknown</name><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>11</thr:total></entry></feed>