I am working on a Dynamic Data website and I have run into a wall. I have a Details page where the details for each employee can be seen, and then I have a separate page to edit each employee. I did this because I need to use DropDownList boxes for Department and Job in each department. Nevertheless, I am having trouble accessing the department ddl and I think it is because it is inside an EditItemTemplate. Here is what I have:
<asp:DetailsView ID="dvEmployee"
DataSourceID="EmpDVds"
AutoGenerateRows="false"
DataKeyNames="Id"
GridLines="None"
CellSpacing="10"
runat="server" DefaultMode="Edit">
<Fields>
<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Department: ">
<EditItemTemplate>
<asp:DropDownList ID="ddlDept" DataSourceID="DeptDDLds" DataTextField = "DepartmentName" DataValueField = "Id" runat="server" SelectedValue='<%#Bind("DeptID") %>' />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Job Code: ">
<EditItemTemplate>
<asp:DropDownList ID="ddlJob" DataSourceID="JobDDLds" DataTextField = "JobName" DataValueField = "Id" runat="server" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
Then I am trying to use the ddlDept SelectedValue to populate the ddlJob. Here is the DataSource I am trying to use.
<asp:SqlDataSource ID="JobDDLds"
SelectCommand="
SELECT
Id,
Code+' - '+[Desc] AS JobName,
Department_Id
FROM
JobCodes
WHERE
JobCodes.Department_Id = @DeptID"
ConnectionString="<%$ConnectionStrings:TrainingDatabaseConnection %>" runat="server" >
<SelectParameters>
<asp:ControlParameter ControlID="ddlDept" PropertyName="SelectedValue"
Name="DeptID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
I know that the format of the Select parameter is correct because I am using another ddl to populate the DetailsView and I know the relationship between Departments and JobCodes is correct because I am using it successfully in and AddEmployee page.
Here is the error I get:
Could not find control 'ddlDept' in ControlParameter 'DeptID'.
I am I correct in assuming that it cannot access the ddlDept by it's ID because it is in the EditItemTemplate? How can I fix this? Other suggestions on how to achieve this? Any and all help is greatly appreciated.
I found this link helps to solve without server side: Solving the error "Could not find control 'xxx' in ControlParameter 'xxx'."
the author says that you can use the dollar char ($) to access the inner control.
Ex:
ControlID="dvEmployee$ddlDept"
will get the value of ddlDept that is a inner control of dvEmployee