我有一个使用DataObjectType (名称)的ObjectDataSource。在这种情况下,使用EmpRow传递更新和插入参数,而不是传递单个参数。
ODS由具有两个多选ListBox控件的FormView使用。因为ListBox控件将只传递一个选定的项,所以我需要在数据源更新之前将所有选定的值正确地添加到DataObject中。
因此,在ObjectDataSource.OnUpdating事件中,我希望迭代选定的项,并在传递给数据源更新方法的DataObject中调整适当的值。
我的问题是我不知道如何获得对dataobject的引用。看起来唯一的方法就是通过OrderedDictionary?是那么回事吗?我需要如何引用EmpRow对象并更新几个属性值?
有什么想法吗?
protected void dsDetail_Updating(object sender,
System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs e)
{
OrderedDictionary od = (OrderedDictionary) e.InputParameters;
IDictionaryEnumerator castRowEnum = (IDictionaryEnumerator)od.GetEnumerator();
//Now I somehow want to create an EmpRow object from the
//passed DataObjectType of the datasource
FormView fv = (FormView)FormView1;
ListBox lstLanguages = (ListBox)fv.Row.FindControl("lstSpokenLanguages");
ListBox lstSECPSTypes = (ListBox)fv.Row.FindControl("lstSECPSTypes");
string strSpokenLanguages = "";
string strSECPSTypes = "";
foreach (ListItem item in lstLanguages.Items)
{
if (item.Selected)
{
strSpokenLanguages += item.Value + ",";
}
}
strSpokenLanguages = strSpokenLanguages.Substring(0,
(strSpokenLanguages.Length - 1));
foreach (ListItem item in lstSECPSTypes.Items)
{
if (item.Selected)
{
strSECPSTypes += item.Value + ",";
}
}
strSECPSTypes = strSECPSTypes.Substring(0, (strSECPSTypes.Length - 1));
//now i need to assign these values to the proper data object properties
//EmpRow.cSECPSTypes = strSECPSTypes;
//EmpRow.cSpokenLanguages = strSpokenLanguages;
}发布于 2010-11-03 00:29:48
我已经得到了一个解决方案,那就是:
EmpRow empRow = (EmpRow) e.InputParameters[0];https://stackoverflow.com/questions/4078576
复制相似问题