This is simple code to export gridview data in export to excel.
Here I assume that Data table name is “_sampleData” and it is already there. To execute the code I also assumed that button names “Button1” is also present and I have called one function named “GridExportToExcel” on click event of that button.

Following is the function to export Gridview control to excel function has two parameters one is gridview object and name of the excel file. This function generates excel file in “.xls” format.




Download Demo Code CLICK HERE

To open new window we need to use following JavaScript function



This function allows us to open a new browser window for the viewer to use; all the attributes are separated by commas

Window Attributes

Below is a list of the attributes you can use:

1. width=300
Use this to define the width of the new window.

2. height=200
Use this to define the height of the new window.

3. resizable=yes or no
Use this to control whether or not you want the user to be able to resize the window.

4. scrollbars=yes or no
This lets you decide whether or not to have scrollbars on the window.

5. toolbar=yes or no
Whether or not the new window should have the browser navigation bar at the top (The back, foward, stop buttons..etc.).

6. location=yes or no
Whether or not you wish to show the location box with the current url (The place to type http://address).

7. directories=yes or no
Whether or not the window should show the extra buttons. (what's cool, personal buttons, etc...).

8. status=yes or no
Whether or not to show the window status bar at the bottom of the window.

9. menubar=yes or no
Whether or not to show the menus at the top of the window (File, Edit, etc...).

10. copyhistory=yes or no
Whether or not to copy the old browser window's history list to the new window.



JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

JSON is built on two structures:

* A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
* An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

Kindly click on following link for more information. I find JSON much more useful for Ajax operations since parsing is easy like an XML.

check it : http://json.org/

This article is for those who are new to Ajax. Ajax stands for Asynchronous Java And Xml. Ajax is the great solution for the new age of web applications, it simply helps developer to increase the performance of the site along with the more user interactive UI. Since web page is not getting refreshed each time, it is more users friendly.

The idea is; if page size is 500kb and only 10kb of data is to be updated, then if web application sending and receiving only 10kb data to and from server make more sense, than refreshing whole page. Also the request to server is asynchronously so that user can continue with the work instead of waiting for the response from the server.

It really works fast a very good web experience, in old days of the web development each time user is suppose to wait for the whole page to get refreshed, not a good idea.

Start with AJAX :
Ajax actually works because of the XMLHttpRequest object. Using this object web application can communicate with the server, i.e. either web service or the webpage. In this case web service or webpage will send required data to client page and then on client side using Java script corresponding field can be update.

You can create XMLHttpRequest object as follows:




“request” is the XMLHttpRequest object in above code. (Code is in JavaScript )

Next step after this is to open the object connection and send the request
Open method looks like

XMLHttpRequest.open(method, url, in boolean async, [user, password])
i.e.
request.open('GET', url+parameter, true)
request.send(null)
(Here we are not going to use user and password)
but before this, we need to specify the function which will take care of the data return from the server. i.e. once we send request to the server using XMLHttpRequest object and once response comes from the server which function will handle it.
Before sending the request we will specify the action; for this XMLHttpRequest object posses one event called as onreadystatechange. On this event we can specify which function should be called on each ready state change.
Now before this will understand which are the states XMLHttpRequest object supports.


Ready state valueDescription
0Represents an uninitialized state in which XMLHttpRequest object is created; and not initialized
1Open() method has been successfully called
2Sent () : request has been sent to the server.
3Represent "receiving" state in which the HTTP response headers have been received; message body has not yet been completely received.
4Loaded, data transfer has been completed.


So the above code will change to





Now we will develop a web application in which user will select the value in the combo box and on selection of the value dependent textbox will be filled. In this case on change event of the combo will be used to fire an Ajax request to the server and server in turns will send a response to the client. (Coding is done in asp.net 2.0)

1.Create a web application design a combo box and text box as follows





2.And in code behind add attribute to “InputList” i.e. to combo box.

"callToServer(this.value)" is the javascript function, this function will accept the selected value and send request to the server; using XMLHttpRequest object.

3.Now add one webservice in the same project. Also add following prototypes in web.config file.

Add above code in tab. This is required to communicate with webservice over http.

4.Now write one webmethod in the webservice. i.e.

We will call this webMethod in our Ajax call.

5.After this, will write a JavaScript function "callToServer(this.value)" . This function will be called on onchange event of dropdown list (Ref point 1).

If you observe the url it is the url of the webserivce in the same project.
Here we have to use url which is under the same domain, Firefox doesn’t allow cross refrence, and IE give warning (i.e. IE 6).

Means
var url = "http://domain1/WebSite/webservice.asmx/sendMessage?str="+val;
this will give warning in the IE 6 but Firefox will not allow you to access this webservice.


In the above function check request.onreadystatechange=handleResponse;
Here if you obsever onreadystatechange on function named handleResponse is called. So in the next step we will have to write a function which will handle the response from the server.


6.handleResponse function will be as follows

Since the response is from webservice and it is in the xmlformat, we have to use parser to parse the data. If you want to see what is the response from the server add alert(request.responseText) in the above code after 1st if condition.

window.document.getElementById('DependentOutput').value = data; this line will fill the textbox with the response from the server.


This how we can create Ajax application, it’s very simple and easy. Once you understand this concept, you can modify the code and make it more complex as per your requirements.

preload preload preload