Use of the. NET 2.0 web control gridview: How to Use hidden primary key columns

Source: Internet
Author: User

. 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}

 

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.