Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Issue with Dynamic Dependent Drop Down Menu

 
 
john_mcmahon@gap.com
Guest
Posts: n/a
 
      01-25-2008
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" %>
<table width="593" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="2"
cellspacing="2">
<tr>
<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>
</table></td>
</tr>
<tr><td><hr /></td></tr>
<tr>
<td>
<table width="100%" border="0" cellpadding="2"
cellspacing="2">
<tr>
<td width="129">Select the type of plant:</td>
<td><aspropDownList ID="ddlPlantTypeID"
runat="server" Width="326" AutoPostBack="true"
OnSelectedIndexChanged="ddlPlantTypeID_SelectedInd exChanged"></
aspropDownList></td>
<td width="95"> </td>
</tr>
<tr>
<td>Select the variety of plant:</td>
<td><aspropDownList ID="ddlVarietyID"
runat="server" Width="326"></aspropDownList></td>
<td> </td>
</tr>
</table>
</td>
</tr>
<tr><td><hr /></td></tr>
</table>
<br />
<asp:Label ID="lblmessage" runat="server" Text="" Visible="false" />
<asp:ObjectDataSource ID="ObjectDataSourcePlantSearch" runat="server"
SelectMethod="SearchPlant"
TypeName="BusinessLayer.Plant">
<SelectParameters>
<asp:ControlParameter ControlID="ddlPlantTypeID"
DefaultValue="" Name="m_planttypeid"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlVarietyID" DefaultValue=""
Name="m_varietyid"
PropertyName="SelectedValue" Type="String" />
<asp:QueryStringParameter DefaultValue="" Name="m_groupid"
QueryStringField="groupid"
Type="String" />
<asp:ControlParameter ControlID="ddlPlantStatus"
DefaultValue="" Name="m_statuscode"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<table width="589" border="0" cellpadding="0" cellspacing="0">
<tr>
<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;"
class="gridViewHeader">Status</td>
</tr>
</table>
<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" />
<Columns>
<asp:HyperLinkField HeaderText="Group Number"
SortExpression="GroupID" DataTextField="GroupID"
DataNavigateUrlFormatString="~/group.aspx?groupid={0}"
DataNavigateUrlFields="GroupID" ItemStyle-Width="48" />
<asp:HyperLinkField HeaderText="Plant"
SortExpression="PlantID" DataTextField="PlantID"
DataNavigateUrlFormatString="~/plant.aspx?plantid={0}"
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" /
>

</Columns>
<EmptyDataTemplate>
<div style="width:585px; font-weight:bold; text-
align:center;">No records found</div>
</EmptyDataTemplate>
</asp:GridView>
</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");
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;
}
}
}
 
Reply With Quote
 
 
 
Reply

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



Advertisments