protected void btnAddCity_Click(object sender, EventArgs e) { DropDownList _ddlPreperationDoW = (DropDownList)this.gvCityDays.Controls[0].Controls[0].Controls[0].FindControl("ddlPreperationDoW");; TextBox _tbxDeliveryDelay = (TextBox)this.gvCityDays.Controls[0].Controls[0].Controls[0].FindControl("tbxDeliveryDelay"); TextBox _tbxDeliveryOrder = (TextBox)this.gvCityDays.Controls[0].Controls[0].Controls[0].FindControl("tbxDeliveryOrder"); int _CityID = Convert.ToInt32(gvCities.SelectedDataKey.Value); control.CityPrepDaysTbl _CityPrepDays = new control.CityPrepDaysTbl(); _CityPrepDays.CityID = _CityID; _CityPrepDays.PrepDayOfWeekID = Convert.ToByte(_ddlPreperationDoW.SelectedValue); _CityPrepDays.DeliveryDelayDays = Convert.ToInt32(_tbxDeliveryDelay.Text); _CityPrepDays.DeliveryOrder = Convert.ToInt32(_tbxDeliveryOrder.Text); _CityPrepDays.InsertCityPrepDay(_CityPrepDays); gvCityDays.DataBind(); }
protected void gvCityDays_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("Update") || e.CommandName.Equals("AddCityDays")) { GridViewRow _EdittedRow = (e.CommandName.Equals("Update")) ? gvCityDays.Rows[gvCityDays.EditIndex] : gvCityDays.FooterRow; DropDownList _ddlPreperationDoW = (DropDownList)_EdittedRow.FindControl("ddlPreperationDoW"); TextBox _tbxDeliveryDelay = (TextBox)_EdittedRow.FindControl("tbxDeliveryDelay"); TextBox _tbxDeliveryOrder = (TextBox)_EdittedRow.FindControl("tbxDeliveryOrder"); Label _lblCityPrepDayID = (Label)_EdittedRow.FindControl("CityPrepDaysIDLabel"); int _CityID = Convert.ToInt32(gvCities.SelectedDataKey.Value); control.CityPrepDaysTbl _CityPrepDays = new control.CityPrepDaysTbl(); _CityPrepDays.CityID = _CityID; _CityPrepDays.PrepDayOfWeekID = Convert.ToByte(_ddlPreperationDoW.SelectedValue); _CityPrepDays.DeliveryDelayDays = Convert.ToInt32(_tbxDeliveryDelay.Text); _CityPrepDays.CityPrepDaysID = Convert.ToInt32(_lblCityPrepDayID.Text); _CityPrepDays.DeliveryOrder = Convert.ToInt32(_tbxDeliveryOrder.Text); if (e.CommandName.Equals("Update")) { _CityPrepDays.UpdateCityPrepDay(_CityPrepDays); } else { _CityPrepDays.InsertCityPrepDay(_CityPrepDays); } gvCityDays.DataBind(); upnlCities.Update(); } else if (e.CommandName.Equals("Delete")) { GridViewRow _row = (GridViewRow)((Control)e.CommandSource).NamingContainer; Label _lblCityPrepDayID = (Label)_row.FindControl("CityPrepDaysIDLabel"); control.CityPrepDaysTbl _CityPrepDays = new control.CityPrepDaysTbl(); _CityPrepDays.CityPrepDaysID = Convert.ToInt32(_lblCityPrepDayID.Text); _CityPrepDays.DeleteByCityPrepDayID(_CityPrepDays.CityPrepDaysID); gvCityDays.DataBind(); upnlCities.Update(); } }