After selecting the ddlprogram it should display the ddl_Location where the programs are avaliable
aspx file
<asp:GridView ID="gvProgram" runat="server" DataKeyNames="ChoiceName" AutoGenerateColumns="False" OnRowDataBound="gvProgram_RowDataBound" Width="100%" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"> <Columns> <asp:BoundField DataField="ChoiceName" HeaderText="Choice" ItemStyle-Width="20%" /> <asp:TemplateField HeaderText="Program"> <ItemTemplate> <asp:DropDownList ID="ddlProgram" runat="server" class="form-control form-control-sm mb-9" OnSelectedIndexChanged="ddlProgram_SelectedIndexChanged" AutoPostBack="true"> <asp:ListItem Value="0">Select Program</asp:ListItem>
</asp:DropDownList> <asp:RequiredFieldValidator ID="rfvddlProgram" runat="server" ErrorMessage="*" ControlToValidate="ddlProgram" Font-Bold="False" Font-Names="Verdana" Font-Size="8pt" SetFocusOnError="True" ValidationGroup="v1" ForeColor="Red" InitialValue="0"></asp:RequiredFieldValidator> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Location"> <ItemTemplate> <asp:DropDownList ID="ddl_Location" runat="server" class="form-control form-control-sm mb-9"> <asp:ListItem Value="0">Select Location</asp:ListItem>
</asp:DropDownList> <asp:RequiredFieldValidator ID="rfvddlLocation" runat="server" ErrorMessage="*" ControlToValidate="ddl_Location" Font-Bold="False" Font-Names="Verdana" Font-Size="8pt" SetFocusOnError="True" ValidationGroup="v1" ForeColor="Red" InitialValue="0"></asp:RequiredFieldValidator> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="White" ForeColor="#000066" /> <HeaderStyle BackColor="#6777ef" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" /> <RowStyle ForeColor="#000066" /> <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F1F1F1" /> <SortedAscendingHeaderStyle BackColor="#007DBB" /> <SortedDescendingCellStyle BackColor="#CAC9C9" /> <SortedDescendingHeaderStyle BackColor="#00547E" /> </asp:GridView>
aspx.cs
protected void gvProgram_RowDataBound(object sender, GridViewRowEventArgs e) { DataSet ds = new DataSet(); Btech.Mode = "BindData"; ds = objDal.Adm(Btech);
if (e.Row.RowType == DataControlRowType.DataRow) { if (ds.Tables[0].Rows.Count > 0 && ds.Tables[1].Rows.Count > 0) { DropDownList ddlProgram = (DropDownList)e.Row.FindControl("ddlProgram"); ddlProgram.Items.Clear(); ddlProgram.DataSource = ds.Tables[13]; ddlProgram.DataTextField = "Description"; ddlProgram.DataValueField = "CourseID"; ddlProgram.DataBind(); ddlProgram.Items.Insert(0, new ListItem("Select course", "0"));
DropDownList ddl_Location = (DropDownList)e.Row.FindControl("ddl_Location"); //ddlTeacherNames.Items.Clear(); ddl_Location.DataSource = ds.Tables[14]; ddl_Location.DataTextField = "CenterName"; ddl_Location.DataValueField = "CentreCode"; ddl_Location.DataBind(); ddl_Location.Items.Insert(0, new ListItem("Select Location", "0")); } }
}
protected void ddlProgram_SelectedIndexChanged(object sender, EventArgs e) {