how to get one column value in repeater_itemdatabound event?
I use repeater in my asp.net application to display records from database. The datasource that binded to 开发者_运维技巧repeater are records of a datatable.
How can I get one column value for an item in repeater's itemdatabound event?
I want to get a value of column called 'id'. How to get it in the repeater_itemdatabound event in backend?
In the Repeaters ItemDataBound event, you can extract the object bound to the item via the e.Item.DataItem
property, and do:
var item = e.Item.DataItem as MyObject;
if (item.ID > 0)
//Do something
In the item databound event you have access to the event arguments (variable e) e.Item.DataItem is the record that is currently being bound. Be sure to cast it as a DataRow or whatever the type is of the item in the collection being bound.
You could access the ID column
Dim dr As System.Data.DataRow = DirectCast(e.Item.DataItem, System.Data.DataRow)
Dim id As Int64 = dr("ID")
精彩评论