1
我有一個使用DataObjectType
(名稱)的ObjectDataSource
。在這種情況下,EmpRow
傳遞更新並插入參數,而不是傳遞單個參數。引用ObjectDataSource來自ObjectDataSource.OnUpdating事件的數據對象類型
ODS由FormView
使用,其中有兩個Multi Select ListBox
控件。因爲ListBox
控件只會傳遞一個選定的項目,所以我需要在數據源更新之前將所有選定的值正確添加到DataObject
。
所以在ObjectDataSource.OnUpdating
事件中,我想遍歷所選項目並調整傳遞給數據源更新方法的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;
}
好吧,我想通了。 EmpRow empRow =(EmpRow)e.InputParameters [0]; – bugzy 2010-11-02 16:28:30