【问题标题】:How to populate an updateable FormView from an EntityDataSource with filter如何使用过滤器从 EntityDataSource 填充可更新的 FormView
【发布时间】:2009-06-29 01:46:12
【问题描述】:

我正在尝试创建一个用于更新帐户详细信息的会员页面。我想用成员的数据填充一个表单,但是我不知道如何在 EntityDataSource 上设置一个过滤器来限制查询。

当我根据成员 ID 设置 select 语句时,我得到了错误

Select cannot be set if EnableDelete, EnableInsert, or EnableUpdate is enabled.

我认为这是因为您无法更新投影或其他内容,但是这是否存在?

还是我必须在 Page_Load 中运行查询并自己填充表单?

【问题讨论】:

    标签: c# asp.net entity-framework formview entitydatasource


    【解决方案1】:

    不需要设置select,只需要设置where子句。

    您可以执行以下操作:

    <asp:EntityDataSource ID="MyDataSource" EntitySetName="Entity1" runat="server"
        ConnectionString="name=MyEntitiesConnString" EnableUpdate="true"
        DefaultContainerName="MyEntities" Where="it.MemberId= @MemberId" >
            <WhereParameters>
                <asp:QueryStringParameter DbType="Int32" Name="memberId" QueryStringField="memberid" />
            </WhereParameters>
    </asp:EntityDataSource>
    

    如果参数是通过查询字符串传入的。还有其他几种内置的 int 参数类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      相关资源
      最近更新 更多