Exemple #1
0
 protected void StateEvent(object sender, EventArgs e)
 {
     if (DropDownListState.SelectedIndex == 1)
     {
         string filePath = Server.MapPath("~/XMLFile1.xml");
         using (DataSet ds = new DataSet())
         {
             ds.ReadXml(filePath);
             DropDownListCity.DataSource     = ds;
             DropDownListCity.DataTextField  = "cityname";
             DropDownListCity.DataValueField = "cityvalue";
             DropDownListCity.DataBind();
         }
     }
     if (DropDownListState.SelectedIndex == 2)
     {
         string filePath = Server.MapPath("~/XMLFile1.xml");
         using (DataSet ds = new DataSet())
         {
             ds.ReadXml(filePath);
             DropDownListCity.DataSource     = ds;
             DropDownListCity.DataTextField  = "cityname";
             DropDownListCity.DataValueField = "cityvalue";
             DropDownListCity.DataBind();
         }
     }
 }
        protected void DropDownListState_SelectedIndexChanged(object sender, EventArgs e) //Select all Cities corresponding to the selected State
        {
            try
            {
                int StateId = Convert.ToInt32(DropDownListState.SelectedValue);

                using (SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ToString()))
                {
                    cn.Open();
                    using (SqlDataAdapter adp = new SqlDataAdapter("Select * from TblCity where StateId=" + StateId, cn))
                    {
                        DataSet ds = new DataSet();
                        adp.Fill(ds);

                        DropDownListCity.DataSource      = ds;
                        DropDownListState.DataValueField = "StateId";
                        DropDownListCity.DataValueField  = "CityId";
                        DropDownListCity.DataTextField   = "CityName";
                        DropDownListCity.DataBind();

                        DropDownListCity.Items.Insert(0, new ListItem("-------------Select City-------------", "0"));

                        if (DropDownListCity.SelectedValue == "0")  //If City is not selected then hide the label
                        {
                            lblDisplay.Visible = false;
                            DropDownListCity.Items.Insert(0, new ListItem("-------------Select City-------------", "0"));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userName"] == null || !(Session["roleNumber"].ToString().Equals("2")))
            {
                Response.Redirect("NotAuthorizatedPage.aspx");
            }
            String myConnectionString;

            myConnectionString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(myConnectionString);

            conn.Open();
            string           querycity = "select * from city order by CityName";
            MySqlCommand     cmd       = new MySqlCommand(querycity, conn);
            MySqlDataAdapter da        = new MySqlDataAdapter {
                SelectCommand = cmd
            };
            DataSet ds = new DataSet();

            da.Fill(ds);
            if (!IsPostBack)
            {
                DropDownListCity.DataTextField = ds.Tables[0].Columns["CityName"].ToString();
                DropDownListCity.DataSource    = ds.Tables[0];
                DropDownListCity.DataBind();
                DropDownListCity.SelectedItem.Text = "";
            }
            string           querydistrict = "select * from district order by Name";
            MySqlCommand     cmddistrict   = new MySqlCommand(querydistrict, conn);
            MySqlDataAdapter dadistrict    = new MySqlDataAdapter {
                SelectCommand = cmddistrict
            };
            DataSet dsdistrict = new DataSet();

            dadistrict.Fill(dsdistrict);
            if (!IsPostBack)
            {
                DropDownListDistrict.DataTextField = dsdistrict.Tables[0].Columns["Name"].ToString();
                DropDownListDistrict.DataSource    = dsdistrict.Tables[0];
                DropDownListDistrict.DataBind();
                DropDownListDistrict.SelectedItem.Text = "";
            }
            string           queryneighborhood = "select * from neighborhood order by Name";
            MySqlCommand     cmdneighborhood   = new MySqlCommand(queryneighborhood, conn);
            MySqlDataAdapter daneighborhood    = new MySqlDataAdapter {
                SelectCommand = cmdneighborhood
            };
            DataSet dsneighborhood = new DataSet();

            daneighborhood.Fill(dsneighborhood);
            if (!IsPostBack)
            {
                DropDownListNeighborhood.DataTextField = dsneighborhood.Tables[0].Columns["Name"].ToString();
                DropDownListNeighborhood.DataSource    = dsneighborhood.Tables[0];
                DropDownListNeighborhood.DataBind();
                DropDownListNeighborhood.SelectedItem.Text = "";
            }

            conn.Close();
        }
    private void fillCity()
    {
        string    Error   = "";
        DBCity    cityObj = new DBCity();
        DataTable table   = cityObj.getAllCity(ref Error);

        DropDownListCity.DataSource     = table;
        DropDownListCity.DataValueField = "CityID";
        DropDownListCity.DataTextField  = "CityName";
        DropDownListCity.DataBind();
    }
Exemple #5
0
    protected void DropDownListState_SelectedIndexChanged(object sender, EventArgs e)
    {
        string reg = DropDownListState.SelectedValue.ToString();

        con.Open();
        SqlDataAdapter adp = new SqlDataAdapter("select * from tbcty where regid ='" + reg + "' ", con);
        DataSet        ds  = new DataSet();

        adp.Fill(ds);
        DropDownListCity.DataSource = ds;

        con.Close();
        ds.Dispose();
        adp.Dispose();
        DropDownListCity.DataTextField  = "city";
        DropDownListCity.DataValueField = "cityid";
        DropDownListCity.DataSource     = ds.Tables[0];
        DropDownListCity.DataBind();
        DropDownListCity.Items.Insert(0, new ListItem("Select Your City", ""));
    }
        protected void DropDownListState_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DropDownListState.SelectedIndex == 0)
            {
                DropDownListCity.SelectedIndex = 0;
                DropDownListCity.Enabled       = false;
                DropDownListBranch.Enabled     = false;
            }
            else
            {
                DropDownListCity.Enabled = true;

                StatesCities GetCitiesByState = new StatesCities();
                DropDownListCity.DataSource     = GetCitiesByState.Get_CitiesByStateId(Convert.ToInt32(DropDownListState.SelectedValue));
                DropDownListCity.DataTextField  = "CityName";
                DropDownListCity.DataValueField = "CityID";
                DropDownListCity.DataBind();

                ListItem listatesCity = new ListItem("Select City", "");
                DropDownListCity.Items.Insert(0, listatesCity);
            }
        }
Exemple #7
0
 protected void DropDownListFrom_SelectedIndexChanged(object sender, EventArgs e)
 {
     DropDownListCity.DataSource = acontroller.getListCities(DropDownListFrom.SelectedItem.Text);
     DropDownListCity.DataBind();
     DropDownListCity.Items.Insert(0, "--Please select City--");
 }