protected void rpItems_ItemCommand(object source, RepeaterCommandEventArgs e) { POItemDAL dal = new POItemDAL(); if (e.Item.ItemType == ListItemType.Header) { if (e.CommandName == "Add") { TextBox txtIntroAdd = e.Item.FindControl("txtIntroAdd") as TextBox; TextBox txtProductAdd = e.Item.FindControl("txtProductAdd") as TextBox; TextBox txtCodeAdd = e.Item.FindControl("txtCodeAdd") as TextBox; TextBox txtLongAdd = e.Item.FindControl("txtLongAdd") as TextBox; TextBox txtWidthAdd = e.Item.FindControl("txtWidthAdd") as TextBox; TextBox txtDeepAdd = e.Item.FindControl("txtDeepAdd") as TextBox; TextBox txtQtyAdd = e.Item.FindControl("txtQtyAdd") as TextBox; TextBox txtSquareAdd = e.Item.FindControl("txtSquareAdd") as TextBox; PurchaseOrderItem item = new PurchaseOrderItem(); item.PO_Id = POId; item.Intro = txtIntroAdd.Text; item.Product_Code = txtProductAdd.Text; item.Code = txtCodeAdd.Text; item.Long = !string.IsNullOrEmpty(txtLongAdd.Text) ? int.Parse(txtLongAdd.Text) : 0; item.Width = !string.IsNullOrEmpty(txtWidthAdd.Text) ? int.Parse(txtWidthAdd.Text) : 0; item.Deepth = !string.IsNullOrEmpty(txtDeepAdd.Text) ? int.Parse(txtDeepAdd.Text) : 0; item.Quantity = !string.IsNullOrEmpty(txtQtyAdd.Text) ? int.Parse(txtQtyAdd.Text) : 0; item.Square = !string.IsNullOrEmpty(txtSquareAdd.Text) ? double.Parse(txtSquareAdd.Text) : 0; dal.AddPOItem(item); dal.Save(); } } if (e.CommandName == "Save") { HiddenField hdId = e.Item.FindControl("hdId") as HiddenField; var item = dal.GetPOItemById(int.Parse(hdId.Value)); TextBox txtIntro = e.Item.FindControl("txtIntro") as TextBox; TextBox txtProduct = e.Item.FindControl("txtProduct") as TextBox; TextBox txtCode = e.Item.FindControl("txtCode") as TextBox; TextBox txtLong = e.Item.FindControl("txtLong") as TextBox; TextBox txtWidth = e.Item.FindControl("txtWidth") as TextBox; TextBox txtDeep = e.Item.FindControl("txtDeep") as TextBox; TextBox txtQty = e.Item.FindControl("txtQty") as TextBox; TextBox txtSquare = e.Item.FindControl("txtSquare") as TextBox; TextBox txtRemark = e.Item.FindControl("txtRemark") as TextBox; item.Intro = txtIntro.Text; item.Product_Code = txtProduct.Text; item.Code = txtCode.Text; item.Long = !string.IsNullOrEmpty(txtLong.Text) ? int.Parse(txtLong.Text) : 0; item.Width = !string.IsNullOrEmpty(txtWidth.Text) ? int.Parse(txtWidth.Text) : 0; item.Deepth = !string.IsNullOrEmpty(txtDeep.Text) ? int.Parse(txtDeep.Text) : 0; item.Quantity = !string.IsNullOrEmpty(txtQty.Text) ? int.Parse(txtQty.Text) : 0; item.Square = !string.IsNullOrEmpty(txtSquare.Text) ? double.Parse(txtSquare.Text) : 0; dal.Save(); } if (e.CommandName == "Delete") { HiddenField hdId = e.Item.FindControl("hdId") as HiddenField; dal.DeletePOItem(int.Parse(hdId.Value)); } BindControl(); SetFocus(source); }