Asp. NET Edit and update data (non-GridView control implementation)

Source: Internet
Author: User

Insus.net in the implementation of the ASP. NET development, from two to three layers, to object-oriented (5) http://www.cnblogs.com/insus/p/3880606.html, did not put the data editing and updating function to demonstrate, left to users to play freely, But there are netizens want to see insus.net with the implementation method.

The previous practice of insus.net is done in the GridView control. As in this video tutorial, "GridView Edit Update Cancel Delete" http://www.cnblogs.com/insus/archive/2011/01/25/1944295.html

or whether the website has music function http://www.cnblogs.com/insus/archive/2013/05/09/3066347.html can see the update function of the GridView control.


Summing up previous experience, feel that editing or updating the GridView control's record, users need to click multiple buttons to complete. There are also many code written for the GridView control. So insus.net wants to directly click on a record of the GridView control and then display it in the added domain to update it.

OK, start to see:
First add a column to the GridView control:



Then after adding the button, add two ammonium buttons, one is the update, the other is cancel:


These two ammonium buttons, at first its state is disabled, can see their enabled= "false". This means that the two ammonium buttons are not available when the page is loaded.
Next, we implement onrowcreated= "gridviewemployee_rowcreated" respectively, onclick= "Buttonupdate_click" and onclick= "Buttoncancel_ Click "Event. First, when you click a record in the GridView control, you want to get the record data. So you need to create a new stored procedure by the primary key to get a click on the current record:



There is a stored procedure with the database layer added, and the previous written Employee.cs also needs to add the appropriate logical method or function.


can now be written:



There is an event delegate Buttonedit_click:



Above the program has a few instructions, first click on Edit, get the selected record primary key, Then the primary key is to get the whole record and then bind to the Add domain (tag 1). Tag 2, you need to disable the Add Ammonium button and the text box that binds the primary key. The
Tag 3 is active update and cancels the ammonium button.

The following is the cancellation of the Ammonium Buttoncancel_click event, which is actually initializing the control state function:



text box empty, the Disabled Ammonium button is disabled, the enabled Ammonium button is enabled. Finally, update the Ammonium button Buttonupdate_click event:


See no, cancel the ammonium button and after the update event ends, the code executed is the same. So they can be written in a single, small way:



Finished, look at the real-time operation demo effect, click on the "Edit" ammonium button, it has an exception:
line:885
Error:Sys.WebForms.PageRequestManagerServerErrorException:Object reference not set to a instance of an Object.


F9 set the break point, F5debug, and then press F11 to track, ran to the following exception:


Careful inspection, the original real problem, appears in the BizBaseSQLSp.cs class library, the function public DataSet executedataset (), the following is the correct method to modify:



Save and run again:



No difficulty, so, when you design a Web page, you can add the domain and edit the same, do not waste in the GridView control, but also define the editing template.


Although the insus.net is not a masterpiece, the ordinary can let you get to the ASP. NET technology has been improved and accumulated, sufficient.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.