private void GridBind() { string sWhere = ""; bool HasParam = false; //------------------------------- // Build WHERE statement //------------------------------- System.Collections.Specialized.StringDictionary Params = new System.Collections.Specialized.StringDictionary(); if (!Params.ContainsKey("paID")) { string temp = Utility.GetParam("paID"); if (Utility.IsNumeric(null, temp) && temp.Length > 0) { temp = CCUtility.ToSQL(temp, FieldTypes.Number); } else { temp = ""; } Params.Add("paID", temp); } if (!Params.ContainsKey("search")) { string temp = Utility.GetParam("search"); Params.Add("search", temp); } if (Params["paID"].Length > 0) { HasParam = true; sWhere += "H.[paID]=" + Params["paID"]; } if (Params["search"].Length > 0) { if (sWhere.Length > 0) { sWhere += " and "; } HasParam = true; sWhere += "H.[hoRoom] like '%" + Params["search"].Replace("'", "''") + "%'"; } if (HasParam) { sWhere = " WHERE (" + sWhere + ")"; } DataView MyDv; String strsql; DataSet myDs; strsql = "select [h].[hoID] as ID," + "[h].*," + "[I].[Name] as IndoorName," + "[c].[Name] as CellName," + "[s].[Name] as sunnyName " + " from ((([House] h inner join [bm_Indoor] I on [h].[indoorID]=[I].[ID]) " + " inner join [bm_cell] c on [h].[cellID]=[c].[ID])" + " inner join [bm_Sunny] s on [h].[sunnyID]=[s].[ID])"; //strsql="select top 10 meterReading.mrID,meterReading.mrYear from MeterReading order by sales DESC"; if (!HasParam) { sWhere = " where hoID=-1"; } strsql += sWhere; myDs = Utility.ExecuteSql4Ds(strsql); MyDv = myDs.Tables[0].DefaultView; if (!object.Equals(ViewState["Sort"], null)) { MyDv.Sort = ViewState["Sort"].ToString(); } DataGrid1.DataSource = MyDv; if (!object.Equals(ViewState["Page"], null)) { DataGrid1.CurrentPageIndex = int.Parse(ViewState["Page"].ToString()); } try { DataGrid1.DataBind(); } catch { DataGrid1.CurrentPageIndex = DataGrid1.PageCount - 1; DataGrid1.DataBind(); } }