Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Issue with Dynamic Dependent Drop Down Menu

Thread Tools

Issue with Dynamic Dependent Drop Down Menu
Posts: n/a
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


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~

My web page code is:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="
plantgrid.ascx.cs" Inherits="FPSweb.usercontrols.plantgrid" %>
<table width="593" border="0" cellpadding="0" cellspacing="0">
<td><table width="100%" border="0" cellpadding="2"
<td width="54">Plant ID:</td>
<td width="62"><asp:TextBox ID="txtPlantID"
runat="server" Width="50"></asp:TextBox></td>
<td width="42">Status:</td>
<td width="121"><aspropDownList ID="ddlPlantStatus"
runat="server" Width="110"></aspropDownList></td>
<td><asp:Button ID="btnSearch" runat="server"
OnClick="btnSearch_Click" Text="Search" /></td>
<tr><td><hr /></td></tr>
<table width="100%" border="0" cellpadding="2"
<td width="129">Select the type of plant:</td>
<td><aspropDownList ID="ddlPlantTypeID"
runat="server" Width="326" AutoPostBack="true"
OnSelectedIndexChanged="ddlPlantTypeID_SelectedInd exChanged"></
<td width="95"> </td>
<td>Select the variety of plant:</td>
<td><aspropDownList ID="ddlVarietyID"
runat="server" Width="326"></aspropDownList></td>
<td> </td>
<tr><td><hr /></td></tr>
<br />
<asp:Label ID="lblmessage" runat="server" Text="" Visible="false" />
<asp:ObjectDataSource ID="ObjectDataSourcePlantSearch" runat="server"
<asp:ControlParameter ControlID="ddlPlantTypeID"
DefaultValue="" Name="m_planttypeid"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlVarietyID" DefaultValue=""
PropertyName="SelectedValue" Type="String" />
<asp:QueryStringParameter DefaultValue="" Name="m_groupid"
Type="String" />
<asp:ControlParameter ControlID="ddlPlantStatus"
DefaultValue="" Name="m_statuscode"
PropertyName="SelectedValue" Type="String" />
<table width="589" border="0" cellpadding="0" cellspacing="0">
<td width="46" style="border-left:1px solid #D6D3CE;"
class="gridViewHeader">Group Number</td>
<td width="33" class="gridViewHeader">Plant</td>
<td width="62" class="gridViewHeader">Accession</td>
<td width="133" class="gridViewHeader">Location</td>
<td width="95" class="gridViewHeader">Source</td>
<td width="60" class="gridViewHeader">Plant<br /> Date</td>
<td width="77" class="gridViewHeader">Variety<br /> Name</td>
<td style="border-right:1px solid #D6D3CE; text-align:left;"
<div id="gridscroll" class="scroll">
<asp:GridView ID="dgPlants" runat="server" Width="589"
BorderStyle="solid" BorderColor="#D6D3CE" ShowHeader="False"
AllowSorting="True" DataSourceID="ObjectDataSourcePlantSearch"
AutoGenerateColumns="False" >
<AlternatingRowStyle BackColor="Gainsboro" />
<asp:HyperLinkField HeaderText="Group Number"
SortExpression="GroupID" DataTextField="GroupID"
DataNavigateUrlFields="GroupID" ItemStyle-Width="48" />
<asp:HyperLinkField HeaderText="Plant"
SortExpression="PlantID" DataTextField="PlantID"
DataNavigateUrlFields="PlantID" ItemStyle-Width="35" />
<asp:BoundField HeaderText="Accession"
DataField="AccessionDescription" SortExpression="AccessionDescription"
ItemStyle-Width="64" />
<asp:BoundField ItemStyle-Wrap="false" HeaderText="Location"
DataField="Location" SortExpression="Location" ItemStyle-Width="135" /

<asp:BoundField HeaderText="Source"
DataField="GroupPublicSource" ItemStyle-Width="97" />
<asp:BoundField HeaderText="Plant Date" DataField="PlantDate"
SortExpression="PlantDate" ItemStyle-Width="62" />
<asp:BoundField HeaderText="Variety Name"
DataField="VarietyDescription" SortExpression="VarietyDescription"
ItemStyle-Width="79" />
<asp:BoundField HeaderText="Status" DataField="RemoveStatus" /

<div style="width:585px; font-weight:bold; text-
align:center;">No records found</div>

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("plantsta tuscode"));
plantstatuscode = "NRM";
varietyid = Utils.GetQSParamAsInt("varietyid");
planttypeid = Utils.GetQSParamAsInt("planttypeid");
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,
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,

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=" +
qrystr += (Utils.IsEmpty(plantstatuscode)) ? "" :
(Utils.IsEmpty(qrystr)) ? "?plantstatuscode=" + plantstatuscode :
"&plantstatuscode=" + plantstatuscode;
qrystr += ( Utils.IsEmpty(varietyid)) ? "" :
(Utils.IsEmpty(qrystr)) ? "?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)

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;
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
dependent drop down lists using AJAX and Access database uandme72 ASP .Net 1 03-27-2009 10:39 PM
non-dependent vs. dependent template names puzzlecracker C++ 1 08-07-2008 07:42 AM
Javascript Drop Down Menu Issue. Replacing Text of the Menu Ivann Javascript 1 07-22-2008 08:34 PM
2.0: two dependent drop down lists RAM ASP .Net 2 10-10-2006 12:56 PM
Help with dependent drop down lists and datagrids Megan green via .NET 247 ASP .Net Datagrid Control 0 03-25-2005 07:23 PM