string gl_roomid = "";
        int gl_row_index = -1;
        DataTable gl_dt = new DataTable();
        DataTable dt = new DataTable();
        

 protected void LoadData()
        {
            gl_dt = dt.Copy(); 

            gl_dt.Columns["price"].DataType = Type.GetType("System.Decimal");

            string roomid = this.txtRoomid.Text.ToString();
            string price_start = this.txtPrice_Start.Text.ToString();
            string price_end = this.txtPrice_End.Text.ToString();


            if (roomid.Length > 0)
            {
                DataRow[] rows = gl_dt.Select(" roomid='" + roomid + "'");

                if (rows.Count() > 0)
                {
                    gl_dt = rows.CopyToDataTable();
                }
                else
                {
                    gl_dt.Clear();
                }
            }

            if (price_start.Length > 0)
            {
                 DataRow[] rows = gl_dt.Select(" price >=" + price_start + " ");

                 if (rows.Count() > 0)
                 {
                     gl_dt = rows.CopyToDataTable();
                 }
                 else
                 {
                     gl_dt.Clear();
                 }

            }

            if (price_end.Length > 0)
            {
                DataRow[] rows = gl_dt.Select(" price <=" + price_end + " ");

                if (rows.Count() > 0)
                {
                    gl_dt = rows.CopyToDataTable();
                }
                else
                {
                    gl_dt.Clear();
                }

            }
                this.dataGridView1.DataSource = gl_dt;          
        }


本文转载:CSDN博客