Thursday, May 2, 2013

gridview paging and sorting without postback in asp.net


In previous articles we have seen Bind data to dropdownlist in gridview,edit,delete,update in grdivew.In this post i will show how to avoid the post back while doing the sorting and paging in gridview.For this we need the set the EnableSortingAndPagingCallbacks to true,then it can perform client side callbacks to fetch the data.If we are using Template field.This property can not support.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Gridview Paging and Sorting with out postback</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GvSales" AllowSorting="True" Runat="server"
 EnableSortingAndPagingCallbacks="true" AllowPaging="true" 
AutoGenerateColumns="False" DataSourceID="SalesDb" 
       PageSize="4">
<Columns>
            <asp:BoundField DataField="SalesID" HeaderText="SalesID"
                 SortExpression="SalesID" />
             <asp:BoundField DataField="SalesPersonName" HeaderText="SalesPersonName"
                SortExpression="SalesPersonName" />
             <asp:BoundField DataField="SaleCity" HeaderText="SalesCity" SortExpression="SaleCity" />
             <asp:BoundField DataField="SalesAmt" HeaderText="Samount"
                 SortExpression="Samount" />
          </Columns>
       </asp:GridView>
<asp:SqlDataSource ID="SalesDb" runat="server"
            ConnectionString="<%$ ConnectionStrings:bhaskarConnectionString %>"
            SelectCommand="SELECT * FROM [Sales_Orders]"></asp:SqlDataSource>
 </div>
 </form>
</body>
</html>
Paging and sorting in Gridview

Post a Comment

Bel