使用以下标记,当选择下拉列表时,我的详细信息视图不会填充。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>
经过进一步的研究,由于没有太多实际的EntityDataSource控制,这很乏味,因为我们所有人可能都在代码后面完成了大部分EF工作,有三个问题
- 我在EDS标记中没有where属性
- WhereParameter中的"Type"需要为DBType
- 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>