asp.net - Get original object from DataRow in GridView C# -
i try display collection (ienumerable
) of objects (generated via linq sql). therefore bind gridview
s datasource
property generated output of linq sql method. in selectedindexchanged
event of gridview
try convert selected rows dataitem
original object end null
value instead.
here code:
protected void page_load(object sender, eventargs e) { rldatacontext dc = new rldatacontext(); this.dgvreports.datasource = dc.getreports(1); this.dgvreports.databind(); } protected void dgvreports_selectedindexchanged(object sender, eventargs e) { if (this.dgvreports.selectedindex >= 0) { report rpt = (report)this.dgvreports.selectedrow.dataitem; } }
the return type of getreports isingleresult<report>
use bindingsource between datagridview , list. when selection made datagridview use bindingsource's current
property right item list.
Comments
Post a Comment