public void DelItem(object sender, EventArgs e) { CostSubjectCollection dataFromGrid = this.GetDataFromGrid(); int i = 0; while (i < dataFromGrid.Count) { if (dataFromGrid[i].SubjectID == int.Parse(this.hidSubjectID.Value)) { dataFromGrid[i].IsValid = false; if (CostSubjectAction.UpdateSubjectInfo(dataFromGrid[i])) { this.js.Text = "alert(\"操作成功!\");"; this.dgSubject.EditItemIndex = -1; break; } this.js.Text = "alert(\"操作失败!\");"; break; } else { i++; } } this.BindData(); }
public void CreateNewItem(object sender, EventArgs e) { CostSubjectCollection dataFromGrid = this.GetDataFromGrid(); CostSubjectCollection costSubjectCollection = new CostSubjectCollection(); for (int i = 0; i < dataFromGrid.Count; i++) { dataFromGrid[i].IsEdit = false; if (i != 0 && dataFromGrid[i].FirstNum != dataFromGrid[i - 1].FirstNum && dataFromGrid[i - 1].FirstNum == int.Parse(this.hidFirst.Value)) { CostSubjectInfo newItem = CostSubjectAction.GetNewItem(dataFromGrid[i - 1].FirstNum); this.dgSubject.EditItemIndex = i; costSubjectCollection.Add(newItem); } costSubjectCollection.Add(dataFromGrid[i]); if (i == dataFromGrid.Count - 1 && dataFromGrid[i].FirstNum == int.Parse(this.hidFirst.Value)) { CostSubjectInfo newItem2 = CostSubjectAction.GetNewItem(dataFromGrid[i].FirstNum); this.dgSubject.EditItemIndex = i + 1; costSubjectCollection.Add(newItem2); } } this.dgSubject.DataSource = costSubjectCollection; this.dgSubject.DataBind(); }
private void BindData() { CostSubjectCollection costSubjectInfos = CostSubjectAction.GetCostSubjectInfos(); this.dgSubject.DataSource = costSubjectInfos; this.dgSubject.DataBind(); }
protected void btnNew_Click(object sender, EventArgs e) { CostSubjectCollection dataFromGrid = this.GetDataFromGrid(); dataFromGrid.Add(CostSubjectAction.GetFistNewItem()); this.dgSubject.EditItemIndex = dataFromGrid.Count - 1; this.dgSubject.DataSource = dataFromGrid; this.dgSubject.DataBind(); }