protected void GVGRNItems_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (ViewState["dt_adItm"] != null) { DataTable dt = (DataTable)ViewState["dt_adItm"]; DataRow drCurrentRow = null; int rowIndex = Convert.ToInt32(e.RowIndex); if (dt.Rows.Count > 1) { dt.Rows.Remove(dt.Rows[rowIndex]); drCurrentRow = dt.NewRow(); ViewState["dt_adItm"] = dt; GVGRNItems.DataSource = dt; GVGRNItems.DataBind(); SetPreRowitm(); //float GTotal = 0; //for (int j = 0; j < GVGRNItems.Rows.Count; j++) //{ // TextBox total = (TextBox)GVGRNItems.Rows[j].FindControl("TbAddPurNetTtl"); // GTotal += Convert.ToSingle(total.Text); //} //TBGrssTotal.Text = GTotal.ToString(); } } }
private void SetInitRowPuritm() { DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("ProNam", typeof(string))); dt.Columns.Add(new DataColumn("dgrn_ItmDes", typeof(string))); dt.Columns.Add(new DataColumn("dgrn_ItmQty", typeof(string))); dt.Columns.Add(new DataColumn("dgrn_ItmInsp", typeof(string))); dt.Columns.Add(new DataColumn("dgrn_ItmReg", typeof(string))); dt.Columns.Add(new DataColumn("dgrn_ItmBal", typeof(string))); dt.Columns.Add(new DataColumn("dgrn_Rmk", typeof(string))); dr = dt.NewRow(); dr["ProNam"] = string.Empty; dr["dgrn_ItmDes"] = string.Empty; dr["dgrn_ItmQty"] = string.Empty; dr["dgrn_ItmInsp"] = "0.00"; dr["dgrn_ItmReg"] = "0.00"; dr["dgrn_ItmBal"] = string.Empty; dr["dgrn_Rmk"] = string.Empty; dt.Rows.Add(dr); //Store the DataTable in ViewState ViewState["dt_adItm"] = dt; GVGRNItems.DataSource = dt; GVGRNItems.DataBind(); }
protected void GVScrhrMGRN_RowCommand(object sender, GridViewCommandEventArgs e) { try { string cmdtxt; GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); //if (e.CommandName == "Delete") //{ // string MPurID = Server.HtmlDecode(GVScrhrMGRN.Rows[row.RowIndex].Cells[0].Text.ToString()); // cmd.Parameters.Add("@mPurID", SqlDbType.Int).Value = MPurID; // cmd = new SqlCommand("sp_del_DPur", con); // cmd.CommandType = CommandType.StoredProcedure; // con.Open(); // cmd.ExecuteNonQuery(); // con.Close(); // FillGrid(); //} //else if (e.CommandName == "Select") { string MGRNID = Server.HtmlDecode(GVScrhrMGRN.Rows[row.RowIndex].Cells[0].Text.ToString()); cmdtxt = " select tbl_mgrn.mgrn_id,mgrn_dat,mgrn_sono,tbl_mgrn.ven_id,mgrn_rmk,tbl_mgrn.ISActive " + " from tbl_mgrn inner join tbl_dgrn on tbl_mgrn.mgrn_id = tbl_dgrn.mgrn_id " + " inner join tbl_MPurOrd on tbl_mgrn.MPurOrdid = tbl_MPurOrd.MPurOrdid " + " inner join t_ven on tbl_mgrn.ven_id = t_ven.ven_id where tbl_mgrn.mgrn_id ='" + MGRNID + "'"; SqlCommand cmdSlct = new SqlCommand(cmdtxt, con); SqlDataAdapter adp = new SqlDataAdapter(cmdSlct); DataTable dt = new DataTable(); adp.Fill(dt); if (dt.Rows.Count > 0) { HFMGRN.Value = dt.Rows[0]["mgrn_id"].ToString(); TBGRNNum.Text = dt.Rows[0]["mgrn_sono"].ToString(); TBGRNDat.Text = dt.Rows[0]["mgrn_dat"].ToString(); ddlVenNam.SelectedValue = dt.Rows[0]["ven_id"].ToString(); TBRmk.Text = dt.Rows[0]["mgrn_rmk"].ToString(); chk_Act.Checked = Convert.ToBoolean(dt.Rows[0]["ISActive"].ToString()); cmdtxt = " select tbl_dgrn.ProductID,dgrn_ItmDes,dgrn_ItmQty,dgrn_ItmInsp,dgrn_ItmReg,dgrn_ItmBal,dgrn_Rmk " + " from tbl_dgrn inner join Products on tbl_dgrn.ProductID = Products.ProductID where mgrn_id = '" + MGRNID + "'"; SqlCommand cmdDslct = new SqlCommand(cmdtxt, con); SqlDataAdapter dadp = new SqlDataAdapter(cmdDslct); DataTable dt_Dgrn = new DataTable(); dadp.Fill(dt_Dgrn); if (dt_Dgrn.Rows.Count > 0) { GVGRNItems.DataSource = dt_Dgrn; GVGRNItems.DataBind(); } else { GVGRNItems.DataSource = null; GVGRNItems.DataBind(); } //for (int i = 0; i < GVAddEdtPur.Rows.Count; i++) //{ // DropDownList PurProNam = (DropDownList)GVAddEdtPur.Rows[i].FindControl("ddl_EdtPurProNam"); // PurProNam.SelectedValue = dt.Rows[0]["ProNam"].ToString(); //} //GVGRNItems.Visible = false; //TBGrssTotal.Text = dt1.Rows[0]["grossttal"].ToString();= //GrandTotal(); } } }catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); lbl_Heading.Text = "Error!"; lblalert.Text = ex.Message; } }
private void AddNewRow() { int rowIndex = 0; if (ViewState["dt_adItm"] != null) { DataTable dt = (DataTable)ViewState["dt_adItm"]; DataRow drRow = null; if (dt.Rows.Count > 0) { for (int i = 1; i <= dt.Rows.Count; i++) { //extract the TextBox values DropDownList ddlPurItm = (DropDownList)GVGRNItems.Rows[rowIndex].Cells[0].FindControl("ddlPurItm"); TextBox ItmDscptin = (TextBox)GVGRNItems.Rows[rowIndex].Cells[1].FindControl("ItmDscptin"); TextBox ItmQty = (TextBox)GVGRNItems.Rows[rowIndex].Cells[2].FindControl("ItmQty"); TextBox TbInsp = (TextBox)GVGRNItems.Rows[rowIndex].Cells[3].FindControl("TbInsp"); TextBox Tbrej = (TextBox)GVGRNItems.Rows[rowIndex].Cells[4].FindControl("Tbrej"); TextBox Tbbal = (TextBox)GVGRNItems.Rows[rowIndex].Cells[5].FindControl("Tbbal"); TextBox Tbrmk = (TextBox)GVGRNItems.Rows[rowIndex].Cells[6].FindControl("Tbrmk"); drRow = dt.NewRow(); dt.Rows[i - 1]["ProNam"] = ddlPurItm.SelectedValue; dt.Rows[i - 1]["dgrn_ItmDes"] = ItmDscptin.Text; dt.Rows[i - 1]["dgrn_ItmQty"] = ItmQty.Text; dt.Rows[i - 1]["dgrn_ItmInsp"] = TbInsp.Text; dt.Rows[i - 1]["dgrn_ItmReg"] = Tbrej.Text; dt.Rows[i - 1]["dgrn_ItmBal"] = Tbbal.Text; dt.Rows[i - 1]["dgrn_Rmk"] = Tbrmk.Text; rowIndex++; //float GTotal = 0, CRAmt = 0, DBAmt = 0; //for (int j = 0; j < GVGRNItems.Rows.Count; j++) //{ // TextBox total = (TextBox)GVGRNItems.Rows[j].FindControl("TbAddPurNetTtl"); // TextBox CRAmtttl = (TextBox)GVGRNItems.Rows[j].FindControl("Tbcramt"); // TextBox DBAmtttl = (TextBox)GVGRNItems.Rows[j].FindControl("Tbdbamt"); // GTotal += Convert.ToSingle(total.Text); // CRAmt += Convert.ToSingle(CRAmtttl.Text); // DBAmt += Convert.ToSingle(DBAmtttl.Text); //} //TBGrssTotal.Text = GTotal.ToString(); //TBCRAmtttl.Text = CRAmt.ToString(); //TBDBAmtttl.Text = DBAmt.ToString(); ddlPurItm.Focus(); } dt.Rows.Add(drRow); ViewState["dt_adItm"] = dt; GVGRNItems.DataSource = dt; GVGRNItems.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on GRNstbacks SetPreRowitm(); }