This blog is based on examples in the book to implementUse gridview and detailsviewNo refreshing data editing effect. Page effect: When you click a row in gridview1 or a new pageThe Data Binding of detailsview1 is displayed on the page.Detailsview1. rebinding of gridview1 is also triggered when you edit, delete, or add it. The entire page is refreshed.
Page Layout:
1. Create an Ajax window named"Norefreshedit. aspx". Two updatepanel methods must be used to implement no-refreshing page editing.
2. InNorefreshedit. aspxAdd a table with one row and two columns to the page and put an updatepanel in each cell.
3. Add a table to updatepanel1. It is better to add a table with a large number of data so that you can see the effect of page refreshing. What I use isTb_infoTable, as I used to do, directly drag it into updatepanel1 and automatically generate the bound gridview1 and sqlperformance1. enable the selection and paging functions in gridview1.
4. Place a sqlperformance2 in updatepanel2 and bind the sqlperformance2 connection stringTb_infoStart to configure sqlperformance2. Click the "advanced" button, select the insert, update, and delete statements, and click the "where" button to bind the ID toSelectedvalueThe ID of the event.
5. Drag and Drop a detailsview1 file into updatepanel2 and set the data source of detailsview1 to sqlperformance2 to enable editing, deletion, and insertion.
6. Change the updatemode attribute of updatepanel1 to conditional, change the updatemode attribute of updatepanel2 to conditional, and add two async-PostBack in triggers of updatepanel2. The controlid is gridview1 and the eventname isSelectedindexchangedAndPageindexchangedThat is, when the row and page number of gridview1 are changed, the updatepanel2 is refreshed and the detailsview1 is also displayed.
The page layout is here. Let's take a look at CSCode:
When you update, delete, and insert the detailsview1 code without refreshing the new edit code, rebind gridview1 and refresh updatepanel1.
1 Public Partial Class Norefreshedit: system. Web. UI. Page
2 {
3 Protected Void Page_load ( Object Sender, eventargs E)
4 {
5
6}
7 Protected Void Detailsviewincluitemdeleted ( Object Sender, detailsviewdeletedeventargs E)
8 {
9Gridview1.databind ();
10Updatepanel1.update ();
11}
12 Protected Void Detailsviewincluiteminserted ( Object Sender, detailsviewinsertedeventargs E)
13 {
14Gridview1.databind ();
15Updatepanel1.update ();
16}
17 Protected Void Detailsviewincluitemupdated ( Object Sender, detailsviewupdatedeventargs E)
18 {
19Gridview1.databind ();
20Updatepanel1.update ();
21}
22 }
23
The two lines of code should be written for two reasons: 1. detailsview1 is not the triggers of updatepanel1, so any of its actions will not refresh the updatepanel1 control, 2. even if detailsview1 becomes the triggers of updatepanel1, its action can cause updatepanel1 to refresh. When updatepanel1 is refreshed, the previous list is continuously displayed because the gridview1 control is not rebound to sqlperformance1. So we need to refresh updatepanel1 and rebind gridview1.
When updatepanel's updatemode is changed to conditional, in addition to setting in triggers to request the time to refreshProgramCall the UPDATE function in the code to refresh the updatepanel.