Feb 26th, 2009 | 1 Comment

The GridView control provides you with the option of sorting and paging records without requiring a form-post back to the Web server. In other words, you can re-render the contents of a GridView when sorting and paging, without needing to re-render the entire page.

You enable client paging and sorting by assigning the value true to the EnableSortingAndPagingCallback property. When this property has the value true, the GridView uses JavaScript to request an updated set of records from the Web server.


1 <%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

2

3 <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

4 <html>

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

6 <title>Callback GridView</title>

7 </head>

8 <body>

9 <form id=”Form1″ runat=”server”>

10 <%=DateTime.Now %>

11 <asp:GridView ID=”GridView1″ DataSourceID=”TitlesSource” EnableSortingAndPagingCallbacks=”true”

12 AllowPaging=”true” AllowSorting=”true” runat=”Server” />

13 <asp:SqlDataSource ID=”TitlesSource” ConnectionString=”Server=localhost;Database=northwind;Trusted_Connection=true”

14 SelectCommand=”SELECT * FROM customers” runat=”Server” />

15 </form>

16 </body>

17 </html>


Here when you will sort the page or click on the page number the time will not change as it is being set on the page load but the data will get sorted. The time doesn’t change because the page is not reloaded.

Behind the scenes, the GridView uses the Microsoft Internet Explorer XMLHTTPRequest object to communicate with the Web server. This object is supported by Internet Explorer version 5.0 and higher.

However this does not work when you have a templatefield in your Gridview. If you have a templatefield in your Gridview you need to perform the pagination like traditional way handling the events.

Written by Ajay Matharu

February 26th, 2009 at 7:00 pm

Dec 29th, 2008 | No Comments

Hi guys, do you know you can use already ready code inside your visual studio? Yes certainly you can insert code snippets into your code. You can invoke the “Insert Snippet” by using shortcut “ctrl k + ctrl x”.

snippet

You can download some of the code snippets from http://msdn.microsoft.com/en-us/vstudio/aa718338.aspx all you need to do is install this file at “My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets” location. You can also find some more snippets at http://www.codeplex.com/snippetlibcsharp/Release/ProjectReleases.aspx?ReleaseId=14841 all you need to do is copy this snippet at “My Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets” and you are ready to use these ready made code into your visual studio using shortcuts “ctrl k + ctrl x”

You can also insert the snippets by writing a part of it and pressing tab twice. For e.g. to insert a new property in your code type

prop + tab + tab

this will insert a property in your code window.

So keep using this to improve your productivity, and enjoy coding.

:Ajay Matharu

Page 5 of 7« First34567