Issue with Dynamic Dependent Drop Down Menu
am 25.01.2008 07:26:54 von phreeskierI'm having issues dynamically populating a second drop down menu
that's dependent upon a selection in the first drop down menu. When I
select an option from the first menu, the page posts back and doesn't
recognize the "ddlPlantTypeID_SelectedIndexChanged" function from the
onSelectedIndexChanged property of the first menu. I've even inserted
a breakpoint within the function in the code behind to no avail. Why
is the "ddlPlantTypeID_SelectedIndexChanged" function not being
invoked? Where am I going wrong? Is it my code or a missing
configuration?
Thanks,
John
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
My web page code is:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="
plantgrid.ascx.cs" Inherits="FPSweb.usercontrols.plantgrid" %>
Plant ID: | Status: |
OnSelectedIndexChanged="ddlPlantTypeID_SelectedIndexChanged" >
asp:DropDownList>
TypeName="BusinessLayer.Plant">
PropertyName="SelectedValue" Type="String" />
PropertyName="SelectedValue" Type="String" />
Type="String" />
PropertyName="SelectedValue" Type="String" />
class="gridViewHeader">Group Number | Plant | Accession | Location | Source | Plant Date | Variety Name | class="gridViewHeader">Status |
AllowSorting="True" DataSourceID="ObjectDataSourcePlantSearch"
AutoGenerateColumns="False" >
DataNavigateUrlFormatString="~/group.aspx?groupid={0}"
DataNavigateUrlFields="GroupID" ItemStyle-Width="48" />
DataNavigateUrlFormatString="~/plant.aspx?plantid={0}"
DataNavigateUrlFields="PlantID" ItemStyle-Width="35" />
ItemStyle-Width="64" />
>
ItemStyle-Width="79" />
My code behind is:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BusinessLayer;
using LT;
namespace FPSweb.usercontrols
{
public partial class plantgrid : BaseUserControl
{
protected int plantid;
protected string plantstatuscode = "";
protected int varietyid;
protected int planttypeid;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
plantid = Utils.GetQSParamAsInt("plantid");
// plantstatuscode =
Utils.GetQSParamAsString("plantstatuscode") == null ? "" :
Utils.StripHTML(Utils.GetQSParamAsString("plantstatuscode")) ;
plantstatuscode = "NRM";
varietyid = Utils.GetQSParamAsInt("varietyid");
planttypeid = Utils.GetQSParamAsInt("planttypeid");
BindControls();
}
}
protected void BindControls()
{
string err = "";
txtPlantID.Text = plantid.ToString();
Common.PopulateStatusDropDown(this.ddlPlantStatus, true,
plantstatuscode.ToString(), "plant");
PopulateDropDown(this.ddlPlantTypeID, Common.GetPlantTypes
(0, out err), "plantTypeDescription", "plantTypeID", true,
planttypeid.ToString());
this.ddlVarietyID.Items.Insert(0, new ListItem("Select
one", ""));
this.ddlVarietyID.Enabled = false;
//PopulateDropDown(this.ddlVarietyID, null,
"varietyDescription", "varietyID", true, varietyid.ToString());
//PopulateDropDown(this.ddlGroupID ,
Group.GetGroup(groupid.ToString()), "groupid", "groupid", true,
groupid.ToString());
}
protected void btnSearch_Click(object sender, EventArgs e)
{
string qrystr = "";
plantid = Utils.CInt(txtPlantID.Text);
plantstatuscode = ddlPlantStatus.SelectedValue.ToString();
varietyid = Utils.CInt(ddlVarietyID.SelectedValue);
planttypeid = Utils.CInt(ddlPlantTypeID.SelectedValue);
qrystr += (Utils.IsEmpty(plantid)) ? "" :
(Utils.IsEmpty(qrystr)) ? "?plantid=" + plantid : "&plantid=" +
plantid;
qrystr += (Utils.IsEmpty(plantstatuscode)) ? "" :
(Utils.IsEmpty(qrystr)) ? "?plantstatuscode=" + plantstatuscode :
"&plantstatuscode=" + plantstatuscode;
qrystr += ( Utils.IsEmpty(varietyid)) ? "" :
(Utils.IsEmpty(qrystr)) ? "?varietyid=" + varietyid : "&varietyid=" +
varietyid;
qrystr += (Utils.IsEmpty(planttypeid)) ? "" :
(Utils.IsEmpty (qrystr)) ? "?planttypeid=" + planttypeid :
"&planttypeid=" + planttypeid;
if (!Utils.IsEmpty(plantid))
{
Response.Redirect("~/plant.aspx" + qrystr);
}
}
protected void ddlPlantTypeID_SelectedIndexChanged(object
sender, EventArgs e)
{
LoadDropDown2Data();
}
private void LoadDropDown2Data()
{
string err = "";
// PopulateDropDown(this.ddlVarietyID,
Common.GetVarieties(0, this.ddlPlantTypeID.SelectedIndex, out err),
"varietyDescription", "varietyID", true, varietyid.ToString());
this.ddlVarietyID.Items.Insert(0, new ListItem("No", ""));
this.ddlVarietyID.Enabled = true;
}
}
}