locked
dynamically building the content of second dropdown list based on selection of first dropdown while editing the templatefield of gridview in asp.net RRS feed

  • Question

  • User1723511120 posted

    I have a gridview, and each field has dropdown list where the second dropdown value gets populated based on the first dropdown value. The same way I want dropdown to get populated based on the value of first dropdown value while editing. I want a solution for this. I have dropdown for the fields, but not able to populate dynamically while editing. 

    Please see my code below and give a solution.

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
        <div style="width:100%; height:300; overflow:auto;">
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AutoGenerateColumns="False" DataKeyNames="Failure_ID" 
            DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#3366CC" 
            BorderStyle="None" BorderWidth="1px" CellPadding="4" 
            RowStyle-HorizontalAlign=Center PageSize="13" ShowHeaderWhenEmpty=true EmptyDataText="No records found">
            <Columns>
            
                <asp:CommandField ShowEditButton="True" ButtonType=Image
                        ItemStyle-Wrap=false EditImageUrl="~/images/edit.jpg" UpdateImageUrl="~/images/update.jpg" CancelImageUrl="~/images/cancel.jpg"/>
                
                <asp:TemplateField> 
                    <ItemTemplate> 
                      <asp:ImageButton ID="ImageButton1" Runat="server"  CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete this Record?');" 
                           ImageUrl="~/images/delete.jpg"/> 
                   </ItemTemplate> 
                </asp:TemplateField> 
    
                <asp:BoundField DataField="Failure_ID" HeaderText="Failure_ID" 
                    InsertVisible="False" ReadOnly="True" SortExpression="Failure_ID" 
                    ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Report_date" HeaderText="Report_date" 
                    SortExpression="Report_date" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                
                <asp:TemplateField HeaderText="Line" SortExpression="Line">
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server" 
                                DataSourceID="SqlDataSource2" DataTextField="Line" DataValueField="Line" 
                                SelectedValue='<%# Bind("Line") %>'>
                            </asp:DropDownList>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Line") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
    
                <asp:BoundField DataField="Reach" HeaderText="Reach" SortExpression="Reach" 
                    ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Station" HeaderText="Station" 
                    SortExpression="Station" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Reported_by" HeaderText="Reported_by" 
                    SortExpression="Reported_by" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="System" HeaderText="System" 
                    SortExpression="System" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Sub_system" HeaderText="Sub_system" 
                    SortExpression="Sub_system" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Equipment" HeaderText="Equipment" 
                    SortExpression="Equipment" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Equipment_ID" HeaderText="Equipment_ID" 
                    SortExpression="Equipment_ID" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Attend_date" HeaderText="Attend_date" 
                    SortExpression="Attend_date" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Rectified_date" HeaderText="Rectified_date" 
                    SortExpression="Rectified_date" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Downtime" HeaderText="Downtime" 
                    SortExpression="Downtime" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Failure_desc" HeaderText="Failure_desc" 
                    SortExpression="Failure_desc" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Action" HeaderText="Action" 
                    SortExpression="Action" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Origin" HeaderText="Origin" 
                    SortExpression="Origin" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Severity" HeaderText="Severity" 
                    SortExpression="Severity" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="RCA_status" HeaderText="RCA_status" 
                    SortExpression="RCA_status" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="Attended_by" HeaderText="Attended_by" 
                    SortExpression="Attended_by" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="status" HeaderText="Status" 
                    SortExpression="status" ItemStyle-Wrap=false>
    <ItemStyle Wrap="False"></ItemStyle>
                </asp:BoundField>
            </Columns>
            <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
            <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" />
            <PagerStyle BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" />
            <RowStyle BackColor="White" ForeColor="#003399" />
            <SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
            <SortedAscendingCellStyle BackColor="#EDF6F6" />
            <SortedAscendingHeaderStyle BackColor="#0D4AC4" />
            <SortedDescendingCellStyle BackColor="#D6DFDF" />
            <SortedDescendingHeaderStyle BackColor="#002876" />
        </asp:GridView> 
    </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConflictDetection="CompareAllValues" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            DeleteCommand="DELETE FROM [Ticket] WHERE [Failure_ID] = @original_Failure_ID AND (([Report_date] = @original_Report_date) OR ([Report_date] IS NULL AND @original_Report_date IS NULL)) AND (([Line] = @original_Line) OR ([Line] IS NULL AND @original_Line IS NULL)) AND (([Reach] = @original_Reach) OR ([Reach] IS NULL AND @original_Reach IS NULL)) AND (([Station] = @original_Station) OR ([Station] IS NULL AND @original_Station IS NULL)) AND (([Reported_by] = @original_Reported_by) OR ([Reported_by] IS NULL AND @original_Reported_by IS NULL)) AND (([System] = @original_System) OR ([System] IS NULL AND @original_System IS NULL)) AND (([Sub_system] = @original_Sub_system) OR ([Sub_system] IS NULL AND @original_Sub_system IS NULL)) AND (([Equipment] = @original_Equipment) OR ([Equipment] IS NULL AND @original_Equipment IS NULL)) AND (([Equipment_ID] = @original_Equipment_ID) OR ([Equipment_ID] IS NULL AND @original_Equipment_ID IS NULL)) AND (([Attend_date] = @original_Attend_date) OR ([Attend_date] IS NULL AND @original_Attend_date IS NULL)) AND (([Rectified_date] = @original_Rectified_date) OR ([Rectified_date] IS NULL AND @original_Rectified_date IS NULL)) AND (([Downtime] = @original_Downtime) OR ([Downtime] IS NULL AND @original_Downtime IS NULL)) AND (([Failure_desc] = @original_Failure_desc) OR ([Failure_desc] IS NULL AND @original_Failure_desc IS NULL)) AND (([Action] = @original_Action) OR ([Action] IS NULL AND @original_Action IS NULL)) AND (([Origin] = @original_Origin) OR ([Origin] IS NULL AND @original_Origin IS NULL)) AND (([Severity] = @original_Severity) OR ([Severity] IS NULL AND @original_Severity IS NULL)) AND (([RCA_status] = @original_RCA_status) OR ([RCA_status] IS NULL AND @original_RCA_status IS NULL)) AND (([Attended_by] = @original_Attended_by) OR ([Attended_by] IS NULL AND @original_Attended_by IS NULL)) AND (([status] = @original_status) OR ([status] IS NULL AND @original_status IS NULL))" 
            InsertCommand="INSERT INTO [Ticket] ([Report_date], [Line], [Reach], [Station], [Reported_by], [System], [Sub_system], [Equipment], [Equipment_ID], [Attend_date], [Rectified_date], [Downtime], [Failure_desc], [Action], [Origin], [Severity], [RCA_status], [Attended_by], [status]) VALUES (@Report_date, @Line, @Reach, @Station, @Reported_by, @System, @Sub_system, @Equipment, @Equipment_ID, @Attend_date, @Rectified_date, @Downtime, @Failure_desc, @Action, @Origin, @Severity, @RCA_status, @Attended_by, @status)" 
            OldValuesParameterFormatString="original_{0}" 
            SelectCommand="SELECT [Failure_ID], [Report_date], [Line], [Reach], [Station], [Reported_by], [System], [Sub_system], [Equipment], [Equipment_ID], [Attend_date], [Rectified_date], [Downtime], [Failure_desc], [Action], [Origin], [Severity], [RCA_status], [Attended_by], [status] FROM [Ticket]" 
            UpdateCommand="UPDATE [Ticket] SET [Report_date] = @Report_date, [Line] = @Line, [Reach] = @Reach, [Station] = @Station, [Reported_by] = @Reported_by, [System] = @System, [Sub_system] = @Sub_system, [Equipment] = @Equipment, [Equipment_ID] = @Equipment_ID, [Attend_date] = @Attend_date, [Rectified_date] = @Rectified_date, [Downtime] = @Downtime, [Failure_desc] = @Failure_desc, [Action] = @Action, [Origin] = @Origin, [Severity] = @Severity, [RCA_status] = @RCA_status, [Attended_by] = @Attended_by, [status] = @status WHERE [Failure_ID] = @original_Failure_ID AND (([Report_date] = @original_Report_date) OR ([Report_date] IS NULL AND @original_Report_date IS NULL)) AND (([Line] = @original_Line) OR ([Line] IS NULL AND @original_Line IS NULL)) AND (([Reach] = @original_Reach) OR ([Reach] IS NULL AND @original_Reach IS NULL)) AND (([Station] = @original_Station) OR ([Station] IS NULL AND @original_Station IS NULL)) AND (([Reported_by] = @original_Reported_by) OR ([Reported_by] IS NULL AND @original_Reported_by IS NULL)) AND (([System] = @original_System) OR ([System] IS NULL AND @original_System IS NULL)) AND (([Sub_system] = @original_Sub_system) OR ([Sub_system] IS NULL AND @original_Sub_system IS NULL)) AND (([Equipment] = @original_Equipment) OR ([Equipment] IS NULL AND @original_Equipment IS NULL)) AND (([Equipment_ID] = @original_Equipment_ID) OR ([Equipment_ID] IS NULL AND @original_Equipment_ID IS NULL)) AND (([Attend_date] = @original_Attend_date) OR ([Attend_date] IS NULL AND @original_Attend_date IS NULL)) AND (([Rectified_date] = @original_Rectified_date) OR ([Rectified_date] IS NULL AND @original_Rectified_date IS NULL)) AND (([Downtime] = @original_Downtime) OR ([Downtime] IS NULL AND @original_Downtime IS NULL)) AND (([Failure_desc] = @original_Failure_desc) OR ([Failure_desc] IS NULL AND @original_Failure_desc IS NULL)) AND (([Action] = @original_Action) OR ([Action] IS NULL AND @original_Action IS NULL)) AND (([Origin] = @original_Origin) OR ([Origin] IS NULL AND @original_Origin IS NULL)) AND (([Severity] = @original_Severity) OR ([Severity] IS NULL AND @original_Severity IS NULL)) AND (([RCA_status] = @original_RCA_status) OR ([RCA_status] IS NULL AND @original_RCA_status IS NULL)) AND (([Attended_by] = @original_Attended_by) OR ([Attended_by] IS NULL AND @original_Attended_by IS NULL)) AND (([status] = @original_status) OR ([status] IS NULL AND @original_status IS NULL))">
            <DeleteParameters>
                <asp:Parameter Name="original_Failure_ID" Type="Int32" />
                <asp:Parameter Name="original_Report_date" Type="DateTime" />
                <asp:Parameter Name="original_Line" Type="String" />
                <asp:Parameter Name="original_Reach" Type="String" />
                <asp:Parameter Name="original_Station" Type="String" />
                <asp:Parameter Name="original_Reported_by" Type="String" />
                <asp:Parameter Name="original_System" Type="String" />
                <asp:Parameter Name="original_Sub_system" Type="String" />
                <asp:Parameter Name="original_Equipment" Type="String" />
                <asp:Parameter Name="original_Equipment_ID" Type="String" />
                <asp:Parameter Name="original_Attend_date" Type="DateTime" />
                <asp:Parameter Name="original_Rectified_date" Type="DateTime" />
                <asp:Parameter Name="original_Downtime" Type="String" />
                <asp:Parameter Name="original_Failure_desc" Type="String" />
                <asp:Parameter Name="original_Action" Type="String" />
                <asp:Parameter Name="original_Origin" Type="String" />
                <asp:Parameter Name="original_Severity" Type="String" />
                <asp:Parameter Name="original_RCA_status" Type="String" />
                <asp:Parameter Name="original_Attended_by" Type="String" />
                <asp:Parameter Name="original_status" Type="String" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="Report_date" Type="DateTime" />
                <asp:Parameter Name="Line" Type="String" />
                <asp:Parameter Name="Reach" Type="String" />
                <asp:Parameter Name="Station" Type="String" />
                <asp:Parameter Name="Reported_by" Type="String" />
                <asp:Parameter Name="System" Type="String" />
                <asp:Parameter Name="Sub_system" Type="String" />
                <asp:Parameter Name="Equipment" Type="String" />
                <asp:Parameter Name="Equipment_ID" Type="String" />
                <asp:Parameter Name="Attend_date" Type="DateTime" />
                <asp:Parameter Name="Rectified_date" Type="DateTime" />
                <asp:Parameter Name="Downtime" Type="String" />
                <asp:Parameter Name="Failure_desc" Type="String" />
                <asp:Parameter Name="Action" Type="String" />
                <asp:Parameter Name="Origin" Type="String" />
                <asp:Parameter Name="Severity" Type="String" />
                <asp:Parameter Name="RCA_status" Type="String" />
                <asp:Parameter Name="Attended_by" Type="String" />
                <asp:Parameter Name="status" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="Report_date" Type="DateTime" />
                <asp:Parameter Name="Line" Type="String" />
                <asp:Parameter Name="Reach" Type="String" />
                <asp:Parameter Name="Station" Type="String" />
                <asp:Parameter Name="Reported_by" Type="String" />
                <asp:Parameter Name="System" Type="String" />
                <asp:Parameter Name="Sub_system" Type="String" />
                <asp:Parameter Name="Equipment" Type="String" />
                <asp:Parameter Name="Equipment_ID" Type="String" />
                <asp:Parameter Name="Attend_date" Type="DateTime" />
                <asp:Parameter Name="Rectified_date" Type="DateTime" />
                <asp:Parameter Name="Downtime" Type="String" />
                <asp:Parameter Name="Failure_desc" Type="String" />
                <asp:Parameter Name="Action" Type="String" />
                <asp:Parameter Name="Origin" Type="String" />
                <asp:Parameter Name="Severity" Type="String" />
                <asp:Parameter Name="RCA_status" Type="String" />
                <asp:Parameter Name="Attended_by" Type="String" />
                <asp:Parameter Name="status" Type="String" />
                <asp:Parameter Name="original_Failure_ID" Type="Int32" />
                <asp:Parameter Name="original_Report_date" Type="DateTime" />
                <asp:Parameter Name="original_Line" Type="String" />
                <asp:Parameter Name="original_Reach" Type="String" />
                <asp:Parameter Name="original_Station" Type="String" />
                <asp:Parameter Name="original_Reported_by" Type="String" />
                <asp:Parameter Name="original_System" Type="String" />
                <asp:Parameter Name="original_Sub_system" Type="String" />
                <asp:Parameter Name="original_Equipment" Type="String" />
                <asp:Parameter Name="original_Equipment_ID" Type="String" />
                <asp:Parameter Name="original_Attend_date" Type="DateTime" />
                <asp:Parameter Name="original_Rectified_date" Type="DateTime" />
                <asp:Parameter Name="original_Downtime" Type="String" />
                <asp:Parameter Name="original_Failure_desc" Type="String" />
                <asp:Parameter Name="original_Action" Type="String" />
                <asp:Parameter Name="original_Origin" Type="String" />
                <asp:Parameter Name="original_Severity" Type="String" />
                <asp:Parameter Name="original_RCA_status" Type="String" />
                <asp:Parameter Name="original_Attended_by" Type="String" />
                <asp:Parameter Name="original_status" Type="String" />
            </UpdateParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            SelectCommand="SELECT DISTINCT [Line] FROM [Ticket]"></asp:SqlDataSource>
    </asp:Content>

    Please help with the solution as soon as possible. need desparately.

    Sunday, January 19, 2014 10:08 AM

Answers

  • User724169276 posted

    sree3011

    Please reply someone to this.

    Hello Sree,

    According to your description you have to populate one dropdownlist according to the selection of other dropdownlist inside a gridview.for that you have to find the control of second dropdownlist inside gridview.please check the resolved thread ..you might get some help.

    Populate one dropdownlist according to other inside a gridview.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 23, 2014 10:59 AM

All replies

  • User1723511120 posted

    Please reply someone to this.

    Monday, January 20, 2014 6:20 AM
  • User-1925713106 posted

    Hi Sree, 

    Thanks for your post.

    Please provide a detailed example to descript your scenario.

    In DropDownList field, you can add the OnSelectedIndexChanged event to invoke method.

    Tuesday, January 21, 2014 6:55 AM
  • User724169276 posted

    sree3011

    Please reply someone to this.

    Hello Sree,

    According to your description you have to populate one dropdownlist according to the selection of other dropdownlist inside a gridview.for that you have to find the control of second dropdownlist inside gridview.please check the resolved thread ..you might get some help.

    Populate one dropdownlist according to other inside a gridview.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, January 23, 2014 10:59 AM