How to Save Country ,State ,City Add On Your Web site With Customized Message Box in C# asp.net -2022

How to Save Country ,State ,City Add On Your Web site With Customized Message Box in C# asp.net -2022

its a admin control panel is need the add country ,add state ,add city is a major of every dynamic web site concepts so we have provide the code with design and message show the successfully on your browser save record is the pages .

out put is
  we have using three table for the data base .
three pages on c# asp.net and three tables in sql  we have provide the source code
First pages Like AddCountry.asp





// code by Mukesh Kumar Date 15/03/2016
// object created for SqlConnection Class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data;
using System.Text.RegularExpressions;
using System.Net;

public partial class AddCountry : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = DBConnection.getConnection();
        cmd.Connection = con;
       
    }
    protected void But_County_Click(object sender, EventArgs e)
    {
           {
            try
            {

                con.Open();
                cmd.CommandText = "insert into CountryTable(CountryID,CountryName) values('" + TxtCountryCode.Text + "','" + TxtCountryNmae.Text + "')";
                cmd.ExecuteNonQuery();

                MessageBox.Show("Your Country Name Add Successfully Submited ", "addcountry.aspx");

            }
            catch (SqlException ex)
            {
                // lblMsg.Text = ex.Message;
            }
            finally
            {
                //lblMsg.Text = "registered succesfully";
                con.Close();
            }
        }
    }
}

Second Page -AddState.aspx


// code by Mukesh Kumar Date 15/06/2016 recreate
// object created for SqlConnection Class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data;

public partial class AddState : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = DBConnection.getConnection();
        cmd.Connection = con;


         if (!IsPostBack)
        {
            BindContrydropdown();
            //BindContrydropdown1();
            //FillGrid_Country();
            //FillGrid_State();
            //FillGrid_Region();
             
       }
    }
    
    //protected void BindContrydropdown1()
    //{
    //    //conenction path for database
    //    con.Open();
    //    SqlCommand cmd = new SqlCommand("select * from CountryTable", con);
    //    SqlDataAdapter da = new SqlDataAdapter(cmd);
    //    DataSet ds = new DataSet();
    //    da.Fill(ds);
    //    con.Close();
    //    ddlCountry1.DataSource = ds;
    //    ddlCountry1.DataTextField = "CountryName";
    //    ddlCountry1.DataValueField = "CountryID";
    //    ddlCountry1.DataBind();
    //    ddlCountry1.Items.Insert(0, new ListItem("--Select--", "0"));
    //    ddlState1.Items.Insert(0, new ListItem("--Select--", "0"));
    //    // ddlRegion.Items.Insert(0, new ListItem("--Select--", "0"));

    //}
   
    protected void BindContrydropdown()
    {
        //conenction path for database
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from CountryTable", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddlCountry.DataSource = ds;
        ddlCountry.DataTextField = "CountryName";
        ddlCountry.DataValueField = "CountryID";
        ddlCountry.DataBind();
        ddlCountry.Items.Insert(0, new ListItem("--Select--", "0"));
        ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
        // ddlRegion.Items.Insert(0, new ListItem("--Select--", "0"));

    }
   
    protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        int CountryID = Convert.ToInt32(ddlCountry.SelectedValue);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from CountryTable where CountryID=" + CountryID, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddlState.DataSource = ds;
        ddlState.DataTextField = "CountryID";
        //  ddlState.DataValueField = "CountryID";
        ddlState.DataBind();
        ddlState.Items.Insert(0, new ListItem("--Select--", "0"));
        if (ddlState.SelectedValue == "0")
        {
            //ddlRegion.Items.Clear();
            //ddlRegion.Items.Insert(0, new ListItem("--Select--", "0"));
        }
    }
    protected void ddlState_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

       
            try
            {
                con.Open();


                cmd.CommandText = "insert into StateTable(StateName,CountryID) values('" + TextBox1.Text + "','" + ddlState.SelectedValue + "')";
                cmd.ExecuteNonQuery();

                MessageBox.Show("Your State Name Add Successfully Submited ", "AddState.aspx");


            }
            catch (SqlException ex)
            {
                // lblMsg.Text = ex.Message;
            }
            finally
            {
                //lblMsg.Text = "registered succesfully";
                con.Close();
            }
        
    }
}
Thired Page AddCity.aspx

// code by Mukesh Kumar Date 15/03/2016
// object created for SqlConnection Class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Diagnostics;
using System.Data.SqlClient;
using System.Data;
public partial class AddCity : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
 
    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = DBConnection.getConnection();
        cmd.Connection = con;
        if (!IsPostBack)
        {
            BindContrydropdown1();

        }
    }

         protected void BindContrydropdown1()
    {
        //conenction path for database
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from CountryTable", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddlCountry1.DataSource = ds;
        ddlCountry1.DataTextField = "CountryName";
        ddlCountry1.DataValueField = "CountryID";
        ddlCountry1.DataBind();
        ddlCountry1.Items.Insert(0, new ListItem("--Select--", "0"));
        ddlState1.Items.Insert(0, new ListItem("--Select--", "0"));
   

    }
    protected void ddlCountry1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int CountryID = Convert.ToInt32(ddlCountry1.SelectedValue);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from StateTable where CountryID=" + CountryID, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddlState1.DataSource = ds;
        ddlState1.DataTextField = "StateName";
        ddlState1.DataValueField = "StateID";
        ddlState1.DataBind();
        ddlState1.Items.Insert(0, new ListItem("--Select--", "0"));
        if (ddlState1.SelectedValue == "0")
        {
         
        }
    }
    protected void ddlState1_SelectedIndexChanged(object sender, EventArgs e)
    {

        int StateID = Convert.ToInt32(ddlState1.SelectedValue);
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from StateTable where StateID=" + StateID, con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        ddlRegionID.DataSource = ds;
        ddlRegionID.DataTextField = "StateID";
        ddlRegionID.DataValueField = "StateID";

   
        ddlRegionID.DataBind();
        Label1.Text = "StateID";

     
    }
    protected void  But_City_Click(object sender, EventArgs e)
    {
      try
              {

                  con.Open();


                  cmd.CommandText = "insert into RegionTable(RegionName,StateID) values('" + TextBox3.Text + "','" + ddlRegionID.SelectedValue + "')";
                  cmd.ExecuteNonQuery();

                  MessageBox.Show("Your City Name Add Successfully Submited ", "addCity.aspx");


              }
              catch (SqlException ex)
              {
           
              }
              finally
              {
             
                  con.Close();
              }
          }


 
}


 

Post a Comment

Previous Post Next Post

Design a beautiful Login/Signup (with google map) in Flutter | Flutter UI | VS Code | iOS Android