Question

Using the following markup, my details view is not populating when the dropdown is selected. The id for the where parameter is to come from the dropdwon selected value.It appears that the control parameter is not functioning properly.

<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>
Was it helpful?

Solution

Upon further research, which was tedious as there isn't a lot of the actual EntityDataSource control since all us probably do most of our EF work in the code behind, there were three issues

  1. I did not have a where attribute in the EDS markup
  2. The "Type" in the WhereParameter needs to be DBType
  3. The Name Attribute of the WhereParameter much match the variable in the Where statement in the EDS markup

Here is the code that works:

<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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top