. NET 2.0 web control gridview is rarely used, compared with the advantages of 1.0 DataGrid has not been found, it found a weak place, for each row of Data primary keys are generally stored with hidden columns, the original hidden columns of the DataGrid can be obtained in the DataGrid event, while the gridview does not assign values to hidden columns, in the event, operations on the specified row of data could not obtain the data corresponding to the row in the database. I don't know if it is a degradation, so I had to find a way to avoid detours.
The Edit/delete operation is generally triggered by the button control in the template column. Therefore, you can assign the primary key value to the event optional parameter commandargument of the button control in the rowdatabound event.
1 protected void grvtest_rowdatabound (Object sender, gridviewroweventargs e ){
2 linkbutton lnk = E. Row. findcontrol ("lnksignup") as linkbutton;
3
4 If (lnk! = NULL ){
5 lnk. Attributes. Add ("onclick", "Return confirmsignup ()");
6 lnk. Visible = true;
7 lnk. commandargument = E. Row. cells [0]. text;
8}
9}
Then, in the rowcommand event, obtain the commandargument attribute value of parameter E.
1 protected void grvreport_rowcommand (Object sender, gridviewcommandeventargs e ){
2 string id = convert. tostring (E. commandargument );
3
4}