0

Using the following markup, my details view is not populating when the dropdown is selected. where 参数的 id 来自 dropdwon 选择的值。看来控制参数没有正常工作。

<asp:UpdatePanel ID="updtEditContact" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="ddlContacttoEdit" runat="server" CssClass="dropdowns"
                      AutoPostBack="True" ClientIDMode="Static"/>
                <asp:DetailsView ID="dvEditContacts" runat="server" Height="50px" Width="125px"
                                 AutoGenerateEditButton="True" CssClass="mGrid"/>
                 <asp:EntityDataSource ID="edsSelectedContact" runat="server" ConnectionString="name=webEntities"
                                       DefaultContainerName="webEntities" EnableFlattening="False"
                                       EntitySetName="contacts">
                    <WhereParameters>
                       <asp:ControlParameter ControlID="ddlContactToEdit" Name="Id"
                            PropertyName="SelectedValue" Type="Int32" />
                    </WhereParameters>
                </asp:EntityDataSource>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="rblAddEditContact" EventName="SelectedIndexChanged"/>
                <asp:AsyncPostBackTrigger ControlID="ddlContacttoEdit" EventName="SelectedIndexChanged"/>
            </Triggers>
        </asp:UpdatePanel>
4

1 回答 1

1

经过进一步研究,这很乏味,因为没有很多实际的 EntityDataSource 控件,因为我们所有人可能在后面的代码中完成了大部分 EF 工作,存在三个问题

  1. 我在 EDS 标记中没有 where 属性
  2. WhereParameter 中的“Type”需要为 DBType
  3. WhereParameter 的 Name 属性与 EDS 标记中 Where 语句中的变量非常匹配

这是有效的代码:

<asp:UpdatePanel ID="updtEditContact" runat="server">
            <ContentTemplate>
                <asp:DropDownList ID="ddlContacttoEdit" runat="server" CssClass="dropdowns"
                      AutoPostBack="True" ClientIDMode="Static"/>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="rblAddEditContact" EventName="SelectedIndexChanged"/>
            </Triggers>
        </asp:UpdatePanel>
        <br />
        <asp:UpdatePanel ID="updatEditContactDetail" runat="server">
            <ContentTemplate>
                 <asp:DetailsView ID="dvEditContacts" runat="server" Height="50px" Width="300px"
                                  DataSourceID="edsSelectedContact" DataKeyNames="Id" Visible="False"
                                  CssClass="mDetail" FieldHeaderStyle-CssClass="fieldheader"
                                  ItemStyle-CssClass="itemvalues" CommandRowStyle-CssClass="cmdRow"
                                  EditRowStyle-CssClass="editvalues" ClientIDMode="Static"
                                  InsertRowStyle-CssClass="insertvalues" RowStyle-CssClass="rowvalues"/>
                 <asp:EntityDataSource ID="edsSelectedContact" runat="server" ConnectionString="name=webEntities"
                                       DefaultContainerName="webEntities" EnableFlattening="False"
                                       EntitySetName="contacts"  Where="it.Id = @ID">
                    <WhereParameters>
                       <asp:ControlParameter ControlID="ddlContactToEdit" Name="ID" PropertyName="SelectedValue" DbType="Int32"/>
                    </WhereParameters>
                </asp:EntityDataSource>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="ddlContacttoEdit" EventName="SelectedIndexChanged"/>
            </Triggers>
        </asp:UpdatePanel>
于 2013-08-20T08:41:20.773 回答