Two Methods for ASP. NET gridview to read hidden Columns

Source: Internet
Author: User

The gridview cannot hide the column visable = false like the DataGrid, so that the background cannot read the data of this hidden column. Today we have summarized two methods to solve this problem.

1. Use CSS

Add the following content to the CSS file:

. Hidden {display: none ;}
Then, in the column editing dialog box of the gridview, set the columns to be hidden and set the cssclass attribute of footstyle, headerstyle, and itemstyle to "hidden" respectively.

2. Use the properties of the gridview.

Although method 1 can be implemented, it seems that it is not a good method. In fact, it can be implemented by using the properties of the gridview itself, that is, the gridview has provided such a function.

First, set the datakeynames attribute (you can set multiple attributes) as follows:

<Asp: gridview id = "gridview1" runat = "server" datakeynames = "ID">

Then read, for example, the value of the ID of the row I to be read:
String id = gridviews1.datakeys [I] ["ID"]. tostring ();

Related Article

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.