Community discussion forum

DropDownList inside of EditItemTemplate inside of DetailsView :P

  • 3 years ago

    Hey everyone!

    I have a DetailsView control, with an EditItemTemplate, and inside that..i have a DropDownList.  The DropDownList is full of Roles that a user is currently NOT a member of, and I want to allow a person to select a role from the dropdownlist, click the "Update" button...and add the user to the role.

    Everytime I try this, I'm getting the error: Could not find control 'DropDownList2' in ControlParameter 'ID'.

    Here is the ASP code!

    <

    asp:DetailsView ID="DetailsView2" runat="server" GridLines="None" DataKeyNames="ID"

                                    DataSourceID="sqlGetAllRolesNot" AutoGenerateRows="False">

             <Fields>

                         <asp:TemplateField ControlStyle-BorderStyle="None" HeaderStyle-BorderStyle="None"

                                                             ItemStyle-BorderStyle="None" FooterStyle-BorderStyle="None">

                                     <ItemTemplate>

                                     </ItemTemplate>

                                      <EditItemTemplate>

                                                             <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="sqlGetAllRolesNot"

                                                                                                          DataTextField="Name" DataValueField="ID" />

                                     </EditItemTemplate>

                        </asp:TemplateField>

                      <asp:CommandField ShowEditButton="True" EditText="Add Role" />

                </Fields>

     </asp:DetailsView>

    <

    asp:SqlDataSource ID="sqlGetAllRolesNot" runat="server" ConnectionString="<%$ ConnectionStrings:mySqlConnection %>"

                SelectCommand="SELECT Role.ID AS ID, Role.Name AS Name

                                                 FROM Role WHERE NOT EXISTS(SELECT UserRole.Role_ID FROM UserRole

                                                 INNER JOIN Users ON Users.ID = UserRole.User_ID

                                                WHERE Role.ID = UserRole.Role_ID AND Users.ID = @ID)"

             UpdateCommand="INSERT INTO UserRole(User_ID, Role_ID) VALUES (@User_ID, @Role_ID)">

    <SelectParameters>

                <asp:ControlParameter ControlID="DropDownList1" Name="ID" PropertyName="SelectedValue" />

    </SelectParameters>

    <UpdateParameters>

                <asp:ControlParameter ControlID="DropDownList1" Name="User_ID" PropertyName="SelectedValue" />

                <asp:ControlParameter ControlID="DropDownList2" Name="ID" PropertyName="SelectedValue" />

    </UpdateParameters>

    </asp:SqlDataSource>

     

    Can anyone help??????

    Thanks in advance!

  • 3 years ago

    I think that the ID of your "DropDownList2" is wrong. The ID of this controller should be "Role_ID", not just "ID", so when you choose submit, the datasource will substitude the @Role_ID to the DropDownList2, but the it can not find the DropDownList2 through the wrong ID

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback