Apr 10, 2016

Databound fields in GridView using Ado.net in asp.net C#

Hello there, here i m explaining how to use Databound fields using gridview .
Now first of all we will create a database.  Here the following script, copy it and run it.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbEmp]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tbEmp](
      [id] [int] IDENTITY(1,1) NOT NULL,
      [name] [varchar](50) NULL,
      [age] [int] NULL,
      [address] [varchar](50) NULL
) ON [PRIMARY]
END



Place the GridView control on a form and set the following property.
       AutoGenerateColumns="False"
And set the Gridview Events name is
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
onrowupdating="GridView1_RowUpdating"



Or add the default.aspx page and paste the following source code in it.


DataList Paging using ado.net in asp.net C#

In this article i am explaining how to do paging in datalist as we know datalist control does not support paging properties as Gridview control support. In this article i m displaying two images for paging and according to your requirement you can change it.  First of all create a database following the script which you can copy and paste it in your sql server 2005.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[tbStudent]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[tbStudent](
      [id] [int] IDENTITY(10,1) NOT NULL,
      [name] [varchar](50) NULL,
      [age] [int] NULL,
      [rollno] [int] NULL,
      [address] [varchar](50) NULL,
      [image] [varchar](50) NULL
) ON [PRIMARY]
END