protected void grvMedicine_RowUpdating(object sender, GridViewUpdateEventArgs e) { int medicineId = Convert.ToInt32(grvMedicine.DataKeys[e.RowIndex].Value.ToString()); GridViewRow row = (GridViewRow)grvMedicine.Rows[e.RowIndex]; TextBox textMedicineName = (TextBox)row.Cells[1].Controls[0]; DropDownList ddlGridMedicineType = (DropDownList)row.Cells[2].Controls[1].FindControl("ddlGridMedicineType"); DropDownList ddlGridCompany = (DropDownList)row.Cells[3].Controls[1].FindControl("ddlGridCompany"); TextBox textWeight = (TextBox)row.Cells[4].Controls[0]; DropDownList ddlGridUnitType = (DropDownList)row.Cells[5].Controls[1].FindControl("ddlGridUnitType"); Core.Entity.Medicine medicine = new Core.Entity.Medicine(); medicine.MedicineName = textMedicineName.Text; medicine.MedicineTypeId = Int32.Parse(ddlGridMedicineType.SelectedValue); medicine.CompanyId = Int32.Parse(ddlGridCompany.SelectedValue); medicine.Weight = Int32.Parse(textWeight.Text); medicine.UnitTypeId = Int32.Parse(ddlGridUnitType.SelectedValue); medicine.MedicineId = Convert.ToInt32(grvMedicine.DataKeys[e.RowIndex].Value); medicineManager.Update(medicine); grvMedicine.EditIndex = -1; BindMedicineGrid(); }
protected void btnSave_Click(object sender, EventArgs e) { Core.Entity.Medicine medicine = new Core.Entity.Medicine(); medicine.MedicineName = textMedicineName.Text; medicine.MedicineTypeId = Convert.ToInt32(ddlMedicineType.SelectedValue); medicine.CompanyId = Convert.ToInt32(ddlCompany.SelectedValue); medicine.Weight = Convert.ToInt32(textWeight.Text); medicine.UnitTypeId = Convert.ToInt32(ddlUnitType.SelectedValue); medicineManager.Add(medicine); BindMedicineGrid(); ResetControls(); }