Updating, Deleting records using Grid. View control. In this article, I am going to explain how to manipulate data using Grid. View control. This article scope is limited to Updating and Deleting records using Grid. View and I am not using any readymade Data controls for that but manually writing all event methods. I will be using Sql objects directly into methods to keep the example simple and straight forward. In practical scenario you should use your existing architecture to populate and update the data. In this article, I am going to take a simple database table that has following fields. In this C# tutorial, you will learn to use the Entity Framework to add, delete, and edit rows or records of a table in SQL Server database. Auto. ID - Int, Auto. Increment, Primary Key. Page. Name - Varchar(5. Page. Description - Varchar(5. Active - Bit(1). In this article, I am not going to explain the workings of Sql objects but focusing on the events and methods of the Grid. View that will help us in updating and deleting the records. Now let’s start with putting the Grid. View on . aspx page. Following is the code for the Grid. View. I have specified Data. Key. Names as Auto. ID, the primary key of the database table. ![]() This demo is a continuation of my previous example “Binding GridView with Data”. If you are not familiar of binding the GridView the ado.net way then I would. If you use the GridView to display large sets of data, see Optimize ListView and GridView for tips to maintain a smooth and responsive user experience. Then I have several methods attached with following events. Get video of hundreds of ASP. NET Tips and Tricks - http: //www. Show/5. 0 . So I have to specify how I want them to appear in the normal view and edit view. That’s why I have placed different templates like Item. Template (for normal view) and Edit. Item. Template (for edit view). You can notice that I have kept Required. Field. Validator too inside the Edit. Very good article about data grid view.Item. Template as I want the textbox to be validated for empty data. In the same way you can put any kind of Validation controls inside Edit. Item. Template to validate the form element while user will click Update link. For Page. Name and Page. Description field I want them to appear in the Text. Box in edit view, so I have specified text property of Text. Box as the field value in Edit. Item. Template and for Active field, I want it to appear as the Drop. Down. List so I have specified the Selected. Value property as the value of the Active field. This will make sure that Bind. Data() method will not fire when you are going to edit, update or delete the record. In this method, I am specifying the Edit. Index property of the Grid. View to the New. Edit. Index of the Grid. View and then calling Bind. Data() method again to bind the data. Please note that when you will not bind the data again, Grid. View will not change in edit mode. In this method, I am specifying the Edit. Index property of the Grid. View to - 1. As there is no row at - 1 position so Grid. View will be shown in normal mode. In this method, we have to get changed values of Text. Box and Drop. Down list and also we need the primary key value for the record that is being edited. To get the Primary key, I have used Data. Keys property of the Grid. View with the index of the row, being edited and stored into a integer variable after parsing. With the help row variable, I am going to find all the controls placed under that row in edit mode using Find. Control property. After finding the controls I am using them to pass their values to the parameter of the Sql. Command object that is ultimately updating the records into database. After that again, I am doing the same thing that I had done in Cancel. Record method, I mean setting Edit. Index property of the Grid. View to - 1 and rebinding the data again by calling Bind. Data() method. In this method again, I am getting the primary key value using Data. Keys property of the Grid. View and using it to delete the records from the database. After successfully deleting records, again I am calling Bind. Data() method to rebind the Grid. View. If you have a feedback or suggestion, please do write to me. Edit, Update, Delete Gridview using 3 - tier in ASP. Net C#In previous asp. Presentation Layer, Business Logic Layer and Data Access Layer. Now, In this asp. STEP 1 : Create ASP. Net web application. First open the visual studio and create a new asp. File menu –> New –> Website. Select ASP. Net web site and declare name “Three. Example” as website name. Create ASP. Net three tier architecture web application. Here, we have created asp. STEP 2 : Design the default. Registration. Now, design the default. The first column is ID which is identification of user, so it must be unique. Here we set ID column Primary Key and Auto. Increment by updating the ID column property. After creating new table create new stored procedure for Insert records, Select records, Update and Delete records. Stored Procedure for SELECT. ANSI. There are many methods developer uses for sql connectivity. Create new Data. Set in Data Layer Class Library project and bind select and insert stored procedure in Data. Set. Data. Layer –> Add –> New Item –> Data. Set. ADD New Data. Set in Data Layer for sql database connectivityset the new dataset name as “DS. Create new Table Adapter in Data. Set and bind select and inset stored procedure. Make connection between asp. Data. Set. Finish above dataset wizard with bind select, insert, update and delete stored procedure with it. After binding all stored procedure we have connection string in web. STEP 6 : write code in Data Access Layer. System. Collections. Generic. using System. Linq. using System. Text. using System. Configuration. using System. Data; using System. Data. Sql. Client. Data. Layer. . Here creating new class library project named “Businees. Layer”. Create New Class Library project Business Logic Layer in asp. Now, we have see the three tier architecture in our application clearly. Three tier architecture example in asp. Now, after creating business layer class library import namespace of database layer by adding references manually as show below: Business. Layer –> References –> Add References –> Project –> Data. Layer. Add data access class references to business layer. Add data access class references to business layer. After importing references create data layer class object in business logic layer class. Data. Layer. using System. Collections. Generic. System. Linq. using System. Text. using Data. Layer. namespace Business.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
August 2017
Categories |