Record the value of hidden columns in the gridview

Source: Internet
Author: User

In short:

When visable = false is set for a column in the gridview, data binding is affected and data cannot be obtained. In general, we need to hide the ID column.

Solution:

Specify the following when binding background data:

This. gridview1.datakeynames = new string [] {"ID "};

Or edit datakeynames: ID in the property editor. If two columns need to be hidden and the value is required, separate each field with "," In datakeynames.

Next we will retrieve the data:

If there is only one keyword, that is, datakeynames has only one value, you can use:

This. gridview1.datakeys [E. rowindex]. value. tostring ();

This method is to take the value of the key word with the index 0 in the datakeynames in the current row, that is, the value of the first keyword. Of course, it doesn't matter if there is only one keyword.

You can also use:

This. gridview1.datakeys [E. rowindex] ["ID"]. tostring ();

If there are multiple keywords, you can only use the following method.

Simple record. For future query.

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.