3

Im make a 3 drop down menu 1) Country 2) City 3) Factory

Country and City Dropdownmenu working correctly(Country selected displayed country to included city's) but city selected not a display city to included factory's how can i fix it? can you please give the solution.

     GodownCls godownCls = new GodownCls();
     CityCls ctyCls = new CityCls();
     FactoryCls facCls = new FactoryCls();


     LoadCountries();

 private void LoadCountries()
        {
            CountryCls objCountry = new CountryCls();

            DataTable dtCountry = objCountry.Country_SelectAll();

            ddlCountry.DataSource = dtCountry;
            ddlCountry.DataTextField = "Name";
            ddlCountry.DataValueField = "ID";
            ddlCountry.DataBind();

        }

        private void LoadFactories(int CityId)
        {
            FactoryCls objFactory = new FactoryCls();

            DataTable dtFactory = objFactory.FactoriesByCity(CityId);

            ddlFactory.DataSource = dtFactory;
            ddlFactory.DataTextField = "Name";
            ddlFactory.DataValueField = "ID";
            ddlFactory.DataBind();
            ddlFactory.SelectedIndex = 0;
        }

        private void LoadCities(int CountryId)
        {
            CityCls objCity = new CityCls();

            DataTable dtCity = objCity.CitiesByCountry(CountryId);

            ddlCity.DataSource = dtCity;
            ddlCity.DataTextField = "Name";
            ddlCity.DataValueField = "ID";
            ddlCity.DataBind();
            ddlCity.SelectedIndex = 0;
        }

 protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedCountryId = Convert.ToInt32(ddlCountry.SelectedValue);
            LoadCities(selectedCountryId);
        }
        protected void ddlFactory_SelectedIndexChanged(object sender, EventArgs e)
        {

            int selectedFactoryId = Convert.ToInt32(ddlFactory.SelectedValue);
            LoadCities(selectedFactoryId);

        }

actually now all of factory displayed for the drop down menu

full code

 public partial class Godown : System.Web.UI.Page
    {
        #region "---- Variables & ViewStates ----"

        clsCommonMethods clsComMethods = new clsCommonMethods();

        public DataTable dtGodownHelp
        {
            get { return (DataTable)ViewState["dtGodownHelp"]; }
            set { ViewState["dtGodownHelp"] = value; }
        }

        public String CurrentMode
        {
            get { return (String)ViewState["CurrentMode"]; }
            set { ViewState["CurrentMode"] = value; }
        }

        public int SelectedGodownId
        {
            get { return (int)ViewState["SelectedGodownId"]; }
            set { ViewState["SelectedGodownId"] = value; }
        }

        public int SelectedUserId
        {
            get { return (int)ViewState["SelectedUserId"]; }
            set { ViewState["SelectedUserId"] = value; }
        }

        public bool ViewRight
        {
            get { return (bool)ViewState["ViewRight"]; }
            set { ViewState["ViewRight"] = value; }
        }

        public bool CreateRight
        {
            get { return (bool)ViewState["CreateRight"]; }
            set { ViewState["CreateRight"] = value; }
        }

        public bool UpdateRight
        {
            get { return (bool)ViewState["UpdateRight"]; }
            set { ViewState["UpdateRight"] = value; }
        }

        #endregion

        GodownCls godownCls = new GodownCls();

        CityCls ctyCls = new CityCls();
        FactoryCls facCls = new FactoryCls();

        #region Page Load
        protected void Page_Load(object sender, EventArgs e)
        {
            this.UnobtrusiveValidationMode = System.Web.UI.UnobtrusiveValidationMode.None;
            if (!IsPostBack)
            {
                if ((Session["UserId"] == null))
                {
                    FormsAuthentication.SignOut();
                    Response.Redirect("~/WebForms/Home/Login.aspx");
                }
                else
                {
                    SelectedUserId = int.Parse(Session["UserId"].ToString());

                    string pageName = "godown";

                    DataTable dtUp = UserPermission(pageName);
                    if (dtUp.Rows.Count > 0)
                    {
                        ViewRight = Convert.ToBoolean(dtUp.Rows[0]["isViewable"]);
                        CreateRight = Convert.ToBoolean(dtUp.Rows[0]["isCreatable"]);
                        UpdateRight = Convert.ToBoolean(dtUp.Rows[0]["isEditable"]);
                    }

                    if (ViewRight != true)
                    {
                        Response.Redirect("~/WebForms/Home/AccessDenied.aspx");
                    }
                    else
                    {
                        SetSavePermission(CreateRight);
                        SetEditPermission(UpdateRight);
                    }
                }

                ClearControls();
                EnableControls(false);
                LoadCountries();


            }
        }

        private void SetSavePermission(bool EnableStatus)
        {
            btnNew.Enabled = EnableStatus;
            btnSave.Enabled = EnableStatus;
        }

        private void SetEditPermission(bool EnableStatus)
        {
            btnUpdate.Enabled = EnableStatus;
            btnSave.Enabled = EnableStatus;

        }

        #endregion

        private DataTable UserPermission(string mPageCode)
        {
            int UserId = int.Parse(Session["UserId"].ToString());
            DataTable dtPermission = new DataTable();

            dtPermission = clsComMethods.GetUserWisePermissions(UserId, mPageCode);

            return dtPermission;
        }

        #region Enable Disable Controls
        private void EnableControls(bool Status)
        {
            txtGodowncode.Enabled = Status;
            txtGodownname.Enabled = Status;
            ddlCountry.Enabled = Status;
            //ddlCity.Enabled = Status;
            //ddlFactory.Enabled = Status;
            txtEmail.Enabled = Status;
            txtFax.Enabled = Status;
            txtGodown.Enabled = Status;
            txtGodownAdd.Enabled = Status;
            txtGodowncontact.Enabled = Status;
            txtPhn1.Enabled = Status;
            txtPhn2.Enabled = Status;
            txtTelex.Enabled = Status;
            txtWebSite.Enabled = Status;

            txtTelex.Enabled = Status;

            if (Status == true)
            {
                txtRemarks.Disabled = false;
            }
            else
            {
                txtRemarks.Disabled = true;
            }
            chkStatus.Enabled = Status;
            btnGodownhelp.Enabled = Status;
        }
        #endregion

        private void LoadCountries()
        {
            CountryCls objCountry = new CountryCls();

            DataTable dtCountry = objCountry.Country_SelectAll();

            ddlCountry.DataSource = dtCountry;
            ddlCountry.DataTextField = "Name";
            ddlCountry.DataValueField = "ID";
            ddlCountry.DataBind();

        }

        private void LoadFactories(int CityId)
        {
            FactoryCls objFactory = new FactoryCls();

            DataTable dtFactory = objFactory.FactoriesByCity(CityId);

            ddlFactory.DataSource = dtFactory;
            ddlFactory.DataTextField = "Name";
            ddlFactory.DataValueField = "ID";
            ddlFactory.DataBind();
            ddlFactory.SelectedIndex = 0;
        }

        private void LoadCities(int CountryId)
        {
            CityCls objCity = new CityCls();

            DataTable dtCity = objCity.CitiesByCountry(CountryId);

            ddlCity.DataSource = dtCity;
            ddlCity.DataTextField = "Name";
            ddlCity.DataValueField = "ID";
            ddlCity.DataBind();
            ddlCity.SelectedIndex = 0;
        }



        #region Button Disable
        private void DisableButtons()
        {
            btnSave.Enabled = false;
            btnUpdate.Enabled = true;
            btnInquiry.Enabled = true;
            btnCancel.Enabled = false;
        }
        #endregion

        #region Clear Controls
        private void ClearControls()
        {
            txtGodowncode.Text = "";
            txtGodownname.Text = "";
            ddlCountry.SelectedIndex = 0;
            //ddlCity.SelectedIndex = 0;
            //ddlFactory.SelectedIndex = 0;
            txtGodowncontact.Text = "";
            txtWebSite.Text = "";
            txtGodownAdd.Text = "";

            txtPhn1.Text = "";
            txtPhn2.Text = "";
            txtEmail.Text = "";
            txtFax.Text = "";

            txtTelex.Text = "";

            lblMsg.Text = "";
            txtRemarks.Value = "";
            chkStatus.Checked = false;
            SelectedGodownId = -1;


            if (CurrentMode == "Modify")
            {
                txtGodowncode.Enabled = true;
            }
        }
        #endregion

        #region New Button Click
        protected void btnNew_Click(object sender, EventArgs e)
        {
            try
            {



                ClearControls();
                CurrentMode = "Add";
                lblMode.Text = "New Record";
                lblMode.ForeColor = System.Drawing.Color.Yellow;
                SelectedGodownId = -1;
                btnUpdate.Enabled = false;
                btnInquiry.Enabled = false;
                btnCancel.Enabled = true;
                EnableControls(true);
                txtGodowncode.Enabled = false;
                btnGodownhelp.Enabled = false;
                btnSave.Enabled = true;
                btnClear.Enabled = true;
                chkStatus.Checked = true;
                txtGodownname.Focus();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Update Button Click
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                CurrentMode = "Modify";
                lblMode.Text = "Modify Record";
                lblMode.ForeColor = System.Drawing.Color.Yellow;
                btnNew.Enabled = false;
                btnInquiry.Enabled = false;
                btnCancel.Enabled = true;
                txtGodowncode.Enabled = true;
                txtGodownname.Enabled = false;
                ddlCountry.Enabled = false;
                ddlCity.Enabled = false;
                txtGodowncontact.Enabled = false;
                txtWebSite.Enabled = false;
                txtGodownAdd.Enabled = false;
                ddlFactory.Enabled = true;
                txtPhn1.Enabled = false;
                txtPhn2.Enabled = false;
                txtEmail.Enabled = false;
                txtFax.Enabled = false;


                txtTelex.Enabled = false;

                txtRemarks.Disabled = true;
                chkStatus.Enabled = false;
                btnGodownhelp.Enabled = true;
                btnSave.Enabled = false;
                btnClear.Enabled = true;
                txtGodowncode.Focus();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Inquiry Button Click
        protected void btnInquiry_Click(object sender, EventArgs e)
        {
            try
            {
                CurrentMode = "Inquiry";
                lblMode.Text = "Inquiry Record";
                lblMode.ForeColor = System.Drawing.Color.Yellow;
                btnNew.Enabled = false;
                btnUpdate.Enabled = false;
                txtGodowncode.Enabled = true;
                btnGodownhelp.Enabled = true;
                btnSave.Enabled = false;
                btnClear.Enabled = true;
                btnCancel.Enabled = true;
                txtGodownname.Focus();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Clear Button Click
        protected void btnClear_Click(object sender, EventArgs e)
        {
            ClearControls();
        }
        #endregion

        #region Cancel Button Click
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                CurrentMode = "Cancel";
                btnNew.Enabled = true;
                btnInquiry.Enabled = true;
                btnUpdate.Enabled = true;
                btnCancel.Enabled = false;
                btnSave.Enabled = false;
                btnClear.Enabled = false;
                EnableControls(false);
                ClearControls();


                SetSavePermission(CreateRight);
                SetEditPermission(UpdateRight);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Save Button Click
        protected void btnSave_Click(object sender, EventArgs e)
        {

            try
            {

                string strGodownCode;
                int statusId;

                if (CurrentMode == "Add")
                {
                    strGodownCode = "";
                }
                else
                {
                    strGodownCode = txtGodowncode.Text.ToString();
                }

                if (chkStatus.Checked == true)
                {
                    statusId = 8;
                }
                else
                {
                    statusId = 9;
                }

                int output = godownCls.InsertGodown(SelectedGodownId, strGodownCode, txtGodownname.Text, int.Parse(ddlCountry.SelectedValue), int.Parse(ddlCity.SelectedValue), int.Parse(ddlFactory.SelectedValue), txtGodowncontact.Text, txtWebSite.Text, txtGodownAdd.Text, txtRemarks.Value.ToString(), txtPhn1.Text, txtPhn2.Text, txtEmail.Text, txtFax.Text, txtTelex.Text, statusId, SelectedUserId, CurrentMode.ToString());
                if (output > 0)
                {
                    if (CurrentMode == "Add")
                    {
                        txtGodowncode.Text = "GDN" + output.ToString("00000");
                        lblMsg.Text = "Successfully Saved!";
                        lblMsg.ForeColor = System.Drawing.Color.Green;
                    }
                    else if (CurrentMode == "Modify")
                    {
                        lblMsg.Text = "Successfully Updated!";
                        lblMsg.ForeColor = System.Drawing.Color.Green;
                    }
                }
                else if (output == -3)
                {
                    lblMsg.Text = "Already Exists!";
                    lblMsg.ForeColor = System.Drawing.Color.Orange;
                }
                else if (output == -1)
                {
                    lblMsg.Text = "Save Unsuccessful! Code Error!";
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                }
                else if (output == -2)
                {
                    lblMsg.Text = "Save Unsuccessful! SP Error!";
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion


        #region GDN Code help Button Click
        protected void btnGodownhelp_Click(object sender, EventArgs e)
        {
            try
            {
                lblMsg.Text = "";
                txtGodownname.Text = "";
                txtRemarks.Value = "";
                chkStatus.Checked = false;

                DataTable dtGodown = godownCls.FGetGodown(txtGodowncode.Text.ToString());

                if (dtGodown.Rows.Count > 0)
                {
                    dtGodownHelp = dtGodown;
                    Session["Help"] = "Godown";

                    gvHelp.DataSource = dtGodown;
                    gvHelp.DataBind();

                    gvHelp.HeaderRow.Cells[3].Visible = false;  //Godown Id
                    gvHelp.HeaderRow.Cells[4].Visible = false;  //Status Id 
                    gvHelp.HeaderRow.Cells[5].Visible = false;  //Remarks
                    foreach (GridViewRow gvr in gvHelp.Rows)
                    {
                        gvr.Cells[3].Visible = false;   //Godown Id
                        gvr.Cells[4].Visible = false;   //Status Id 
                        gvr.Cells[5].Visible = false;   //Remarks 
                    }


                    //rgData.DataSource = dtColour;
                    //rgData.DataBind();

                    mpConfirm.Show();
                }
                else
                {
                    lblMsg.Text = "No Record Found";
                    lblMsg.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Help Grid Row Command
        protected void gvHelp_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {

                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow selectedRow = gvHelp.Rows[index];

                if (Session["Help"].ToString() == "Godown")
                {
                    SelectedGodownId = Convert.ToInt32(selectedRow.Cells[3].Text);

                    DataRow[] dr = dtGodownHelp.Select("[Godown Id] = " + SelectedGodownId);

                    if (CurrentMode == "Modify")
                    {
                        txtGodowncode.Enabled = false;
                        txtGodownname.Enabled = true;
                        ddlCountry.Enabled = true;
                        chkStatus.Enabled = true;
                        txtRemarks.Disabled = false;
                        btnSave.Enabled = true;
                    }
                    else if (CurrentMode == "Inquiry")
                    {
                        txtGodowncode.Enabled = true;
                        txtGodownname.Enabled = false;
                        ddlCountry.Enabled = false;
                        chkStatus.Enabled = false;
                        txtRemarks.Disabled = true;
                        btnSave.Enabled = false;
                    }

                    int countryId = Convert.ToInt32((dr[0]["Country Id"]).ToString());
                    LoadFactories(countryId);

                    int factoryId = Convert.ToInt32((dr[0]["Factory Id"]).ToString());
                    LoadFactories(factoryId);


                    txtGodowncode.Text = dr[0]["Godown Code"].ToString();
                    txtGodownname.Text = dr[0]["Godown Name"].ToString();
                    ddlCountry.SelectedValue = (dr[0]["Country Id"]).ToString();
                    ddlFactory.SelectedValue = (dr[0]["Factory Id"]).ToString();
                    ddlCity.SelectedValue = (dr[0]["City Id"]).ToString();
                    txtGodowncontact.Text = dr[0]["GodownContactPerson"].ToString();
                    txtWebSite.Text = dr[0]["GodownWebsite"].ToString();
                    txtGodownAdd.Text = dr[0]["GodownAddress"].ToString();
                    txtPhn1.Text = dr[0]["PhoneNumber"].ToString();
                    txtPhn2.Text = dr[0]["Mobile"].ToString();
                    txtEmail.Text = dr[0]["Email"].ToString();
                    txtFax.Text = dr[0]["Fax"].ToString();

                    txtTelex.Text = dr[0]["Telex"].ToString();


                    if (Convert.ToInt32(dr[0]["Status Id"]) == 8)
                    {
                        chkStatus.Checked = true;
                    }
                    else
                    {
                        chkStatus.Checked = false;
                    }
                    txtRemarks.Value = dr[0]["Remarks"].ToString();
                }
            }
        }
        #endregion

        #region Help Grid Page Index Changing
        protected void gvHelp_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            // gvHelp.PageIndex = e.NewPageIndex;
            // gvHelp.DataSource = dt;
            // gvHelp.DataBind();
            // mpConfirm.Show();
        }
        #endregion

        protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedCountryId = Convert.ToInt32(ddlCountry.SelectedValue);
            LoadCities(selectedCountryId);
        }
        protected void ddlFactory_SelectedIndexChanged(object sender, EventArgs e)
        {

            int selectedFactoryId = Convert.ToInt32(ddlFactory.SelectedValue);
            LoadCities(selectedFactoryId);

        }

    }
}

FactoryCls

public class FactoryCls 
   {
     DataManipulation clsDataMan = new DataManipulation();

       public int InsertFactory
           (
           int FactoryId,
           string FactoryCode, 
           string FactoryName,
           int CountryId, 
           int CityId, 
           string FactoryContactPerson, 
           string FactoryWebsite, 
           string FactoryAddress,
           string TQB_No, 
           string Remarks,
           string PhoneNumber,
           string Mobile,
           string Email,
           string Fax,
           string DisplayNameForTQB,
           string Declarant_SequenceNo, 
           string Telex,  
           int StatusId,
           int UserId,
           string sMode
           )
        {
            int Output = 0;

            SqlParameter[] sqlParam = new SqlParameter[21];

            sqlParam[0] = new SqlParameter("@FactoryId", FactoryId);
            sqlParam[1] = new SqlParameter("@FactoryCode", FactoryCode);
            sqlParam[2] = new SqlParameter("@FactoryName", FactoryName);
            sqlParam[3] = new SqlParameter("@CountryId", CountryId);
            sqlParam[4] = new SqlParameter("@CityId", CityId);
            sqlParam[5] = new SqlParameter("@FactoryContactPerson", FactoryContactPerson);
            sqlParam[6] = new SqlParameter("@FactoryWebsite", FactoryWebsite);
            sqlParam[7] = new SqlParameter("@FactoryAddress", FactoryAddress);
            sqlParam[8] = new SqlParameter("@TQB_No", TQB_No);
            sqlParam[9] = new SqlParameter("@Remarks", Remarks);
            sqlParam[10] = new SqlParameter("@PhoneNumber", PhoneNumber);
            sqlParam[11] = new SqlParameter("@Mobile", Mobile);
            sqlParam[12] = new SqlParameter("@Email", Email);
            sqlParam[13] = new SqlParameter("@Fax", Fax);
            sqlParam[14] = new SqlParameter("@DisplayNameForTQB", DisplayNameForTQB);
            sqlParam[15] = new SqlParameter("@Declarant_SequenceNo", Declarant_SequenceNo);
            sqlParam[16] = new SqlParameter("@Telex", Telex);
            sqlParam[17] = new SqlParameter("@StatusId", StatusId);
            sqlParam[18] = new SqlParameter("@CreateId", UserId);
            sqlParam[19] = new SqlParameter("@Mode", sMode);
            sqlParam[20] = new SqlParameter("@iOutput", 0);
            sqlParam[20].Direction = ParameterDirection.Output;

            try
            {
                Output = clsDataMan.InsertData("Factory_InsertUpdate", sqlParam);
            }
            catch (Exception ex)
            {
                Output = -1;
            }
            return Output;
        }
        public DataTable Factory_SelectAll()
        {
            DataTable dtResults = new DataTable();

            dtResults = clsDataMan.RetrieveToDataSet("Factory_SelectAll").Tables[0];

            return dtResults;
        }
        #region Get Factory For Help
        public DataTable FGetFactory(string strFactoryCode)
        {
            DataTable rsResult = new DataTable();

            SqlParameter[] sqlParam = new SqlParameter[1];

            sqlParam[0] = new SqlParameter("@inFactory", strFactoryCode);


            rsResult = clsDataMan.RetrieveToDataSet("Factory_GetFactories", sqlParam).Tables[0];

            return rsResult;
        }
        #endregion

        //public DataTable LoadFactory()
        //{
        //    DataTable dtResults = new DataTable();
        //    SqlParameter[] sqlParam = new SqlParameter[0];

        //    dtResults = clsDataMan.RetrieveToDataSet("Factory_Select", sqlParam).Tables[0];

        //    return dtResults;

        //}




        public DataTable FactoriesByCity(int FactoryId)
        {
            DataTable rsResult = new DataTable();

            SqlParameter[] sqlParam = new SqlParameter[1];

            sqlParam[0] = new SqlParameter("@FactoryId", FactoryId);

            rsResult = clsDataMan.RetrieveToDataSet("Factory_FactoriesByCity", sqlParam).Tables[0];

            return rsResult;
        }


    }


}
4
  • What about creating a minimal (but complete) code piece that reproduces this error? Commented Mar 15, 2016 at 6:34
  • no any error, but im choose the city after not display factory drop down menu to city to included factorys Commented Mar 15, 2016 at 6:51
  • simply tell it I have 3 dropdownmenu i wanna make 3 dropdownmenu with cascade Commented Mar 15, 2016 at 6:53
  • @PhantomAssassin you need to use the ddlCity_SelectedIndexChanged inorder to Populate the factory from the ddlcity Commented Mar 22, 2016 at 10:06

2 Answers 2

6
+50

You Need to add the ddlCity_SelectedIndexChanged to the asp markup and in your

CS code :

protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
   int selectedCityId = Convert.ToInt32(ddlCity.SelectedValue);
   LoadFactories(selectedCityId);
}

I am assuming your Load Factory method is as below . You need to verify that Text and Value field names are correctly coming from the Dataset .

private void LoadFactories(int CityId)
        {
            FactoryCls objFactory = new FactoryCls();

            DataTable dtFactory = objFactory.FactoriesByCity(CityId);

            ddlFactory.DataSource = dtFactory;
            ddlFactory.DataTextField = "Name";
            ddlFactory.DataValueField = "ID";
            ddlFactory.DataBind();
            ddlFactory.SelectedIndex = 0;
        }

lastly check your aspx Markup and see that

  1. you haven't given any duplicate names for your Dropdown
  2. Make sure you set "AutoPostBack=true" in ddlCity
Sign up to request clarification or add additional context in comments.

11 Comments

Thanks for the help, but i have a little error , "Procedure or function 'Factory_FactoriesByCity' expects parameter '@CityId', which was not supplied."}
This SP ALTER PROCEDURE [dbo].[Factory_FactoriesByCity] @CityId int AS BEGIN SELECT -1 as ID ,'Select a Factory' as Name , 0 as RowNo UNION SELECT FactoryId AS ID , FactoryName AS Name , 1 As RowNo FROM Factories WHERE CityId = @CityId AND statusId = 8 ORDER BY RowNo , Name; END
@PhantomAssassin i am assuming the fault is not with the Db or not in the Asp markup, the connection between the aspx and db, there the value of Cityid is missing. so can you show me the code of factory class
Sir, Im add the FactoryClass file , can you please check my question
Sir finally its working, Im not the set this parameter and this part correctly sqlParam[0] = new SqlParameter("@CityId", CityId);
|
0

Man, you have it messed up. If you want cascade in this order: Country > City > Factory your code should look like:

protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
   int selectedCountryId = Convert.ToInt32(ddlCountry.SelectedValue);
   LoadCities(selectedCountryId);
}

protected void ddlCity_SelectedIndexChanged(object sender, EventArgs e)
{
   int selectedCityId = Convert.ToInt32(ddlCity.SelectedValue);
   LoadFactories(selectedCityId);
}

And remove ddlFactory_SelectedIndexChanged because you don't need it.

10 Comments

Did you attached ddlCity_SelectedIndexChanged to the ddlCity event?
How its working now? Does ddlFactory don't change when you select different city?
still not a working ,selected city of factory's ,Im selected city but not selected,
i have a some error message - Procedure or function 'Factory_FactoriesByCity' expects parameter '@CityId', which was not supplied
sp- ALTER PROCEDURE [dbo].[Factory_FactoriesByCity] @CityId int AS BEGIN SELECT -1 as ID ,'Select a Factory' as Name , 0 as RowNo UNION SELECT FactoryId AS ID , FactoryName AS Name , 1 As RowNo FROM Factories WHERE CityId = @CityId AND statusId = 8 ORDER BY RowNo , Name; END
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.