ASP.NET
  Home arrow ASP.NET arrow How to Play with DataGrid Control
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

How to Play with DataGrid Control
By: Mayank Gupta
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 53
    2004-06-16

    Table of Contents:
  • How to Play with DataGrid Control
  • How the Work is Done
  • The Page_Load Event Handler
  • Editing
  • Handling Item Edit Events
  • Handling Multiple Row Selection for Deletion by Checkbox Control
  • Finishing Up

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    How to Play with DataGrid Control


    (Page 1 of 7 )

    This article provides a demo of  how to divide up data into pages. Mayank Gupta illustrates how to automatically create pages containing the number of rows you require and how to make a custom interface.

    Introduction

    One example of using the DataGrid control to display data is the use of “paging”. When you have a large number of rows to display, sending them all to the client in one group at once doesn’t make sense. Your client will get impatient waiting for them all to arrive and may find that they actually wanted to see something else instead. To prevent this aggravation and waste of bandwidth, we actually divide the output into pages containing 10 –20 rows per page.

    DataGrid web control makes it easy to provide a paging feature. It contains logic that can automatically create pages containing the number of rows you require, and it can render the navigation control in a range of ways. You can also take over paging entirely and implement all the features yourself to provide a custom interface.

    Description

    To allow paging we simply ALLOWPAGING property of the DataGrid control to true and specify the name of an event handler that will run when the PAGEINDEXCHANGED event occurs.

    <asp:DataGrid id="dgNonApproveList" runat="server" OnPageIndexChanged="MyDataGrid_Page" Width="752px" AllowPaging="True" AllowSorting="True" ForeColor="#000000"
    Font-Names="Arial" Font-Size="Smaller" AutoGenerateColumns="false">

    Our example that uses the automatic paging feature is used with a DataGrid control as well as EDITITEMTEMPLATE.

    To start describing below example, Viewer to run the SQL script in SQL analyzer:

    In Web.Config file, you have to define your own connection string:

    <appSettings><add key="strConn" value="workstation id='VENIRE-102-011';packet size=4096;integrated security=SSPI;data source='VENIRE-102-011\MAYANK';persist security info=True;initial catalog=vkmf"></add>
    </appSettings>

    CREATE TABLE [DocTemplate] (
     [DocTId] [int] NOT NULL ,
     [DocTitle] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
     [PostDate] [datetime] NOT NULL CONSTRAINT [DF_DocTemplate_PostDate] DEFAULT (getdate()),
     [FuncId] [int] NULL ,
     [TemplateAttachment] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
     [MetaData] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
     [Image] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_DocTemplate_Image] DEFAULT ('UnrecoFile.jpg')
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO

    Insert Into DocTemplate values(1,Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)
    Insert Into DocTemplate values(2, Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)
    Insert Into DocTemplate values(3, Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)
    Insert Into DocTemplate values(4, Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)
    Insert Into DocTemplate values(5, Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)
    Insert Into DocTemplate values(6, Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)
    Insert Into DocTemplate values(7, Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)
    Insert Into DocTemplate values(8, Microsoft  Stake Holder Request’,’1/1/1900 0:00’,1,’DocTemplate\VKMFStakeholder Requests-1.doc’,’<Long Text>’,’UnrecoFile.jpg’)

    CREATE TABLE [UserDocDefault] (
     [UserId] [int] NULL ,
     [DocTId] [int] NULL ,
     [DateTo] [datetime] NULL CONSTRAINT [DF_UserDocDefault_DateTo] DEFAULT (getdate()),
     [DateTill] [datetime] NULL CONSTRAINT [DF_UserDocDefault_DateTill] DEFAULT (getdate()),
     [Activate] [tinyint] NULL CONSTRAINT [DF_UserDocDefault_Activate] DEFAULT (0)
    ) ON [PRIMARY]
    GO

    Insert Into UserDocDefault values(11003,1, ‘5/22/2004’,’ 5/26/2004’, 0)
    Insert Into UserDocDefault values(11003,2, ‘5/22/2004’,’ 5/26/2004’, 0)
    Insert Into UserDocDefault values(11003,3, ‘5/22/2004’,’ 5/26/2004’, 0)
    Insert Into UserDocDefault values(11003,4, ‘5/22/2004’,’ 5/26/2004’, 0)
    Insert Into UserDocDefault values(11003,5, ‘5/22/2004’,’ 5/26/2004’, 0)
    Insert Into UserDocDefault values(11003,6, ‘5/22/2004’,’ 5/26/2004’, 0)
    Insert Into UserDocDefault values(11003,7, ‘5/22/2004’,’ 5/26/2004’, 0)
    Insert Into UserDocDefault values(11003,8, ‘5/22/2004’,’ 5/26/2004’, 0)

    More ASP.NET Articles
    More By Mayank Gupta


     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek