After selecting the ddlprogram it should display the ddl_Location where the programs are avaliable
aspx file
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)
{
}

Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 18, 2024, 6:33 AM EST
It seems like you want to populate the
ddl_Locationdropdown based on the selected value of theddlProgramdropdown. You can achieve this by fetching the relevant data inside theddlProgram_SelectedIndexChangedevent. Here is a sample code snippet:protected void ddlProgram_SelectedIndexChanged(object sender, EventArgs e) { // Get the selected program DropDownList ddlProgram = (DropDownList)sender; string selectedProgram = ddlProgram.SelectedValue; // Find the ddl_Location control GridViewRow row = (GridViewRow)ddlProgram.NamingContainer; DropDownList ddl_Location = (DropDownList)row.FindControl("ddl_Location"); // Fetch the locations based on the selected program // This is just a placeholder, replace it with your actual data fetching logic DataSet dsLocations = FetchLocationsForProgram(selectedProgram); // Bind the fetched data to ddl_Location ddl_Location.DataSource = dsLocations; ddl_Location.DataTextField = "CenterName"; ddl_Location.DataValueField = "CentreCode"; ddl_Location.DataBind(); ddl_Location.Items.Insert(0, new ListItem("Select Location", "0")); }In this code,
FetchLocationsForProgram(selectedProgram)is a placeholder method which you should replace with your actual logic to fetch the locations based on the selected program. This method should return aDataSetorDataTablewhich can be bound toddl_Location.Please replace the placeholder method with your actual data fetching logic.
Thanks.