protected void grdGridView_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "EditField") { hdnOperationType.Value = "Update"; int pkid = Convert.ToInt32(e.CommandArgument); hdnIdPK.Value = pkid.ToString(); MedicineBAO BAO = new MedicineBAO(); int id = Convert.ToInt32(Session["HospitalId"]); Medicine obj = BAO.GetMedicineDetailsById(pkid, id); if (obj != null) { txtMedicineName.Text = obj.MedicineName; txtMedicineCategory.Text = obj.MedicineCategory; txtRemark.Text = obj.Remark; } pnlAddForm.Visible = true; pnlGrid.Visible = false; } if (e.CommandName == "DeleteField") { int id = Convert.ToInt32(e.CommandArgument); MedicineBAO BAO = new MedicineBAO(); BAO.DeleteMedicine(id); FillGridView(); } }
protected void bntAdd_Click(object sender, EventArgs e) { string ids = string.Empty; if (lstMedcines.SelectedIndex != -1) { string alreadyExistList = string.Empty; List <Medicine> tempList = new List <Medicine>(); if (ViewState["Selected"] != null) { selectedMedicineList = (List <Medicine>)ViewState["Selected"]; } if (ViewState["SelectedMedicine"] != null) { selectedList = (List <Medicine>)ViewState["SelectedMedicine"]; tempList = (List <Medicine>)ViewState["SelectedMedicine"]; } else { selectedList = new List <Medicine>(); } foreach (ListItem li in lstMedcines.Items) { if (li.Selected == true) { int id = Convert.ToInt32(li.Value); int count = 0; if (selectedMedicineList.Count > 0) { foreach (Medicine ob in selectedMedicineList) { if (ob.PK_Medicineid == id) { alreadyExistList = alreadyExistList + ";" + ob.MedicineName; break; } count++; } if (selectedMedicineList.Count == count) { int hid = Convert.ToInt32(Session["HospitalId"]); Medicine m = obj.GetMedicineDetailsById(id, hid); selectedList.Add(m); ids = ids + "," + id.ToString(); } } else { int hid = Convert.ToInt32(Session["HospitalId"]); Medicine m = obj.GetMedicineDetailsById(id, hid); selectedList.Add(m); ids = ids + "," + id.ToString(); // selectedMedicineList.Add(m); } } } grdSelectedMedicine.DataSource = selectedList; grdSelectedMedicine.DataBind(); ViewState["SelectedMedicine"] = selectedList; if (!string.IsNullOrEmpty(ids)) { ids = ids.Substring(1, ids.Length - 1); foreach (string i in ids.Split(',')) { int hid = Convert.ToInt32(Session["HospitalId"]); Medicine m = obj.GetMedicineDetailsById(Convert.ToInt32(i), hid); selectedMedicineList.Add(m); } ViewState["Selected"] = selectedMedicineList; } if (!string.IsNullOrEmpty(alreadyExistList)) { Page.ClientScript.RegisterStartupScript(Page.GetType(), "Failuer", "alert('Already Exist items are skipped:" + alreadyExistList + "')", true); } } }