In this article I will explain how to insert, edit, update and delete data in gridview using asp.net.

Description:

I have one gridview I need to write code to insert data into gridview after that I need to edit that gridview data and update it and if I want to delete the record in grdview we need to delete record simply by click on delete button of particular row to achieve these functionalities I have used some of gridview events those are

11) Onrowcancelingedit

22) Onrowediting

33) Onrowupdating

44) Onrowcancelingedit

55) Onrowdeleting

By Using above griview events we can insert, edit, update and delete the data in gridview. My Question is how we can use these events in our coding before to see those details first design table in database and give name Employee_Details

If you having a problem at con.open() it is because there is no database. Right click on App_Data, and add new item . SQL Server Database and name it anything you want. Add a table, and add 4 columns, called UserID int (make this primary key and also make it auto increment by adjusting the column properties to Identity Specification to YES)and three others called UserName, City, Designation (all strings or nchar(40))Save this table as Employee_Details. Right click on the database and select properties. Copy the whole connection string and paste into line #17 where the string starts with Data Source=. When you start the sample it should run!

@Rajeev Ranjan...That problem because of you mentioned column datatype as int and sending string values to that column. i think you forgot to change your stored procedure datatype int to varchar check it once...

sir how can i display only one row which is click for edit..bcoz the grid view of my database is so long and when i press edit for last row it wil disply in edit mode but the page will move to up so we scroll down the page where i choose for edit the row

this is working very fastly but i have one problm whne grid contains much record then it get scrolled ,i want that footer is going to be fixed.so how to fix the footer in above grid plz rly sir...its urgent

Hi,your coding is very useful. I made some modification in the above coding I feel one difficulty. That is I added a button or a dropdownlist with autopostback set as true. Initially the gridview is empty and thus "No Records Found" message is shown. When I select any item from the dropdownlist or button click an empty row with Item Template controls(edit and delete) at 1st row position by the gridview.please give me a solution for avoiding this auto post back problem.Thank you...

Wow! just posting the comment gives user google account details and link to user blog to the website. This is wonderful. How did you do this? How can I achieve this in my website? I am new to asp.net and programmer in C#. Moreover there is sign out option too. Does that make user sign out of google?

Suresh garu your examples are soooo good, i have a small doubt,if there is in(sql data base) no of particles like name ,date, dob etc. so, my requirement is ,i need two of them only. Is it possible in Grid view. Please Post Your answer.

hi i need help. when start w/o debugging i have this error Invalid object name 'Employee_Details'Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Suresh, I'm not an ASP developer, but was able to put an ASPX page together some time ago that does just this that you showed. It runs smoothly when under VS IDE, but when I deploy it to GoDaddy's server, it pops the following error :

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

I'm willing to pay for you to correct this and leave this page running fast when deployed. My e-mail is epastorejr(arr)hotmail(dot)com, please get in touch. Regards, Emilio.

IMAGES edit/delete continously refresh after insert ing one record so its little bit disturbing pleasetell me solution i used update panel but does not work another point i want enter instead of tab about navigation

I want to make a DLL which recive some information and errors from another application and display it on text file named error.txtscenerio ------------------------------------------------Some Information Processed and displayed

------------------------------------------------Repeat this step Each time client Application Call this DLL

I don't know sir ,if you are still replying at this site as your last reply was at Oct 6,2012. Still if you can assist please help,i couldnt find ts solution even at google,and other places still.and am a beginner in asp.net. am getting this following error,how should i remove this?"Validation(XHTML 1.0 Transitional):Element 'panel' is not supported."

I am having trouble whle following this example. I have a dropdownlist that populates with the column names of the table and a text box. I sucessfully search for records that only match the type input and rebind with no issues. Now if I try to use the edit or delete buttons the page crashes with the error:

Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

all my research points to the IsPostback but if that were the case my postback from my search field wouldn't work either. Help

changed the buttons from Image buttons to Link buttons and that works, however there is one more issue. I set the CommandName on the AddNew button and I enter the new data in the footer, but upon stepping through the code I see that the fields being returned is "{System.Web.UI.WebControls.TextBox}", not sure what I missed. I even tried just storing them in a string variable, no luck.

Hi, i want to perform update,delete and insert options using MVC 4,after performing the operations it should be displayed in gridview and should be updated in the database,how can i do that,please let me know i need it ASAP...any help would be appreciated..Thankyou so much,Bhavani.

I want to insert,update ,delete,in gridview. But Here only we can bind the data,, but i need images also to be binded in gridview with the help of fileupload control.Inside the footer template only i need fileupload control to be accessed..

i need a help for this...i have 3 radio buttons in gridview...how can i update data using radio buttons...without radio button thats not a problem...using radio buttons how can i update data in asp.net with c#

sir, suppose there are 2 pages and on click of some hyperlink the control goes to next page.

in the next page i'm inserting some data and once i click the submit button, the details are stored in the database and immediately the control should go to the 1st page... not knowing how to go about it.

I want to insert,update ,delete,in gridview. But Here only we can bind the data,, but i need images also to be binded in gridview with the help of fileupload control.Inside the footer template only i need fileupload control to be accessed.. Please can u help me... Thank you...

hello sir, there is problem in binding of gridview with empty data. if i use your code and there is no data in table then EDIT and DELETE botton automatically appears and create problem if i click on that buttons. Is there any code so that i can hide those buttons an can display only empty Griedview.

Sir,I have tried it in entity framework too but it didn't work for me.problem is when gridview is empty at that time gridview not showing the footer.And using entity framework how to show the no record found msg in gridview?

I am fresher. I am doing one small medical application which has around 29 fields in database.. I want to use a grid view, only for few fields.. Is it possible? If yes, then how to do... Database is oracle 10g.

Create a employee table, designation table, as soon as we select designation form dropdown list according to that the employee name should be display in grid view. The grid should be fully editable all facilities should be there. Take 5 designation names in table.Use stored procedure.

TextBox txtR_adderss = (TextBox)gvDetails.Rows[e.RowIndex].FindControl("txtR_adderss");in this line :-e.RowIndex gives error .. so pl if possible beacouse it does not contayins in the cureent contecst on update and add new button. thak u pl ... sir

hello sir,I'm kohila. your each and every code run successfully.but, in my project i have to save gridview data and other textbox data at the same time,in a single table. please give me sample code for these. please do it for me sir.i hope many people get useful if you post that code.thank you sir. here my email-id: kohilavani2011@gmail.com.Thank you sir.