예제 #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //Response.Write("result is displayed");

        //GridRestaurant .DataSource
        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["restaurantConnectionString"].ConnectionString))
        {
            conn.Open();

            string         query = "select RESTAURANT_NAME,RESTAURANT_CITY,RESTAURANT_COUNTRY,CUISINE,RESTAURANT_RATING from restaurant where RESTAURANT_CITY like '%" + DropDownList1.SelectedItem.Text + "%' or  CUISINE like '%" + DropDownList2.SelectedItem.Text + "%' or  RESTAURANT_RATING like '%" + DropDownList3.SelectedItem.Text + "%'";
            SqlDataAdapter da    = new SqlDataAdapter(query, conn);
            DataTable      tab   = new DataTable();
            da.Fill(tab);
            GridRestaurant.DataSource = tab;
            GridRestaurant.DataBind();
            conn.Close();
        }
    }
예제 #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"));
            }
        }