【问题标题】:ASP.NET ModelBinding Complex Objects / Nested ListViewsASP.NET 模型绑定复杂对象/嵌套列表视图
【发布时间】:2014-03-20 03:09:43
【问题描述】:

我想使用 asp.net webforms 模型绑定并在列表视图中嵌套一个列表视图。这可能吗?

目前我已经在父级上设置了 DataKeyNames 并在 SelectMethod 中使用 [Control] 属性,并且该方法在父级中的每一行都被调用,但参数为空。

如有任何帮助,我们将不胜感激。

<asp:ListView ID="Topics" runat="server"
    ItemType="Topic"
    SelectMethod="Topics_GetData"
    DataKeyNames="ID" >
    <EmptyDataTemplate>
                <div class="notice">
                    There are no Questions.
                </div>
            </EmptyDataTemplate>
    <ItemTemplate>
        <div><%# Item.TopicName %></div>

        <asp:ListView ID="QuestionSetListView" runat="server"
            ItemType="Question"
            SelectMethod="QuestionListView_GetData"
                 DataKeyNames="ID">
                <EmptyDataTemplate>
                    <div class="notice">
                        There are no Questions.
                    </div>
                </EmptyDataTemplate> ...

选择方法:

QuestionListView_GetData([Control("Topics")] int? ID)

有什么想法吗?

谢谢

【问题讨论】:

    标签: c# asp.net listview


    【解决方案1】:

    很高兴看到有人用 Web 窗体模型绑定做很酷的事情。 你绝对可以做到,你只需要使用一个 HiddenField 来保存你的 ID,

    <div><%# Item.TopicName %></div>
    <asp:HiddenField ID="TopicID" runat="server" Value="<%# Item.ID %>" />
    <asp:ListView ID="QuestionSetListView" runat="server"
    

    然后在你的控件属性中引用TopicID

    QuestionListView_GetData([Control("TopicID")] int? ID)
    

    【讨论】:

    • 很好!!!现在我需要弄清楚如何使用 formview 将这些对象插入到数据库中。
    • 很高兴您喜欢它,FormView 的工作原理几乎相同。如果您有兴趣,我已经在 ListView 中使用 FormView 做了一些示例?查看我的“VS 2013.zip 的导航标识”示例,地址为navigation.codeplex.com/documentation
    猜你喜欢
    • 1970-01-01
    • 2013-04-24
    • 2013-08-24
    • 2013-07-08
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 2015-04-14
    相关资源
    最近更新 更多