Basic operation of the gridview: Edit event: rowediting 1 protected void gridviewinclurowediting (Object sender, gridviewediteventargs E)
2 {
3gridview1. editindex = E. neweditindex;
4gridview_databind (); // you need to bind it again.
5}
Basic operation of the gridview: Update event: rowupdating 1 protected void gridview1_rowupdating (Object sender, gridviewupdateeventargs E)
2 {
3int click, score, times;
4 string name;
5
6if (Reg. ismatch (textbox) gridview1.rows [E. rowindex]. cells [3]. controls [0]). Text ))
7 {
8 click = int. parse (textbox) gridview1.rows [E. rowindex]. cells [3]. controls [0]). Text );
9}
10 else
11 {
12 click = int. parse (gridview1.rows [E. rowindex]. cells [3]. Text );
13}
14 // in the source code, the gridview is implemented using templatefield, but it can also be used to obtain the value of a cell.
15 // you can also use row [E. rowindex]. findcontrol ("Control ID") to obtain the control and perform type conversion.
16 score = int. parse (textbox) gridview1.rows [E. rowindex]. cells [2]. controls [0]). Text );
17 times = int. parse (textbox) gridview1.rows [E. rowindex]. cells [1]. controls [0]). Text );
18 name = gridview1.rows [E. rowindex]. cells [0]. text;
19 // call the database update Method
20 string message = GP. updatepinlun (click, times, score, name );
21 // disable edit mode
22gridview1. editindex =-1;
23 // rebind data
24gridview_databind ();
25}
Basic operation of the gridview: cancel the update event: rowcancelingedit 1 protected void gridview1_rowcancelingedit (Object sender, gridviewcancelediteventargs E)
2 {
3 // disable the editing mode
4gridview1. editindex =-1;
5 // Data Binding
6gridview_databind ();
7}