I need some help. I have a detailsview and it has several different fields in it. The fields I am having a problem with it the dropdownlist. I have two dropdownlist, one that is dependent on the other. That works fine. But now when I try to insert the selected items into my DB it takes the value of the first dropdownlist fine but the second one it just keeps inputting Select Dept Code, which is my default value. I know that I am selecting something, but it just will not take it. I will paste my asp.net and my c# code. Please help. Thank you.

<asp:DetailsView ID="AddRequestDetailsView" runat="server" Height="110px" Width="508px"
        DataSourceID="EnterRequestDS" AutoGenerateRows="False" CellPadding="4" DataKeyNames="rAuid"
        DefaultMode="Insert" ForeColor="#333333" GridLines="None" 
    EnableViewState="False" oniteminserting="AddRequestDetailsView_ItemInserting">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
        <EditRowStyle BackColor="#999999" />
        <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
        <Fields>
            <asp:BoundField DataField="rAuid" HeaderText="rAuid" InsertVisible="False" ReadOnly="True"
                ShowHeader="False" SortExpression="rAuid" />
            <asp:BoundField DataField="internalId" HeaderText="internalId" InsertVisible="False"
                SortExpression="internalId" />
            <asp:TemplateField HeaderText="Employee First Name" SortExpression="Employee First Name">
                <InsertItemTemplate>
                    <asp:TextBox ID="firstNameTxt" runat="server" Text='<%# Bind("employeeFirstName") %>'></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Employee Middle Name" SortExpression="Employee Middle Name">
                <InsertItemTemplate>
                    <asp:TextBox ID="middleNameTxt" runat="server" Text='<%# Bind("employeeMiddleName") %>'></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Employee Last Name" SortExpression="Employee Last Name">
                <InsertItemTemplate>
                    <asp:TextBox ID="lastNameTxt" runat="server" Text='<%# Bind("employeeLastName") %>'></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Employee Start Date" SortExpression="Employee Start Date">
                <InsertItemTemplate>
                    <asp:TextBox ID="startDateTxt" runat="server" AutoPostBack="false" Text='<%# Bind("startDate") %>'></asp:TextBox>
                    <asp:ImageButton ID="calendarImageBtn" runat="server" ImageUrl="~/Images/Calendar_schedule.png"
                        OnClick="calendarImageBtn_Click" CausesValidation="False" />
                    <asp:Calendar ID="startDateCalendar" runat="server" Visible="false" SelectedDate=""
                        SelectionMode="Day" OnSelectionChanged="startDateCalendar_SelectionChanged" BackColor="#99CCFF"
                        TitleStyle-BackColor="White"></asp:Calendar>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Department Code" SortExpression="Department Code">
                <InsertItemTemplate>
                    <asp:DropDownList ID="departmentCodeDDL" runat="server" DataValueField="deptCode" AppendDataBoundItems = "true"
                        AutoPostBack="True" DataBound="MyListDataBound" DataSourceID="DeptSqlDS" DataTextField="deptCode">
                        <asp:ListItem>Select Dept Code</asp:ListItem> 

                    </asp:DropDownList>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Job Code" SortExpression="Job Code">
                <InsertItemTemplate>
                    <asp:DropDownList ID="jobCodeDDL" runat="server" AutoPostBack="False" DataTextField="jobCode" AppendDataBoundItems = "true"
                        DataValueField="jobCode" DataSourceID="jobSqlDS" OnSelectedIndexChanged="jobCodeDDL_SelectedIndexChanged"
                        DataBound="MyListDataBound2" EnableViewState="True">
                        <asp:ListItem>Select Dept Code</asp:ListItem> 
                    </asp:DropDownList>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Job Title" SortExpression="Job Title">
                <InsertItemTemplate>
                    <asp:Label runat="server" Text="" ID="jobTitleLabel"></asp:Label>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:RadioButton ID="standardProfileRB" runat="server" GroupName="Profile" Text="Standard Profile for this Job Code" /><br />
                    <asp:RadioButton ID="customProfileRB" runat="server" GroupName="Profile" Text="Custom Request" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Special Notes" SortExpression="Special Notes">
                <InsertItemTemplate>
                    <asp:TextBox ID="specialNotesTxt" runat="server" Text='<%# Bind("specialNotes") %>'
                        TextMode="MultiLine" Height="100" Width="300"></asp:TextBox>
                </InsertItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <InsertItemTemplate>
                    <asp:Button ID="submitBtn" runat="server" CausesValidation="False" CommandName="Insert"
                        Text="Submit" />
                </InsertItemTemplate>
            </asp:TemplateField>
        </Fields>
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
    </asp:DetailsView>
    <asp:SqlDataSource ID="DeptSqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:UserAccessConnectionString %>"
        SelectCommand="SELECT DISTINCT  [deptCode] FROM [DeptJobCode]"></asp:SqlDataSource>
    <asp:SqlDataSource ID="jobSqlDS" runat="server" ConnectionString="<%$ ConnectionStrings:UserAccessConnectionString %>"
        SelectCommand="SELECT [jobCode] FROM [DeptJobCode] where [deptCode] = @deptcode">
        <SelectParameters>
            <asp:ControlParameter ControlID="AddRequestDetailsView$departmentCodeDDL" Name="deptcode"
                PropertyName="SelectedValue" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:ObjectDataSource ID="EnterRequestDS" runat="server" InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetAllRequests" TypeName="UserAccessTableAdapters.RequestsTableAdapter">
        <InsertParameters>
            <asp:Parameter Name="internalId" Type="String" />
            <asp:Parameter Name="employeeLastName" Type="String" />
            <asp:Parameter Name="employeeFirstName" Type="String" />
            <asp:Parameter Name="employeeMiddleName" Type="String" />
            <asp:Parameter Name="departmentCode" Type="String" />
            <asp:Parameter Name="jobCode" Type="String" />
            <asp:Parameter Name="jobTitle" Type="String" />
            <asp:Parameter Name="startDate" Type="DateTime" />
            <asp:Parameter Name="manager" Type="String" />
            <asp:Parameter Name="managerEmail" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
    <asp:Label runat="server" ID="jsHolder" Font-Bold="True" ForeColor="Red"></asp:Label>
</asp:Content>

C#

protected void AddRequestDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        DropDownList dcDDL = (DropDownList)AddRequestDetailsView.FindControl("departmentCodeDDL");
        DropDownList jcDDL = (DropDownList)AddRequestDetailsView.FindControl("jobCodeDDL");
EnterRequestDS.InsertParameters["departmentCode"].DefaultValue = dcDDL.SelectedValue;
            EnterRequestDS.InsertParameters["jobCode"].DefaultValue = jcDDL.SelectedValue;

Check the selectCommand in sqldatasource id "jobSqlDS" add "Distinct" in the select statement and give it a try.

I tried, that did not work. It lets me select an item it will just not put a valid selection in the database upon insert. Thanks for trying though.

I dont know if this might help you too, i sometimes has problem using dropdownlist.selectedValue; instead i use DropDownList.SelectedItem.Value, the last one seems to work right. as far as i know they both should do the same, but why one is working for me and the other one not, dont know yet.

regards

Thanks again, but that did not work. Still will not hold the value of the second drop down.

I found the problem, I had to change enableviewstate to true on the detailsview and that fixed my problem.

yes, by default it is true, but in another post on another website where they were talking about setting up 2 cascading dropdownlist stated that I needed to change it to false and that is what messed me up i guess. thanks for looking and trying to help.

put dropdown in ispostback

if(!Page.IsPostBack)
{
DropDownList1.DataSource=dt;
DropDownList1.DataValueField="field";
DropDownList1.DataTextField="field";
DropDownList1.DataBind();
}
This question has already been answered. Start a new discussion instead.