void Clrscr() { txtFormName.Text = ""; txtFormTitle.Text = ""; txtRemark.Text = ""; btnSave.Text = "Save"; hfPKEdit.Value = "0"; Divform.Visible = true; txtComponent.Text = string.Empty; txtCompSeqNo.Text = string.Empty; ViewState["dtData"] = null; LWComponent.DataSource = null; LWComponent.DataBind(); LoadFormName(); }
protected void lstvComponent_ItemCommand(object sender, ListViewCommandEventArgs e) { if (e.CommandName == "DeleteData") { HiddenField Hiddenid = e.Item.FindControl("hfDKValidationId") as HiddenField; if (Convert.ToInt32(Hiddenid.Value) == -1) { msg.GetMsg(this.Page, "Configuration Head is generated for this component, you cannot delete this record.", ""); return; } if (ViewState["dtData"] != null) { dt = (DataTable)ViewState["dtData"]; Int32 id = Convert.ToInt32(e.CommandArgument); DataRow dr = dt.Rows[id - 1]; dt.Rows.Remove(dr); ViewState["dtData"] = dt; LWComponent.DataSource = dt; LWComponent.DataBind(); } } if (e.CommandName == "EditData") { if (ViewState["dtData"] != null) { dt = (DataTable)ViewState["dtData"]; Int32 id = Convert.ToInt32(e.CommandArgument); DataRow dr = dt.Rows[id - 1]; txtComponent.Text = dr["ComponentName"].ToString(); txtCompSeqNo.Text = dr["SeqNo"].ToString(); ViewState["UpdateComponentName"] = dr["ComponentName"].ToString(); ViewState["SeqNo"] = dr["SeqNo"].ToString(); btnAdd.Text = "Update"; } else { btnAdd.Text = "Add"; } } }
protected void btnAdd_Click(object sender, EventArgs e) { if (txtComponent.Text == string.Empty) { msg.GetMsg(this.Page, "Enter Component Name.", ""); return; } if (txtCompSeqNo.Text == string.Empty) { msg.GetMsg(this.Page, "Enter Component Sequence Number.", ""); return; } if (btnAdd.Text == "Add") { if (ViewState["dtData"] != null) { dt = (DataTable)ViewState["dtData"]; Boolean ChkValidation = false; if (ViewState["dtData"] != null) { for (int i = 0; i <= dt.Rows.Count - 1; i++) { DataRow dr1 = dt.Rows[i]; if (dr1["ComponentName"].ToString() == txtComponent.Text.Trim()) { msg.GetMsg(this.Page, "Component Name Already Exist.", ""); ChkValidation = true; } if (Convert.ToDecimal(dr1["SeqNo"].ToString()) == Convert.ToDecimal(txtCompSeqNo.Text.Trim())) { msg.GetMsg(this.Page, "Component Sequence Number Alredy Exist.", ""); ChkValidation = true; } if (ChkValidation == true) { return; } } } } else { dt.Columns.Add("ComponentName"); dt.Columns.Add("SeqNo"); dt.Columns.Add("id"); dt.Columns.Add("Validationid"); } DataRow dr = dt.NewRow(); dr["ComponentName"] = txtComponent.Text; dr["SeqNo"] = txtCompSeqNo.Text.Trim(); dr["id"] = 0; dr["Validationid"] = 0; dt.Rows.Add(dr); ViewState["dtData"] = dt; if (dt.Rows.Count > 0) { LWComponent.DataSource = dt; LWComponent.DataBind(); } txtComponent.Text = string.Empty; txtCompSeqNo.Text = string.Empty; } else if (btnAdd.Text == "Update") { dt = (DataTable)ViewState["dtData"]; if (ViewState["dtData"] != null) { for (int i = 0; i <= dt.Rows.Count - 1; i++) { DataRow dr = dt.Rows[i]; if (dr["ComponentName"].ToString() == txtComponent.Text.Trim() && dr["ComponentName"].ToString() != ViewState["UpdateComponentName"].ToString()) { msg.GetMsg(this.Page, "Component Name Already Exist.", ""); return; } if (Convert.ToDecimal(dr["SeqNo"].ToString()) == Convert.ToDecimal(txtCompSeqNo.Text.Trim()) && Convert.ToDecimal(dr["SeqNo"].ToString()) != Convert.ToDecimal(ViewState["SeqNo"].ToString())) { msg.GetMsg(this.Page, "Component Sequence Number Alredy Exist.", ""); return; } if (dr["ComponentName"].ToString() == ViewState["UpdateComponentName"].ToString()) { dr["ComponentName"] = txtComponent.Text; dr["SeqNo"] = txtCompSeqNo.Text; btnAdd.Text = "Add"; if (dt.Rows.Count > 0) { LWComponent.DataSource = dt; LWComponent.DataBind(); } } } txtComponent.Text = string.Empty; txtCompSeqNo.Text = string.Empty; ViewState["UpdateComponentName"] = null; ViewState["SeqNo"] = null; } } }
void BindComponentData(DataTable dtitem) { LWComponent.DataSource = dtitem; LWComponent.DataBind(); }