【发布时间】:2010-03-09 16:14:49
【问题描述】:
数据绑定到复杂“对象”的格式是什么?我有一个包含包含的 linq to sql 类,即 object.containedobject。
我想引用子对象字段声明。
所以我尝试了我的 MySubField.MyBasicProperty,但没有成功,还有 MySubField_MyBasicProperty。
感谢您的帮助!
【问题讨论】:
标签: asp.net linq-to-sql data-binding
数据绑定到复杂“对象”的格式是什么?我有一个包含包含的 linq to sql 类,即 object.containedobject。
我想引用子对象字段声明。
所以我尝试了我的 MySubField.MyBasicProperty,但没有成功,还有 MySubField_MyBasicProperty。
感谢您的帮助!
【问题讨论】:
标签: asp.net linq-to-sql data-binding
我找到了答案,这是 boundfield 类的问题,而不是数据绑定的问题。
http://www.iridescence.no/post/FixingBoundFieldSupportforCompositeObjects.aspx
【讨论】:
我找到了解决方案并分享给未来追随我的人。
您需要重写 objectdatasource 更新方法来替换参数名称。这只有在未设置 objectdatasource 的 objectypename 属性时才有可能,否则它们将是只读的。
这是我的例子:
protected void ObjectDataSource1_Updating(object sender, ObjectDataSourceMethodEventArgs e)
{
foreach (string currentKey in e.InputParameters.Keys)
{
if (currentKey.Contains("."))
{
string newKey = currentKey.Replace(".", "_");
object myValue = null;
if (e.InputParameters[currentKey] != null)
myValue = e.InputParameters[newKey];
if (e.InputParameters.Contains(newKey))
e.InputParameters.Remove(newKey);
e.InputParameters.Add(newKey, myValue);
e.InputParameters.Remove(currentKey);
}
}
【讨论】: