protected void Page_PreRender(object sender, EventArgs e) { if (grid.UpdatedRow != null) { var city = new City { CityID = SQLDataHelper.GetInt(grid.UpdatedRow["ID"]), Name = grid.UpdatedRow["CityName"], RegionID = RegionID, CitySort = SQLDataHelper.GetInt(grid.UpdatedRow["CitySort"]) }; CityService.UpdateCity(city); } DataTable data = _paging.PageItems; while (data.Rows.Count < 1 && _paging.CurrentPageIndex > 1) { _paging.CurrentPageIndex--; data = _paging.PageItems; } var clmn = new DataColumn("IsSelected", typeof(bool)) { DefaultValue = _inverseSelection }; data.Columns.Add(clmn); if ((_selectionFilter != null) && (_selectionFilter.Values != null)) { for (int i = 0; i <= data.Rows.Count - 1; i++) { int intIndex = i; if (Array.Exists(_selectionFilter.Values, c => c == data.Rows[intIndex]["RegionID"].ToString())) { data.Rows[i]["IsSelected"] = !_inverseSelection; } } } if (data.Rows.Count < 1) { goToPage.Visible = false; } grid.DataSource = data; grid.DataBind(); pageNumberer.PageCount = _paging.PageCount; lblFound.Text = _paging.TotalRowsCount.ToString(); }
public static void InsertCity(City city) { city.CityID = SQLDataAccess.ExecuteScalar<int>("INSERT INTO [Customers].[City] (CityName, RegionID, CitySort) VALUES (@Name, @RegionID, @CitySort);SELECT scope_identity();", CommandType.Text, new SqlParameter("@Name", city.Name), new SqlParameter("@CitySort", city.CitySort), new SqlParameter("@RegionID", city.RegionID)); }
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Delete") { CityService.DeleteCity(SQLDataHelper.GetInt(e.CommandArgument)); } if (e.CommandName == "AddCity") { GridViewRow footer = grid.FooterRow; if (string.IsNullOrEmpty(((TextBox)footer.FindControl("txtNewName")).Text)) { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ffcccc"); return; } int temp; int.TryParse(((TextBox)footer.FindControl("txtNewSort")).Text, out temp); var city = new City { Name = ((TextBox)footer.FindControl("txtNewName")).Text, CitySort = temp, RegionID = RegionID }; CityService.InsertCity(city); grid.ShowFooter = false; } if (e.CommandName == "CancelAdd") { grid.FooterStyle.BackColor = System.Drawing.Color.FromName("#ccffcc"); grid.ShowFooter = false; } }
public static void UpdateCity(City city) { SQLDataAccess.ExecuteNonQuery("Update [Customers].[City] set CityName=@name, CitySort=@CitySort, RegionId=@RegionId where CityID = @id", CommandType.Text, new SqlParameter("@id", city.CityID), new SqlParameter("@name", city.Name), new SqlParameter("@CitySort", city.CitySort), new SqlParameter("@RegionID", city.RegionID)); }