我有一个GridView绑定到一个ObjectDataSource,包括一个复选框来选择网格中的一个项目。从gridview获取底层的ObjectDataSource
在CheckChanged事件我有一些像这样的代码:
//Clear the existing selected row
foreach (GridViewRow oldrow in uxRaceList.Rows)
{
var otherOpt = (RadioButton)oldrow.FindControl("rdbRaceNum");
if (otherOpt != sender)
otherOpt.Checked = false;
}
//Set the new selected row
RadioButton rb = (RadioButton)sender;
GridViewRow row = (GridViewRow)rb.NamingContainer;
((RadioButton)row.FindControl("rdbRaceNum")).Checked = true;
现在,我有到GridViewRow参考,是否有可能,我让我的OrigionalDataSourceObject?
我知道我可以在网格中显示的数据得到:
_selectedRaceNum = Convert.ToInt32(rb.Text.Substring(0, 1));
但我想是这样的:
VAR odsMyobject = row.DataItem为MyCustomObject;
我知道我可以在网格中存储一个ID并使用它回顾我的数据库以获取数据,但我希望避免数据的其他往返。
也许我可以以某种方式问ObjectDataSource的对象?
谢谢。
谢谢。我误解了DataSource对象会存在多长时间。 – Steve 2012-04-11 17:12:36