【问题标题】:Databinding to a sub object declarative syntax?数据绑定到子对象声明性语法?
【发布时间】:2010-03-09 16:14:49
【问题描述】:

数据绑定到复杂“对象”的格式是什么?我有一个包含包含的 linq to sql 类,即 object.containedobject。

我想引用子对象字段声明。

所以我尝试了我的 MySubField.MyBasicProperty,但没有成功,还有 MySubField_MyBasicProperty。

感谢您的帮助!

【问题讨论】:

    标签: asp.net linq-to-sql data-binding


    【解决方案1】:

    我找到了答案,这是 boundfield 类的问题,而不是数据绑定的问题。

    http://www.iridescence.no/post/FixingBoundFieldSupportforCompositeObjects.aspx

    【讨论】:

    • 这引入了另一个问题,即更新不再起作用。有什么建议吗?
    【解决方案2】:

    我找到了解决方案并分享给未来追随我的人。

    您需要重写 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);
    
                }
            }
    

    【讨论】:

    • 另一件事,不应该修改 foreach 中的集合,以便修复。
    猜你喜欢
    • 1970-01-01
    • 2021-12-04
    • 2015-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-10
    • 1970-01-01
    相关资源
    最近更新 更多