We help IT Professionals succeed at work.
Get Started

problem with Cascading DropDownList within a datagrid on insert mode

465 Views
Last Modified: 2013-11-26
hi all

i have 2 Cascading DropDownList  which are in a datagrid which is in insert mode only.
i cant seem to get dropdownbox2 to pick up the value from dropdownbox1.
which will then give me only the values that corresponse to the choice from dropdownbox1

any help would be great
<asp:Panel ID="Panel1" runat="server" Visible="False">
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" 
                DataKeyNames="TeamId" DataSourceID="SqlDataSource1" DefaultMode="Insert" 
                HeaderText="Add to a Team or Teams" Height="50px" Width="125px">
                <Fields>
                    <asp:TemplateField HeaderText="TeamId" InsertVisible="False" 
                        SortExpression="TeamId">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("TeamId") %>'></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("TeamId") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="UserDirectorateId" 
                        SortExpression="UserDirectorateId">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" 
                                Text='<%# Bind("UserDirectorateId") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                                DataSourceID="SqlDataSource1" DataTextField="UserDirectorate" 
                                DataValueField="UserDirectorateId" AppendDataBoundItems="True">
                            <asp:ListItem Value="-1">Please Select</asp:ListItem>
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:NISATConnectionString2 %>" 
                                SelectCommand="SELECT [UserDirectorateId], [UserDirectorate] FROM [tbl_UserDirectorate]">
                            </asp:SqlDataSource>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                ControlToValidate="DropDownList1" 
                                InitialValue="-1"></asp:RequiredFieldValidator>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text='<%# Bind("UserDirectorateId") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                    <asp:TemplateField HeaderText="UserDivisionId" SortExpression="UserDivisionId">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("UserDivisionId") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                          <asp:DropDownList ID="DropDownList2" runat="server" AppendDataBoundItems="True" 
                                AutoPostBack="True" DataSourceID="divisionSqlDataSource1" 
                                DataTextField="UserDivision" DataValueField="UserDivisionId" 
                                SelectedValue='<%# Bind("UserDivisionId") %>'>
                                <asp:ListItem Value="-1">Please Select</asp:ListItem>
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="divisionSqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:NISATConnectionString2 %>" 
                                
                                SelectCommand="SELECT [UserDivisionId], [UserDivision] FROM [tbl_UserDivision] WHERE ([UserDirectorateId] = @DropDownList1)">
                                <SelectParameters>
                                    <asp:SessionParameter DefaultValue="" Name="UserDirectorateId" 
                                        SessionField="UserDirectorateId" Type="Int32" />
                                </SelectParameters>
                                </asp:SqlDataSource>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                ControlToValidate="DropDownList2" InitialValue="-1">*</asp:RequiredFieldValidator>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text='<%# Bind("UserDivisionId") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    
                    <asp:TemplateField HeaderText="UserProfessionId" 
                        SortExpression="UserProfessionId">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" 
                                Text='<%# Bind("UserProfessionId") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox3" runat="server" 
                                Text='<%# Bind("UserProfessionId") %>'></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label4" runat="server" Text='<%# Bind("UserProfessionId") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="StaffNo" SortExpression="StaffNo">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("StaffNo") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("StaffNo") %>'></asp:TextBox>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label5" runat="server" Text='<%# Bind("StaffNo") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ShowInsertButton="True" />
                </Fields>
                <HeaderStyle BackColor="#CC9900" />
            </asp:DetailsView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConflictDetection="CompareAllValues" 
                ConnectionString="<%$ ConnectionStrings:NISATConnectionString2 %>" 
                DeleteCommand="DELETE FROM [tbl_UserTeam] WHERE [TeamId] = @original_TeamId AND (([UserDirectorateId] = @original_UserDirectorateId) OR ([UserDirectorateId] IS NULL AND @original_UserDirectorateId IS NULL)) AND (([UserDivisionId] = @original_UserDivisionId) OR ([UserDivisionId] IS NULL AND @original_UserDivisionId IS NULL)) AND (([UserProfessionId] = @original_UserProfessionId) OR ([UserProfessionId] IS NULL AND @original_UserProfessionId IS NULL)) AND (([StaffNo] = @original_StaffNo) OR ([StaffNo] IS NULL AND @original_StaffNo IS NULL))" 
                InsertCommand="INSERT INTO [tbl_UserTeam] ([UserDirectorateId], [UserDivisionId], [UserProfessionId], [StaffNo]) VALUES (@UserDirectorateId, @UserDivisionId, @UserProfessionId, @StaffNo)" 
                OldValuesParameterFormatString="original_{0}" 
                SelectCommand="SELECT [TeamId], [UserDirectorateId], [UserDivisionId], [UserProfessionId], [StaffNo] FROM [tbl_UserTeam]" 
                UpdateCommand="UPDATE [tbl_UserTeam] SET [UserDirectorateId] = @UserDirectorateId, [UserDivisionId] = @UserDivisionId, [UserProfessionId] = @UserProfessionId, [StaffNo] = @StaffNo WHERE [TeamId] = @original_TeamId AND (([UserDirectorateId] = @original_UserDirectorateId) OR ([UserDirectorateId] IS NULL AND @original_UserDirectorateId IS NULL)) AND (([UserDivisionId] = @original_UserDivisionId) OR ([UserDivisionId] IS NULL AND @original_UserDivisionId IS NULL)) AND (([UserProfessionId] = @original_UserProfessionId) OR ([UserProfessionId] IS NULL AND @original_UserProfessionId IS NULL)) AND (([StaffNo] = @original_StaffNo) OR ([StaffNo] IS NULL AND @original_StaffNo IS NULL))">
                <DeleteParameters>
                    <asp:Parameter Name="original_TeamId" Type="Int32" />
                    <asp:Parameter Name="original_UserDirectorateId" Type="Int32" />
                    <asp:Parameter Name="original_UserDivisionId" Type="Int32" />
                    <asp:Parameter Name="original_UserProfessionId" Type="Int32" />
                    <asp:Parameter Name="original_StaffNo" Type="Int64" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="UserDirectorateId" Type="Int32" />
                    <asp:Parameter Name="UserDivisionId" Type="Int32" />
                    <asp:Parameter Name="UserProfessionId" Type="Int32" />
                    <asp:Parameter Name="StaffNo" Type="Int64" />
                    <asp:Parameter Name="original_TeamId" Type="Int32" />
                    <asp:Parameter Name="original_UserDirectorateId" Type="Int32" />
                    <asp:Parameter Name="original_UserDivisionId" Type="Int32" />
                    <asp:Parameter Name="original_UserProfessionId" Type="Int32" />
                    <asp:Parameter Name="original_StaffNo" Type="Int64" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="UserDirectorateId" Type="Int32" />
                    <asp:Parameter Name="UserDivisionId" Type="Int32" />
                    <asp:Parameter Name="UserProfessionId" Type="Int32" />
                    <asp:Parameter Name="StaffNo" Type="Int64" />
                </InsertParameters>
            </asp:SqlDataSource>
            <dx:ASPxButton ID="ASPxButton2" runat="server" 
                CssFilePath="~/App_Themes/Youthful/{0}/styles.css" CssPostfix="Youthful" 
                SpriteCssFilePath="~/App_Themes/Youthful/{0}/sprite.css" Text="ASPxButton">
            </dx:ASPxButton>
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
            <br />
            <br />
        </asp:Panel>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE