Archive for the ‘Javascript’ Category

Creating MAC OS X Lion Login and Desktop using Css3

This post is taken from http://www.alessioatzeni.com/blog/mac-os-x-lion-with-css3/

Alessio Atzeni wanted to create with only use of CSS3 the boot, the login page and finally the desktop of the Mac OS X Lion.

This is the first release and as you will see not everything is fully functional and at least as regards the desktop. In the next release Alessio Atzeni will implement new icons and new features while we examine what we have today.
Boot

This is simply the Mac OS X Lion boot. This section is simply composed by a CSS3 keyframes animation.
It has a logo (created in Photoshop) and a simple loader (fake loading). After the animation, dissolves the section to show the login section.

mac-boot
Login

This section mainly consists of a clock, two images (logos and avatars user name), two backgrounds and a password input field.
Alessio Atzeni used javascript only for the clock, create a fake login and when the password is valid Alessio Atzeni added some class to fix the desktop section and remove permanently the section login animation.

Thanks to the :target pseudo-class can be passed from one section to another. Regarding the rest is all CSS 3, such as hide/show the input field when you click on the avatar, same goes for the appearance of the tooltip when you click on the input field.

The animation of password error is connected via javascript but the animation is created using CSS3. The pseudo-class target has its limits and then to fix those small weaknesses, once you enter your password, javascript sets the desktop as the main section.

mac-login
Desktop

Finally here we have in our desktop. As mentioned previously this is only the first version, and consequently still missing several features that Alessio Atzeni will implement in the next release. Alessio Atzeni use javascript only for the clock and the jQuery UI Draggable library to have a draggable windows.

For the rest is all CSS3 excluding the background image and icons.

mac-dock
About this Project

Here Alessio Atzeni will list what he used for this project.
Modern Browser Supported

To see this experiment you will need a browser that supports CSS3 Keyframes Animations, so the choice is Firefox, Safari, or Chrome.
HTML5 and CSS3

For this project he used HTML5 and the unique capacity of CSS3.
Javascript

The use of JavaScript is for the clock, and to add a fix to the section desktop once you get the validation.
Draggable Window

Alessio Atzeni used this library jQuery UI Draggable.
Images and other decoration

Finally he used images for logos, user-avatar, spinner loading, cursors, background images, icons and window buttons.
Conclusion and Next Release

At the end of this experiment he realized the potential and limitations of CSS3, but thanks to the use of javascript (although to a limited) you can really get something unique.

Regarding the next release he plan to add the dock, delete and appears the windows if you click on a link on the menu only through the use of CSS. Optimize the code for better performance.

Alessio Atzeni hope that this experiment can be useful, and please you in your study, if you have any questions please do not hesitate to write.

Thank you all for your support.

Advertisements

Designing a vimeo player for website

Coding a vimeo Player is not a hard task but maitaining its skin and style is a very deficult task. any one can design a small vimeo player just by coding some of the lines like the lines given below and the vimeo player is ready for you.

Note :- Please replace &lt; by < and &gt; by > before making it as your player. the code is as follows.

&lt;div style=”width:504px; height:412px; overflow:hidden;”&gt;
&lt;object&gt;
&lt;param name=”allowfullscreen” value=”true” /&gt;&lt;param name=”wmode” value=”opaque” /&gt;
&lt;param name=”allowscriptaccess” value=”always” /&gt;
&lt;param name=”movie” value=”http://vimeo.com/moogaloop.swf?clip_id=2285902&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1&#8243; /&gt;
&lt;embed src=”http://vimeo.com/moogaloop.swf?clip_id=2285902&amp;amp;server=vimeo.com&amp;amp;show_title=0&amp;amp;show_byline=0&amp;amp;show_portrait=0&amp;amp;color=00ADEF&amp;amp;fullscreen=1&#8243; type=”application/x-shockwave-flash” allowfullscreen=”true” wmode=”opaque” allowscriptaccess=”always” width=”504″ height=”412″&gt;&lt;/embed&gt;
&lt;/object&gt;
&lt;/div&gt;

Now the vimeo player has been designed.

Best 25 Free Online Fax Services

It can be quite expensive to keep separate and dedicated Fax machines for different sections of big offices. Every department want privacy of data and want to shed the dependence on one particular fax machine.

But on the other hand, when many employees are at freedom of working from home and others are traveling continuously to every corner of world, keeping Fax machines at every place is next to impossible. Many of you don’t know that we can look up to online fax service in such a right spot.

Although most of these online fax services are not free to use but you can always opt for the trial version before actually buying the paid version. Today we have collected 25 Best Free Online Fax Services which will give you a whole bunch of happiness. You will no more be on the mercy of the Fax machine being kept on the reception area of your office. These Online Fax Services send Fax to you in form of emails so you can check the fax at your ease. Please have a look at below mentioned 25 Best Free Online Fax Services (Trial Versions) and make your life simple and better.

If you like this article, you might be interested in check the collection of website for Free Stock Photos,Make a Cartoon of Yourself, Finding a Perfect Domain Name, Download Free Fonts, Have Fun With Your Pics, Free Textures, and Getting Free Vector Art Images.

eFax

Send & receive faxes by email and you will also get a local fax number. You can check it with a 30 day trial offer.

eFax

More Information on eFax

K7

Its a web-based unified messaging system that channels your free voicemail and fax messages directly to your e-mail. K7 Unified Messaging provides you with a free phone number.

K7

More Information on K7

faxZERO

In its free version, you will have an Ad on the cover page,you can Fax 1 document — max 3 pages and Max 2 free faxes on per day basis

faxZERO

More Information on faxZERO

My1Voice

My1Voice is a virtual phoone. You can check a 30 day trial version and receive faxes from your my1voice number along with other features.

My1Voice

More Information on My1Voice

PamFax

With a trial version of PamFax, you can send some faxes for free. Iit supports many file formats in addition to PDF and DOC files.

PamFax

More Information on PamFax

ScanR

It’s a digital scanner and fax in your pocket! Your phone is suddenly a business center – scan, print and fax wherever you go. Scan documents to turn them into digital files you can store, share, and fax.

ScanR

More Information on ScanR

freefax

freefax

More Information on freefax

Interpage

This is a free service offered by Interpage to demonstrate and promote our fast, robust, and reliable email-to-fax and other fax delivery services. Using this service, you may send a fax for free to any US/Canada-based fax machine, for delivery to the destination fax which you specify

Interpage

More Information on Interpage

MaxEmail

Send & Receive Faxes Without Buying a Fax Machine or an Expensive Dedicated Phone Line

MaxEmail

More Information on MaxEmail

RapidFAX

RapidFAX combines the utility of fax with the ease of email to meet the needs of the small office and home office.

RapidFAX

More Information on RapidFAX

smartfax

Send fax from email to any fax number. Merge the convenience of email with fax.

smartfax

More Information on smartfax

TrustFax

With Trustfax, no Fax Machine or Phone Line Required and you get a Toll-Free and Local Fax Number.

TrustFax

More Information on TrustFax

VIF Internet

ervice limited to sending free faxes to the city of Montreal, Canada.

VIF Inter

More Information on VIF Internet

Metro Fax

With metro fax you can send high quality faxes from anywhere in the world using your web browser, no need for a fax machine, to a wide range of locations.

Metro Fax

More Information on Metro Fax

PopFax

You will get an account to send and receive fax, with a local fax number you can choose from over 500 cities in 20 countries. What more you can even go for a mobile fax service.

PopFax

More Information on PopFax

FaxFreedom

Fax machines are expensive and take up too much room. With FaxFreedom you can now simply send and receive faxes from any computer.

FaxFreedom

More Information on FaxFreedom

nextiva

With Nextiva vFAX all you need is an Internet connection in order to send and receive faxes. Our online fax service is easy to use, affordable and gives you great flexibility.

nextiva

More Information on nextiva

MyFax

MyFax is a fax service that lets you send and receive faxes through your email, the web, or smart phone.

MyFax

More Information on MyFax

Wonderfax

WonderFax is a free UK fax number that pick up your fax, converts them to a pdf file and emails it back to you as an attachment. So there is no need for fax lines or fax machines.

Wonderfax

More Information on Wonderfax

FaxOrama

FaxOrama supports multiple document formats like DOC, DOCX, RTF, GIF, JPG, JPEG, PDF, TIF, XLS, XLSX, TXT, PNG, BMP and WPS. You can also opt for a restricted sending option but an ad free free version.

FaxOrama

More Information on FaxOrama

Superfax

You can get a Fax Number in Paris, Los Angles or London for Free for a week. And See how it works.

Superfax

More Information on Superfax

MESSAGENET

It gives you 90 days trial period to check the service. You can both receive as well as send fax free till this time

MESSAGENET

More Information on MESSAGENET

GotFreeFax

It lets user send free fax online to the US and Canada without ads

GotFreeFax

More Information on GotFreeFax

that’s it.

Top 10 online Fax Services

A fax (short for facsimile) is a document sent over a telephone line. Although businesses usually maintain some kind of fax capability, the technology has faced increasing competition from Internet-based alternatives. However, fax machines still retain some advantages, particularly in the transmission of sensitive material which, if sent over the Internet unencrypted, may be vulnerable to interception. In many corporate environments, standalone fax machines have been replaced by “fax servers” and other computerized systems capable of receiving and storing incoming faxes electronically, and then routing them to users on paper or via an email (which may be secured). Such systems have the advantage of reducing costs by eliminating unnecessary printouts and reducing the number of inbound analog phone lines needed by an office.

Don’t have a fax machine ? No problem. You can use the Internet to send a free fax to any number all over the world. Here You find 10 websites for free online fax services.

1 . Myfax

  • Website : http://myfax.com
  • Fax Limitation : Unlimited
  • Support : Text and Document (.doc , .pdf etc)
  • Fax Receive : No
  • Registration Requirement : No
  • Country Limitation : Available for 41 Country’s

2 . Pamfax

  • Website : http://www.pamfax.biz
  • Fax Limitation : Unlimited
  • Support : Text and Document
  • Fax Receive : Yes
  • Registration Requirement : Yes
  • Country Limitation : Worldwide

3 . Faxzero

  • Website : http://faxzero.com
  • SMS Limitation : 2 faxes per day for free
  • Support : Text and Document
  • Registration Requirement : No
  • Country Limitation : Unknown

4 . Freepopfax

  • Website : http://www.freepopfax.com
  • Fax Limitation : Unlimited
  • Support : Text and Document
  • Registration Requirement : No
  • Country Limitation : Available for 48 Country’s

5 . Gotfreefax

  • Website : http://www.gotfreefax.com
  • Fax Limitation : 2 faxes per day for free
  • Support : Text and Document
  • Registration Requirement : No
  • Country Limitation : Worldwide

6 . Freefaxbutton

  • Website : http://www.freefaxbutton.com
  • Fax Limitation : 2 faxes per day for free
  • Support : Text only
  • Registration Requirement : No
  • Country Limitation : Available for 65 Country’s

7 . Fax1

  • Website : http://www.fax1.com
  • Fax : $1 for free use
  • Support : Text and Document
  • Fax Receive : Yes
  • Registration Requirement : Yes
  • Country Limitation : Worldwide

8 . Freefax

  • Website : http://freefax.1888usa.com
  • Fax Limitation : Unlimited
  • Support : Text only
  • Registration Requirement : No
  • Country Limitation : Available for 28 Country’s

9. Sendfreefax

  • Website : http://sendfreefax.net
  • Fax Limitation : Unlimited
  • Support : Text only
  • Registration Requirement : No
  • Country Limitation : Worldwide

10 . Faxaway

  • Website : http://www.faxaway.com
  • Fax Limitation : Unknown
  • Support : Text and Document
  • Fax Receive : Yes
  • Registration Requirement : Yes
  • Country Limitation : Worldwide

A detailed Discussion about CSS3 : border-image

Another exciting new border feature of CSS3 is the property border-image. With this feature you can define an image to be used instead of the normal border of an element. This feature is actually split up into a couple of properties: border-image and border-corner-image. These two values are shorthands for:

  • border-image:
    • border-top-image
    • border-right-image
    • border-bottom-image
    • border-left-image
  • border-corner-image:
    • border-top-left-image
    • border-top-right-image
    • border-bottom-left-image
    • border-bottom-right-image

border-image currently works in Safari and Firefox 3.1 (Alpha). The syntax to use it is:

border-image: url(border.png) 27 27 27 27 round round;

Which results in:

Lorem ipsum dolor sit amet.

Or:

border-image: url(border.png) 27 27 27 27 stretch stretch;

Which then results in:

Lorem ipsum dolor sit amet.

For those of you not so lucky as to be able to see this, here are screenshots of the two examples.

Number one:
border-image first example
Number two:
border-image second example

The new CSS3 property border-image is a little tricky, but it can allow you to create flexible boxes with custom borders (or drop shadows, if that’s your thing) with a single div and a single image. In this article I explain how the border-image shorthand property works in today’s browsers.

The basic idea

The border-image shorthand property has 3 parts:

border-image: url(border-image.png) 25% repeat;

Essentially, these allow you to specify:

  1. An image to use as the border
  2. Where to slice that image, dividing the image into 9 sections
  3. How the browser should apply those sections to the edges of your element

The pertinent details

Let’s look at each part of the process in a little more detail. The first part is easy, and is familiar from the background-image property. For demonstration purposes I’ll use this image, which is 100px x 100px:

A border-image

Slicing your image

The second part can have from one to four values, much like the border-width property, and they are specified in the same order: top, right, bottom, left. You can use percentages or pixels. Strangely, the percentages require the “%”, while pixels should be listed without the “px”:

border-image: url(my-image.gif) 25% 30% 10% 20% repeat;
border-image: url(my-image.gif) 25 30 10 20 repeat;

In this case, since my image is 100px x 100px, the two rules above are equivalent – they slice the image in the same places. I’ve added some dimensions on my image to demonstrate:

A border-image

Repeat, Round, Stretch

border-image will always place the corner sections of your image into the corresponding corners of your element box, but the third part of the shorthand rule tells the browser how to treat the middle sections of your image — the ones that will go along the edges of your element. Repeat (repeat, or tile, the image) and stretch (stretch, or scale, the image) are pretty self-explanatory. Round means tile the image but only so that a whole number of tiles fit, and otherwise scale the image. Right now, Safari and Chrome interpret round asrepeat. There can be up to two values: one for the top and bottom edges of the element, and one for the left and right. Here’s an example with the top/bottom value set to repeat, and the left/right value set to stretch:

#example-one {
 border-width:25px 30px 10px 20px;
 -moz-border-image:url("border-image.png") 25 30 10 20 repeat stretch;
 -webkit-border-image:url("border-image.png") 25 30 10 20 repeat stretch;
 border-image:url("border-image.png") 25 30 10 20 repeat stretch;
}

Screenshot for Example One

LIVE DEMO, RSS READERS CLICK OVER TO SEE. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu arcu non dui consequat vestibulum non vitae eros. Donec imperdiet lorem at mi rhoncus lacinia. Phasellus porttitor ligula eu justo condimentum eget placerat arcu pharetra. Proin fringilla vulputate eros in accumsan. Sed mi nibh, pulvinar eu sollicitudin ut, feugiat non ipsum. In ornare, quam sit amet tempor suscipit, erat odio suscipit nisi, eu gravida nisl orci ut arcu. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Border-width

border-image won’t do anything if you don’t specify a width for your border. For browsers that understand border-image, your image slices will be scaled to the specified width. If you use the border shorthand property, it provides a nice fallback for browsers that don’t:

#example-two {
 border:50px double orange;
 -moz-border-image:url("border-image.png") 25 30 10 20 repeat;
 -webkit-border-image:url("border-image.png") 25 30 10 20 repeat;
 border-image:url("border-image.png") 25 30 10 20 repeat;
}

Screenshot of Example Two

LIVE DEMO, RSS READERS CLICK OVER TO SEE.Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu arcu non dui consequat vestibulum non vitae eros. Donec imperdiet lorem at mi rhoncus lacinia. Phasellus porttitor ligula eu justo condimentum eget placerat arcu pharetra. Proin fringilla vulputate eros in accumsan. Sed mi nibh, pulvinar eu sollicitudin ut, feugiat non ipsum. In ornare, quam sit amet tempor suscipit, erat odio suscipit nisi, eu gravida nisl orci ut arcu. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Or you can specify each width individually (in this example I’ve specified widths such that the image slices aren’t scaled at all):

#example-three {
 border-color:orange;
 border-style:double;
 border-width:25px 30px 10px 20px;
 -moz-border-image:url("border-image.png") 25 30 10 20 repeat;
 -webkit-border-image:url("border-image.png") 25 30 10 20 repeat;
 border-image:url("border-image.png") 25 30 10 20 repeat;
}

Screenshot of Example Three

LIVE DEMO, RSS READERS CLICK OVER TO SEE. dolor sit amet, consectetur adipiscing elit. Aenean eu arcu non dui consequat vestibulum non vitae eros. Donec imperdiet lorem at mi rhoncus lacinia. Phasellus porttitor ligula eu justo condimentum eget placerat arcu pharetra. Proin fringilla vulputate eros in accumsan. Sed mi nibh, pulvinar eu sollicitudin ut, feugiat non ipsum. In ornare, quam sit amet tempor suscipit, erat odio suscipit nisi, eu gravida nisl orci ut arcu. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Using a plain border at the same widths as your border-image won’t always be ideal, however, so you may want to use conditional stylesheets to give IE some different border styles altogether.

Browser quirks

Predictably, IE doesn’t understand anything of border-image. Browsers that do support border-image only support the shorthand property, not all the individual properties that aredescribed in the spec. Some potentially useful properties aren’t supported at all, especiallyborder-image-outset, which would solve this problem.

Also, the default behavior is supposed to be to discard the center section of the image, and use the ‘fill’ keyword on the border-image-slice property to preserve it:

The ‘fill’ keyword, if present, causes the middle part of the border-image to be preserved. (By default it is discarded, i.e., treated as empty.) (Read the spec)

But the current browser behavior is to preserve the middle, and there is no way to turn it off. Thus, if you don’t want your element’s content area to have a background, the center section of your image must be empty. However, you can use this filling behavior to your advantage, to create a box with a fancy border and background, with only one image.

Interactive demo

I built a border-image demo page to help me get my head around this complicated new set of CSS3 properties. You can pick an image, specify repeat, round, or stretch, and adjust the border-width and slicing. Enjoy!

Examples in the wild

CSS3 makes it possible to specify an image as an element’s border, instead of just a solid color. While on the surface this doesn’t seem particularly interesting, the way the property works makes it more than that which meets the eye. The border-image property lets you specify a single image for the purpose and then slices that image to create the desired border effect. Yes, CSS is slicing now. border-image is currently supported in all the modern browsers to various degrees except IE (as of IE9). The shorthand syntax is:

border-image: url(image.png) 25 40 12 10 stretch;

Where:

  • url: The image that should be used as the border image.
  • slicevalues: Up to four numbers that specify where the browser should slice the image:
    • The 1st value sets the offset of the first horizontal cut from the top of the image. For pixel units, do NOT include the “px” suffix.

    • The 2nd value sets the offset of the second vertical cut from the right edge of the image.

    • The 3rd value sets the offset of the third horizontal cut from the bottom of the image.

    • The 4th value sets the offset of the fourth vertical cut from the left edge of the image.

  • stretch: How the slices should be oriented inside the element’s border. Valid values are “stretch”, “repeat”, “round”, or “space”.

For slicevalues, if only one number is defined, the same value will be used for all 4 cuts. If 2 numbers are defined, the first is used for the top and bottom cuts, and the second the left and right cuts. Regardless, 4 cuts are made to the image in total, and the browser ends up with 9 slices that it uses to put together the border image of an element. Each slice is used to fill the corresponding edges of the element’s border, with the center slice covering the element itself (and should be made transparent in most cases).

This post isn’t about a detailed description of border-image– that will have to be for another post. For this post, what I want to demonstrate is how to use this property to easily add image frames to containers on your page. First, create the image you’d like to use as the frame; here I’ve whipped up 2 simple frames to illustrate the technique:

  

Note that both images above have a transparent inside so the content they are framing can show through.

Now, to the heart of the matter- to add an image border to an element, define the border-image property with slicevalues that cut up the image as desired. Also define a border-width property echoing those values. Enough talk, to some examples now! Note that the below examples do not work in IE (as of IE9):

Example 1:

Found across much of the tropics, the coconut is known for its great versatility as seen in the many domestic, commercial, and industrial uses of its different parts. Coconuts are part of the daily diet of many people. Its endosperm is known as the edible “flesh” of the coconut; when dried it is called copra. The oil and milk derived from it are commonly used in cooking and frying; coconut oil is also widely used in soaps and cosmetics. The clear liquid coconut water within is a refreshing drink and can be processed to create alcohol. The husks and leaves can be used as material to make a variety of products for furnishing and decorating. It also has cultural and religious significance in many societies that use it. -Wikipedia

CSS:

.imageborder{
border-width: 20px;
-moz-border-image: url(frame.gif) 20 stretch; /*Mozilla version*/
-webkit-border-image: url(frame.gif) 20 stretch; /*Webkit version*/
-o-border-image: url(frame.gif) 20 stretch; /*Opera version*/
-ms-border-image: url(frame.gif) 20 stretch; /*IE syntax when it does support this prop*/
border-image: url(frame.gif) 20 stretch; /*Standard version*/
}

Markup:

<div style=”width:50%;min-height:150px”>
Content text here…
</div>

Example 2:

CSS: Same as above.

Markup:

<img src=”coconut.jpg” />

Example 3:

CSS:

.imageborder2{
border-width: 25px 30px;
-moz-border-image: url(frame2.png) 25 30 stretch;
-webkit-border-image: url(frame2.png) 25 30 stretch;
-o-border-image: url(frame2.png) 25 30 stretch;
-ms-border-image: url(frame2.png) 25 30 stretch;
border-image: url(frame2.png) 25 30 stretch;
}.

Markup:

<div style=”width:470px;height:300px;background:url(ocean_thumb.jpg) center center no-repeat”>
</div>

 

If you have other examples on live sites, I’d love to see them. Leave a link in the comments!

How to get a Paypal Button on webpage

Write the below given code into an HTML file where you want to add a donation button.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick"/>
    <input type="hidden" name="business" value="donations@example.com"/>
    <input type="hidden" name="item_name" value="School Fund"/>
    <input type="hidden" name="item_number" value="2011"/>
    <input type="hidden" name="amount" value="50.00"/>
    <input type="hidden" name="no_shipping" value="2"/>
    <input type="hidden" name="no_note" value="1"/>
    <input type="hidden" name="currency_code" value="USD"/>
    <input type="hidden" name="tax" value="0"/>
    <input type="hidden" name="bn" value="PP-DonationsBF"/>
    <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but21.gif" 
        border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
    <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>

where input type are fields to have values for your expectations, the name business shows the value for the type of business, item_name shows the type of item, amount for the value of item, and so on …

And you are done with a button for your Paypal payment gateway.

And for the rest making a change in value for the line <input type=”hidden” name=”bn” value=”PP-DonationsBF”/>,
you can switch between several types of alternatives:

  1. <input type=”hidden” name=”bn” value=”PP-SubscriptionsBF”/>
  2. <input type=”hidden” name=”bn” value=”PP-DonationsBF”/>
  3. <input type=”submit” value=”PayPal”/>
  4. <input type=”hidden” name=”bn” value=”PP-BuyNowBF”/>
  5. <input type=”hidden” name=”bn” value=”PP-ShopCartBF”/>

Hence your Paypal gateway is ready to face the world of payments.

Exporting only selected or checked rows and records from grid to Word or Excel sheet using asp.net

Introduction: 
Here I will explain how to export only selected or checked rows or records from gridview to Word or Excel sheet using asp.net.
Description:

After all the concepts one of the user has asked me a question i.e. how to export gridview records to excel/word based on checkbox selection in gridview. To implement this one first design one table in database as shown below and give name as “UserInformation” 

ColumnName

DataType

UserId

Int(set identity property=true)

UserName

varchar(50)

LastName

varchar(50)

Location

varchar(50)

After completion of table creation enter some dummy data and design aspx page like this

<html xmlns=”http://www.w3.org/1999/xhtml”&gt;

<head id=”Head1″ runat=”server”>

<title>Export Selected records from Gridview to Excel/ Word</title>

<style type=”text/css”>

.GridviewDiv {font-size100%font-family‘Lucida Grande’, ‘Lucida Sans Unicode’, Verdana, Arial,Helevetica, sans-serifcolor#303933;}

Table.Gridview{border:solid 1px #df5015;}

.Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em0.5em 0.5em 0.5em;text-align:center}

.Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em0.5em;}

.Gridview tr{colorBlackbackground-colorWhitetext-align:left}

:link,:visited { color#DF4F13text-decoration:none }

.highlight {text-decorationnone;color:black;background:yellow;}

</style>

</head>

<body>

<form id=”form1″ runat=”server”>

<div>

<table>

<tr>

<td align=”right”>

<asp:ImageButton ID=”btnExcel” runat=”server” ImageUrl=”~/ExcelImage.jpg”

onclick=”btnExportExcel_Click” />

<asp:ImageButton ID=”btnWord” runat=”server” ImageUrl=”~/WordImage.jpg”

onclick=”btnWord_Click” />

</td>

</tr>

<tr>

<td>

<div class=”GridviewDiv”>

<asp:GridView ID=”gvdetails” runat=”server” AutoGenerateColumns=”False” AllowPaging=”True”

AllowSorting=”true” Width=”540px” PageSize=”10″ CssClass=”Gridview” 

DataKeyNames=”UserId”OnPageIndexChanging=”gvdetails_PageIndexChanging” >

<HeaderStyle BackColor=”#df5015″ />

<Columns>

<asp:TemplateField>

<ItemTemplate>

<asp:CheckBox ID=”chkSelect” runat=”server” />

</ItemTemplate>

</asp:TemplateField>

<asp:BoundField DataField=”UserId” HeaderText=”UserId” />

<asp:BoundField DataField=”UserName” HeaderText=”UserName” />

<asp:BoundField DataField=”LastName” HeaderText=”LastName” />

<asp:BoundField DataField=”Location” HeaderText=”Location” />

</Columns>

</asp:GridView>

</div>

</td>

</tr>

</table>

</div>

</form>

</body>

</html>

Now in code behind add following namespace references

using System;

using System.Collections;

using System.Data;

using System.Data.SqlClient;

using System.IO;

using System.Web.UI;

using System.Web.UI.WebControls;

After that write the following code in code behind
C# Code


protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

BindGridData();

}

}

/// <summary>

/// This Method is used to bind gridview

/// </summary>

private void BindGridData()

{

SqlConnection con = new SqlConnection(“Data Source=SD;Integrated Security=true;Initial Catalog=MySampleDB”);

SqlCommand cmd = new SqlCommand(“select * from UserInformation”, con);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds);

gvdetails.DataSource = ds;

gvdetails.DataBind();

}

public override void VerifyRenderingInServerForm(Control control)

{

/*Verifies that the control is rendered */

}

protected void gvdetails_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

SaveCheckedValues();

gvdetails.PageIndex = e.NewPageIndex;

BindGridData();

PopulateCheckedValues();

}

/// <summary>

/// This event is used to export gridview data to Excel document

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

protected void btnExportExcel_Click(object sender, EventArgs e)

{

ExportFunction(“attachment;filename=GridViewExport.xls”“application/vnd.ms-excel”);

}

/// <summary>

/// This event is used to export gridview data to word document

/// </summary>

/// <param name=”sender”></param>

/// <param name=”e”></param>

protected void btnWord_Click(object sender, EventArgs e)

{

ExportFunction(“attachment;filename=GridViewExport.doc”“application/vnd.ms-word”);

}

/// <summary>

/// This Function is used to generate Excel or word document with gridview checkbox selected values

/// </summary>

/// <param name=”header”></param>

/// <param name=”contentType”></param>

private void ExportFunction(string header, string contentType)

{

SaveCheckedValues();

Response.Clear();

Response.Buffer = true;

Response.AddHeader(“content-disposition”, header);

Response.Charset = “”;

Response.ContentType = contentType;

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

gvdetails.AllowPaging = false;

BindGridData();

gvdetails.HeaderRow.Style.Add(“background-color”“#FFFFFF”);

gvdetails.HeaderRow.Cells[0].Visible = false;

for (int i = 0; i < gvdetails.HeaderRow.Cells.Count; i++)

{

gvdetails.HeaderRow.Cells[i].Style.Add(“background-color”“#df5015”);

gvdetails.HeaderRow.Cells[i].Style.Add(“color”“#FFFFFF”);

}

if (ViewState[“CHECKED_ITEMS”] != null)

{

ArrayList CheckBoxArray = (ArrayList)ViewState[“CHECKED_ITEMS”];

int rowIdx = 0;

for (int i = 0; i < gvdetails.Rows.Count; i++)

{

GridViewRow row = gvdetails.Rows[i];

row.Visible = false;

int index = (int)gvdetails.DataKeys[row.RowIndex].Value;

if (CheckBoxArray.Contains(index))

{

row.Visible = true;

row.Cells[0].Visible = false;

}

}

}

gvdetails.RenderControl(hw);

Response.Output.Write(sw.ToString());

Response.End();

}

/// <summary>

///This method is used to populate the saved checked status of checkbox values

/// </summary>

private void PopulateCheckedValues()

{

ArrayList userdetails = (ArrayList)ViewState[“CHECKED_ITEMS”];

if (userdetails != null && userdetails.Count > 0)

{

foreach (GridViewRow gvrow in gvdetails.Rows)

{

int index = (int)gvdetails.DataKeys[gvrow.RowIndex].Value;

if (userdetails.Contains(index))

{

CheckBox myCheckBox = (CheckBox)gvrow.FindControl(“chkSelect”);

myCheckBox.Checked = true;

}

}

}

}

/// <summary>

/// This method is used to save the checkedstate of checkbox values

/// </summary>

private void SaveCheckedValues()

{

ArrayList userdetails = new ArrayList();

int index = -1;

foreach (GridViewRow gvrow in gvdetails.Rows)

{

index = (int)gvdetails.DataKeys[gvrow.RowIndex].Value;

bool result = ((CheckBox)gvrow.FindControl(“chkSelect”)).Checked;

// Check in the Session

if (ViewState[“CHECKED_ITEMS”] != null)

userdetails = (ArrayList)ViewState[“CHECKED_ITEMS”];

if (result)

{

if (!userdetails.Contains(index))

userdetails.Add(index);

}

else

userdetails.Remove(index);

}

if (userdetails != null && userdetails.Count > 0)

ViewState[“CHECKED_ITEMS”] = userdetails;

}

VB.NET Code

Imports System.Collections

Imports System.Data

Imports System.Data.SqlClient

Imports System.IO

Imports System.Web.UI

Imports System.Web.UI.WebControls

Partial Public Class VBExportData

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs)

If Not IsPostBack Then

BindGridData()

End If

End Sub

”’ <summary>

”’ This Method is used to bind gridview

”’ </summary>

Private Sub BindGridData()

Dim con As New SqlConnection(“Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB”)

Dim cmd As New SqlCommand(“select * from UserInformation”, con)

Dim da As New SqlDataAdapter(cmd)

Dim ds As New DataSet()

da.Fill(ds)

gvdetails.DataSource = ds

gvdetails.DataBind()

End Sub

Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)

‘Verifies that the control is rendered

End Sub

Protected Sub gvdetails_PageIndexChanging(ByVal sender As Object

ByVal e As GridViewPageEventArgs)

SaveCheckedValues()

gvdetails.PageIndex = e.NewPageIndex

BindGridData()

PopulateCheckedValues()

End Sub

”’ <summary>

”’ This event is used to export gridview data to Excel document

”’ </summary>

”’ <param name=”sender”></param>

”’ <param name=”e”></param>

Protected Sub btnExportExcel_Click(ByVal sender As ObjectByVal e 

AsSystem.Web.UI.ImageClickEventArgs) Handles btnExcel.Click

ExportFunction(“attachment;filename=GridViewExport.xls”“application/vnd.ms-excel”)

End Sub

”’ <summary>

”’ This event is used to export gridview data to word document

”’ </summary>

”’ <param name=”sender”></param>

”’ <param name=”e”></param>

Protected Sub btnWord_Click(ByVal sender As ObjectByVal e As 

System.Web.UI.ImageClickEventArgs)Handles btnWord.Click

ExportFunction(“attachment;filename=GridViewExport.doc”“application/vnd.ms-word”)

End Sub

”’ <summary>

”’ This Function is used to generate Excel or word document with gridview checkbox selected values

”’ </summary>

”’ <param name=”header”></param>

”’ <param name=”contentType”></param>

Private Sub ExportFunction(ByVal header As StringByVal contentType As String)

SaveCheckedValues()

Response.Clear()

Response.Buffer = True

Response.AddHeader(“content-disposition”, header)

Response.Charset = “”

Response.ContentType = contentType

Dim sw As New StringWriter()

Dim hw As New HtmlTextWriter(sw)

gvdetails.AllowPaging = False

BindGridData()

gvdetails.HeaderRow.Style.Add(“background-color”“#FFFFFF”)

gvdetails.HeaderRow.Cells(0).Visible = False

For As Integer = 0 To gvdetails.HeaderRow.Cells.Count – 1

gvdetails.HeaderRow.Cells(i).Style.Add(“background-color”“#df5015”)

gvdetails.HeaderRow.Cells(i).Style.Add(“color”“#FFFFFF”)

Next

If ViewState(“CHECKED_ITEMS”IsNot Nothing Then

Dim CheckBoxArray As ArrayList = DirectCast(ViewState(“CHECKED_ITEMS”), ArrayList)

Dim rowIdx As Integer = 0

For As Integer = 0 To gvdetails.Rows.Count – 1

Dim row As GridViewRow = gvdetails.Rows(i)

row.Visible = False

Dim index As Integer = CInt(gvdetails.DataKeys(row.RowIndex).Value)

If CheckBoxArray.Contains(index) Then

row.Visible = True

row.Cells(0).Visible = False

End If

Next

End If

gvdetails.RenderControl(hw)

Response.Output.Write(sw.ToString())

Response.[End]()

End Sub

”’ <summary>

”’This method is used to populate the saved checked status of checkbox values

”’ </summary>

Private Sub PopulateCheckedValues()

Dim userdetails As ArrayList = DirectCast(ViewState(“CHECKED_ITEMS”), ArrayList)

If userdetails IsNot Nothing AndAlso userdetails.Count > 0 Then

For Each gvrow As GridViewRow In gvdetails.Rows

Dim index As Integer = CInt(gvdetails.DataKeys(gvrow.RowIndex).Value)

If userdetails.Contains(index) Then

Dim myCheckBox As CheckBox = DirectCast(gvrow.FindControl(“chkSelect”), CheckBox)

myCheckBox.Checked = True

End If

Next

End If

End Sub

”’ <summary>

”’ This method is used to save the checkedstate of checkbox values

”’ </summary>

Private Sub SaveCheckedValues()

Dim userdetails As New ArrayList()

Dim index As Integer = -1

For Each gvrow As GridViewRow In gvdetails.Rows

index = CInt(gvdetails.DataKeys(gvrow.RowIndex).Value)

Dim result As Boolean = DirectCast(gvrow.FindControl(“chkSelect”), CheckBox).Checked

‘ Check in the Session

If ViewState(“CHECKED_ITEMS”IsNot Nothing Then

userdetails = DirectCast(ViewState(“CHECKED_ITEMS”), ArrayList)

End If

If result Then

If Not userdetails.Contains(index) Then

userdetails.Add(index)

End If

Else

userdetails.Remove(index)

End If

Next

If userdetails IsNot Nothing AndAlso userdetails.Count > 0 Then

ViewState(“CHECKED_ITEMS”) = userdetails

End If

End Sub

End Class

After that run your application output would be like this

If you observe above code I written code to export selected rows of gridview based on checkbox selection.  here I used “maintain state of checkboxes in while paging in gridview” concept to maintain the state of checkboxes while paging in gridview and I added one function that is VerifyRenderingInServerForm this function is used to avoid the error like “control must be placed in inside of form tag”.

If we set VerifyRenderingInServerForm function then compiler will think that controls rendered before exporting and our functionality will work perfectly. Here I used simple code to export gridview data to excel document and for word document we can use the same code (Export to Word) to import gridview data just by replacing GridViewExport.xls to GridViewExport.doc and application/ms-excel toapplication/ms-word

Demo

Now select checkboxes and click on Excel button you will get output like this

Demo for Excel document

Demo for Word document

Download : sample code attached

Now if you’re getting any error message please feel free to let me know ?

%d bloggers like this: