Thursday, May 31, 2007

How to handle hidden columns/values in gridview 2.0?


It is always a "Fact" that we are not supposed to disclose any confidential data to the browser, whether it is a primary key or not. At the same time we may need those values for further processing of the page logic. In datagrid (.net 1.1), we always used to get the hidden values in the viewstate and we can make use of those values in client side script.


However, the situation is changed now!. Due to security breach, microsoft has come up with new term "DataKeys" in order to hide the hidden fields forever (from rendering). You cannot see the hidden column values in View State. At the sametime, you can have multiple datakeys for a particular gridview control. Doing so, you can extract the values of those fields against each row, but only from code behind as it is not rendered in the browser.

You can access the values as below :

where 'i' represent the rownumber and 'j' represent the index of DataKeys (defined).


No comments: