Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to populate an updateable FormView from an EntityDataSource with filter

I'm trying to create a member page for updating account details. I want to populate a form with the member's data, but I don't know how to set a filter on the EntityDataSource to limit the query.

When I set the select statement based on the member ID, I get the error

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

I think this is because you can't update a projection or something, but is there anyway around this?

Or do I have to run a query in Page_Load and populate the form myself?

like image 711
John B Avatar asked Jun 29 '09 01:06

John B


1 Answers

There is no need to set the select, only the where clause.

You could do something like the following:

<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>

If the parameter is passed in by querystring. there are several other built-int parameter types as well.

like image 174
Merritt Avatar answered Oct 30 '22 06:10

Merritt