problem with Cascading DropDownList within a datagrid on insert mode

mcdermon
mcdermon used Ask the Experts™
on
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

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

In your code behind file, put the following:

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("UserDirectorateId") = CType(sender, DropDownList).SelectedValue
    End Sub

/Carl.
Hi,

Any feedback on this, did you get it working?

/Carl.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial