Click here to Skip to main content
15,885,278 members
Articles / Web Development / ASP.NET

The Complete Datagrid (Alphabetic and Customized Paging )

Rate me:
Please Sign up or sign in to vote.
4.43/5 (3 votes)
23 Jul 2011CPOL3 min read 34.6K   1.4K   17  
Editing, Deleting, Sorting, Alphabetic and Customized paging all in one
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomizePaging.aspx.cs" Inherits="DataGrid_Demo.CustomizePaging" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
 <style type="text/css">
        #div1
        {
            
            color:White;
            font-size:25px;
            font-family:Arial;
        }
        .style1
        {
            width: 180px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div style="background-color:Navy;margin-bottom:100px;text-align:center;width:101%; position:relative;height:150px;position:relative; top: -12px; left: -6px; height: 156px;">
  <div id="div1">DATAGRID
</div>  </div>
<div>

<asp:DataGrid  runat="server" ID="dgProductN" AllowCustomPaging="True"   Width="100%"
        AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" 
        PageSize="5" 
            onsortcommand="dgProductN_SortCommand" 
            oncancelcommand="dgProductN_CancelCommand" 
            ondeletecommand="dgProductN_DeleteCommand" 
            oneditcommand="dgProductN_EditCommand" 
            onupdatecommand="dgProductN_UpdateCommand" DataKeyField="ProductID" 
            CellPadding="4" ForeColor="#333333" GridLines="None" 
            onitemdatabound="dgProductN_ItemDataBound">
           <AlternatingItemStyle BackColor="White" Width="10px" />
        <Columns>
               
              <asp:BoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"></asp:BoundColumn>
              <asp:BoundColumn DataField="Price" HeaderText="Price" SortExpression="Price"></asp:BoundColumn>           
              <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" CausesValidation="false" ItemStyle-Width="10px" Visible="true" HeaderText="Edit">
              </asp:EditCommandColumn>
             <asp:ButtonColumn Text="Delete" CommandName="Delete" CausesValidation="false" 
                HeaderText="Delete"></asp:ButtonColumn>
         </Columns>
           <EditItemStyle BackColor="#CCFFCC" HorizontalAlign="Left" Width="10px" />
           <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
           <HeaderStyle BackColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" 
               ForeColor="White" Font-Bold="True" />
           <ItemStyle BackColor="#EFF3FB" Width="10px" />
           <PagerStyle Visible="False" BackColor="#2461BF" ForeColor="White" 
               HorizontalAlign="Center" />
           <SelectedItemStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
     </asp:DataGrid>  </div>
    <div>
    <p>Page:<asp:Label ID="CurrentPage" runat="server">
</asp:Label><asp:Label ID="lblOf" runat="server" Text=" of "></asp:Label>
        <asp:Label ID="TotalPages" runat="server"></asp:Label>
            <asp:Label ID="lblalpha" runat="server" Visible="False"></asp:Label> 
       <asp:Label ID="lblflag" runat="server" Visible="False"></asp:Label>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <asp:LinkButton runat="server" CommandName="Prev" Text="< Prev" ID="PrevPage" 
            onclick="PrevPage_Click" CausesValidation="False"  ></asp:LinkButton>&nbsp;
    <asp:LinkButton ID="Nextbtn" runat="server" CommandName="Next" Text="Next >" 
            onclick="Nextbtn_Click" CausesValidation="False"></asp:LinkButton> </p>
    </div>
    <div> <asp:Label ID="lblError" runat="server" Visible="False" ForeColor="Red"></asp:Label></div>
    </form>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions