Issue with Dynamic Dependent Drop Down Menu

Issue with Dynamic Dependent Drop Down Menu

am 25.01.2008 07:26:54 von phreeskier

I'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" %>










cellspacing="2">







Plant ID: runat="server" Width="50"> Status: runat="server" Width="110"> OnClick="btnSearch_Click" Text="Search" />


cellspacing="2">










Select the type of plant: runat="server" Width="326" AutoPostBack="true"
OnSelectedIndexChanged="ddlPlantTypeID_SelectedIndexChanged" > asp:DropDownList>
 
Select the variety of plant: runat="server" Width="326">  






SelectMethod="SearchPlant"
TypeName="BusinessLayer.Plant">

DefaultValue="" Name="m_planttypeid"
PropertyName="SelectedValue" Type="String" />
Name="m_varietyid"
PropertyName="SelectedValue" Type="String" />
QueryStringField="groupid"
Type="String" />
DefaultValue="" Name="m_statuscode"
PropertyName="SelectedValue" Type="String" />













class="gridViewHeader">Group Number Plant Accession Location Source Plant
Date
Variety
Name
class="gridViewHeader">Status


BorderStyle="solid" BorderColor="#D6D3CE" ShowHeader="False"
AllowSorting="True" DataSourceID="ObjectDataSourcePlantSearch"
AutoGenerateColumns="False" >


SortExpression="GroupID" DataTextField="GroupID"
DataNavigateUrlFormatString="~/group.aspx?groupid={0}"
DataNavigateUrlFields="GroupID" ItemStyle-Width="48" />
SortExpression="PlantID" DataTextField="PlantID"
DataNavigateUrlFormatString="~/plant.aspx?plantid={0}"
DataNavigateUrlFields="PlantID" ItemStyle-Width="35" />
DataField="AccessionDescription" SortExpression="AccessionDescription"
ItemStyle-Width="64" />
DataField="Location" SortExpression="Location" ItemStyle-Width="135" /
>
DataField="GroupPublicSource" ItemStyle-Width="97" />
SortExpression="PlantDate" ItemStyle-Width="62" />
DataField="VarietyDescription" SortExpression="VarietyDescription"
ItemStyle-Width="79" />
>


No records found






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;
}
}
}