ASP.NET GridView Samples

HOW TO DO INSERT,UPDATE,DELETE AND SELECT in gridview without writing a single   piece of code(ASP.NET C#):



STEP 1:
FIRST CREATE TABLES & STORED PROCEDURES IN SQL SERVER:


CREATE TABLE tbl_Student(Stud_ID varchar(20) primary key,Stud_Name VARCHAR(50),
Stud_Addr VARCHAR(MAX))

INSERT INTO tbl_Student(Stud_ID,Stud_Name,Stud_Addr)
Values
('07ca054','Rexmine Rose','Ooty')

INSERT INTO tbl_Student(Stud_ID,Stud_Name,Stud_Addr)
Values
('07ca055','Arvind','Dindugal')

INSERT INTO tbl_Student(Stud_ID,Stud_Name,Stud_Addr)
Values
('07ca056','Annie George','Trissur')

INSERT INTO tbl_Student(Stud_ID,Stud_Name,Stud_Addr)
Values
('07ca057','Jaikumar','Jabalpur')

INSERT INTO tbl_Student(Stud_ID,Stud_Name,Stud_Addr)
Values
('07ca058','Vijay Vignesh','Tanjore')

INSERT INTO tbl_Student(Stud_ID,Stud_Name,Stud_Addr)
Values
('07ca059','Cleetes Praveen','Palladam')

INSERT INTO tbl_Student(Stud_ID,Stud_Name,Stud_Addr)
Values
('07ca060','Sarlin Raj Tilak','Vellore')

SELECT * FROM tbl_Student



-- STORED PROCEDURE FOR SELECT
CREATE PROC sp_Select
AS
SELECT * FROM tbl_Student

--STORED PROCEDUE FOR UPDATE
CREATE PROC sp_Update
@Stud_ID VARCHAR(20),
@Stud_Name Varchar(50),
@Stud_Addr VARCHAR(MAX)
AS
UPDATE tbl_Student SET Stud_Name=@Stud_Name,Stud_Addr=@Stud_Addr WHERE

Stud_ID=@Stud_ID

--STORED PROCEDURE FOR DELETE
CREATE PROC sp_Delete
@Stud_ID VARCHAR(20)
AS
DELETE FROM tbl_Student WHERE Stud_ID=@Stud_ID



SELECT,UPDATE AND DELETE in ASP.NET gridview:
Step 2:
Open Visual Studio--->>file--->>> new --->>>
Website--->>>choose language as c#--->>>ok

Step 3:
drag and drop a "sql datasource" control from the datatab of the tool box
and place it in .aspx page

Step 4:
now click on the smart tag(">") of sqldatasource-->>
configure datasource-->>new connection--->>>and create a connection with your

database--->>>ok--->>next--->>>next--->>>





Step 5:
now select "Specify a custom SQL statement or stored procedure" option--->>
now in the,


SELECT TAB--->>> choose "stored procedure" option--->>
and select "sp_Select"


UPDATE TAB--->>> choose "stored procedure" option--->>
and select "sp_Update"



DELETE TAB--->>> choose "stored procedure" option--->>
and select "sp_Delete"



now give next--->>>finish.



Step 6:
now drag and drop a gridview control into the .aspx page

Step 7:
now click on the smart tag(">") of gridview-->>choose datasource options to

sqldatasource1--->>>
and also enable the check boxes such as
sorting,
paging,
editing,
deleting,
selection



thats it!!! now the run the program and see a gridview with

editing,deleting,selecting options working fine without writing a single code in

asp.net.

3 comments:

  1. This is too good and really helpful :)
    I wanted to know cn we insert data into gridview as we edit,update or delete it ?

    ReplyDelete
  2. very nice
    by mathes...
    but i also need the above should be done in code
    can u plz post me..

    ReplyDelete
  3. @Mathes: try this link http://vijayvigneshonflex.blogspot.com/p/linq_24.html

    ReplyDelete