コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                if (Session["Username"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                //To store the user name and dispay it in the webform
                LblUser.Text = Session["Username"].ToString();
                //Takes the connection string from the web config and stores it in Address string
                string Address = ConfigurationManager.ConnectionStrings["LOGIN"].ConnectionString;

                //This block is used to populate the menu list according to the database
                using (SqlConnection Connection = new SqlConnection(Address))
                {
                    //Query to select Cities
                    using (SqlCommand cmd = new SqlCommand(Constants.SQLQuery.City))
                    {
                        //Mode through which the commands will be implemented on SQL Server
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection  = Connection;
                        Connection.Open();
                        LstBxCity.DataSource     = cmd.ExecuteReader();
                        LstBxCity.DataTextField  = "City";
                        LstBxCity.DataValueField = "City";
                        LstBxCity.DataBind();
                    }
                }
                //Value of the list at data value 0
                LstBxCity.Items.Insert(0, new ListItem("--Select City--", "0"));
                LstBxLocation.Items.Insert(0, new ListItem("--Select City--", "0"));
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Username"] == null)
                {
                    Response.Redirect("/Login.aspx");
                }

                using (SqlConnection Connection = new SqlConnection(Address))
                {
                    //Query to select location from a given city
                    using (SqlCommand cmd = new SqlCommand(SQLQuery.Restaurant))
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection  = Connection;
                        Connection.Open();
                        SqlDataReader ReadFromTable = cmd.ExecuteReader();
                        GridRestaurant.DataSource = ReadFromTable;
                        GridRestaurant.DataBind();
                    }
                }

                using (SqlConnection Connection = new SqlConnection(Address))
                {
                    //Query to select Cities
                    using (SqlCommand cmd = new SqlCommand(Constants.SQLQuery.City))
                    {
                        //Mode through which the commands will be implemented on SQL Server
                        cmd.CommandType = CommandType.Text;
                        cmd.Connection  = Connection;
                        Connection.Open();
                        LstBxCity.DataSource     = cmd.ExecuteReader();
                        LstBxCity.DataTextField  = "City";
                        LstBxCity.DataValueField = "City";
                        LstBxCity.DataBind();
                    }
                }
                //Value of the list at data value 0
                LstBxCity.Items.Insert(0, new ListItem("--Select City--", "0"));
                LstBxLocation.Items.Insert(0, new ListItem("--Select Location--", "0"));
            }
        }