开发者

How to read items during databinding which don't appear in GridView?

开发者 https://www.devze.com 2023-03-18 05:28 出处:网络
In ASP.NET, using a GridView control. Assume my SQLDataSource has an ID, Name and Address.I am only showing Name and Address in the grid, but I want to read the ID every time a row is databound to the

In ASP.NET, using a GridView control. Assume my SQLDataSource has an ID, Name and Address. I am only showing Name and Address in the grid, but I want to read the ID every time a row is databound to the grid. How woul开发者_如何学God I do this?

Thanks


The best way in these scenarios is to set the DatakeyName of your ID column in the GridView.

You may use it later on where you need DataKeyNames="ID"


You can bind the ID to a hiddenfield or to any control and make that control's visible property false.


What you need to do is get access to the underlying DataViewRow Object through the Gridview's RowDataBound Event. Once you have the DataViewRow you have access to the DataItem object this is the actual object your GridView is bound to. MSDN has an example here.

Cheers

0

精彩评论

暂无评论...
验证码 换一张
取 消