简体   繁体   中英

Best way to fetch gridview row on row databound event?

Hi I was just wondering what is the best way to fetch gridview data using row databound event of gridview. I am previously used to Eval but read its not recommended as it uses reflection.

What do you mean "Fetch" the data, by the time the the RowDataBound event has triggered, there already has to be a row of data, that is why the event has executed. If you want to access and mapipulate the data then it is in e.Row.DataItem .

Edit

To answer your comment, using Eval in the markup and putting code in the RowDataBound event handler and accessing e.Row.DataItem tend to be used under different cirumstances. If all you want to do is take the data and bind it to the property of a control then using Eval() (or Bind() for that matter) is fine. However if you want to do something more complex then you might need to do it in the RowDataBound event handler. For exam-ple you might have a grid of customer accounts and ballances. For customers where thir ballances are overdue you might want to turn the row red to highlight the fact that thier accounts are overdue. You could not do that using Eval or Bind in the markup so you would check e.Row.DataItem in the RowDataBound event handler and then decide whether to change the colour of the row.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM