Beispiel #1
0
    protected void AddCountryButton_Click(object sender, EventArgs e)
    {
        CountryLabel.Visible      = true;
        FlagLabel.Visible         = true;
        BreakLabel.Visible        = true;
        NewCountryTextBox.Visible = true;
        FlagFileUpload.Visible    = true;

        if (NewCountryTextBox.Text.Trim() != "")
        {
            string pic = "";
            if (FlagFileUpload.PostedFile != null)
            {
                if (FlagFileUpload.PostedFile.FileName.Trim().Length > 0 && FlagFileUpload.PostedFile.ContentLength > 0)
                {
                    pic = Path.GetFileName(FlagFileUpload.PostedFile.FileName.Trim());

                    string dir  = Server.MapPath("~/Pictures/CountryFlag/");
                    string file = Path.GetFileName(FlagFileUpload.PostedFile.FileName.Trim());

                    FlagFileUpload.PostedFile.SaveAs(dir + file);
                }
            }

            Country c1 = new Country(0, NewCountryTextBox.Text, pic);

            Countries.AddCountry(c1);

            NewCountryTextBox.Text    = "";
            CountryLabel.Visible      = false;
            FlagLabel.Visible         = false;
            BreakLabel.Visible        = false;
            NewCountryTextBox.Visible = false;
            FlagFileUpload.Visible    = false;

            CountriesDropDownList.DataSource     = Countries.GetAllCountries();
            CountriesDropDownList.DataTextField  = "Country";
            CountriesDropDownList.DataValueField = "CountryID";
            CountriesDropDownList.DataBind();
        }
    }