Asp.net Gridview Edit Update using bound Field

Hello friends


In this example, we will see how to “Edit, Update and Delete GridView Using BoundField”

In this example, I am using Employee Table

Table script:

Source Code:


C# Code:

Data():  Method will fetch records from database and bind to gridview using boundField



GridView1_RowEditing: Event Will Send the selected row in Edit Mode Using

GridView1.EditIndex=e.NewEditIndex

And Again call the data() method

Once you click on Edit Button Dynamic textbox will generate for Each Column.





GridView1_RowUpdating: Event Will get all textbox values and update that 

record in the database

           (1)              (2)       (3)
GridView1.Rows[e.RowIndex].Cells[2].Controls[0]                                                                   
(1) e.rowsIndex will give currently selected row no

(2) It will Get the  Selected Row cell number 2

(3) In that cell select 1st control that is textbox

Like this, u will get all textbox values then just Concatenate those values In 

Update Query.



Change Some text & click on Update button


GridView1_RowCreated: Event Will fire for Each row which is going to bind

with gridview. In this Event, I’m Making EmpId column as a Read Only 

because EmpId is a 

Primary key column and while updating you need one Unique Column That’s 

why I made EmployeeId Column as Readonly(see in above image Employee Id 

is Read Only).

GridView1_RowCancelingEdit: Event will Cancel the Currently Edited Row

For canceling Current Operation just make GridView EditIndex to -1 and 

call data() method.

GridView1_RowDeleting: Event Will fire when you click on Delete button. 

Once you click on delete button it will get currently selected row and 

raise this event.

For deleting a record we need to get the EmpId id of that record.

 int Id =int.Parse(GridView1.Rows[e.RowIndex].Cells[1].Text);

Note: There are two ways of Editing and Updating Gridview rows.

In this article I explained it using BoundField In my Next Article I will show How to Edit Update GridView Using TemplateField. There are several ways for getting those dynamically generated textbox values we use that in different scenarios. If u have any queries regarding Grid View Post your comment or send mail on ranjeetpatil4545@gmail.com

Thank you

32 comments :

  1. Thank you Very much....
    -
    shivmidhin

    ReplyDelete
  2. its really good........
    Thank you

    ReplyDelete
  3. if i want to insert the data into a Boundfield
    then how can i will insert ???

    ReplyDelete
  4. I am really happy with your blog because your article is very unique and powerful for new reader.
    selenium training in chennai

    ReplyDelete
  5. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Blueprism training in Bangalore

    Blueprism training in Pune

    Blueprism training in Chennai

    ReplyDelete
  6. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

    angularjs

    Training in chennai


    angularjs-Training in chennai

    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    ReplyDelete
  7. Hello, I read your blog occasionally, and I own a similar one, and I was just wondering if you get a lot of spam remarks? If so how do you stop it, any plugin or anything you can advise? I get so much lately it’s driving me insane, so any assistance is very much appreciated.
    Android Training in Chennai | Best Android Training in Chennai
    Matlab Training in Chennai | Best Matlab Training in Chennai
    Best AWS Training in Chennai | AWS Training in Chennai
    Selenium Training in Chennai | Best Selenium Training in chennai
    Devops Course Training in Chennai | Best Devops Training in Chennai

    ReplyDelete
  8. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete
  9. Attend The Machine Learning Training in Bangalore From ExcelR. Practical Machine Learning Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Machine Learning Training in Bangalore.
    ExcelR Machine Learning Training in Bangalore

    ReplyDelete
  10. I can’t imagine that’s a great post. Thanks for sharing.

    Learn Best Microstrategy Training in Bangalore from Experts. Softgen Infotech offers the Best RPA Training in Bangalore.100% Placement Assistance, Live Classroom Sessions, Only Technical Profiles, 24x7 Lab Infrastructure Support.

    ReplyDelete
  11. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work.
    AWS training in chennai | AWS training in anna nagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery

    ReplyDelete
  12. wonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article resolved my all queries.thanks
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  13. I feel very grateful that i read this.It is very helpful and very informative and i really learned a lot from it.
    learn360digitmg artificial intelligence course

    ReplyDelete
  14. it's really cool blog. Linking is very useful thing.you have really helped
    360digitmg business analytics online course training

    ReplyDelete
  15. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.
    The people to give them a good shake to get your point and across the command.
    Java training in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Online Training

    ReplyDelete
  16. Thank you for sharing such a nice and interesting blog and really very helpful article.
    Want to become Oracle Recruiting Cloud Certified Specialist or Consultant? Attend this Best Oracle Recruiting Cloud Training course offered by the Unogeeks (Rated as Top Oracle Recruiting Cloud Training Institute in the market)

    ReplyDelete