protected void BtnRemove_loc_Click(object sender, ImageClickEventArgs e) { DataSet dsdelete = new DataSet(); Label itemcode = (Label)GridView_Location.FindControl("lblItemNo"); dsdelete = (DataSet)Session["LocationDS"]; try { ImageButton BtnLnk2 = (ImageButton)sender; GridViewRow rowGv = (GridViewRow)BtnLnk2.Parent.Parent; int rowGvIndex = rowGv.RowIndex; dsdelete.Tables[0].Rows[rowGvIndex].Delete(); dsdelete.Tables[0].AcceptChanges(); if (dsdelete.Tables[0].Rows.Count == 0) { DataRow dr = dsdelete.Tables[0].NewRow(); dsdelete.Tables[0].Rows.Add(dr); } GridView_Location.DataSource = dsdelete.Tables[0]; GridView_Location.DataBind(); Session["LocationDS"] = dsdelete; } catch (Exception ex) { success_add_item.Visible = true; success_add_item.ForeColor = Color.Red; success_add_item.Text = ex.Message; } }
protected void GridView_Location_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { DataSet ds = new DataSet(); GridView_Location.EditIndex = -1; ds = (DataSet)Session["LocationDS"]; GridView_Location.DataSource = ds.Tables[0]; GridView_Location.DataBind(); }
protected void GridView_Location_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { DataSet ds_update = new DataSet(); TextBox txtqty = (TextBox)GridView_Location.Rows[e.RowIndex].FindControl("txtQty"); DropDownList ToLocCode = (DropDownList)GridView_Location.Rows[e.RowIndex].FindControl("ddlToLoc_code"); Label itemcode = (Label)GridView_Location.Rows[e.RowIndex].FindControl("lblItemNo"); double qty = double.Parse(txtqty.Text.Trim() == "" ? "0" : txtqty.Text.Trim()); if (ToLocCode.SelectedIndex == 0) { success_add_item.Visible = true; success_add_item.Text = "Select (To Location)"; return; } if (qty <= 0 || txtqty.Text.Trim() == string.Empty) { success_add_item.Visible = true; success_add_item.Text = "Quantity can not Zero(0) or empty."; return; } ds_update = (DataSet)Session["LocationDS"]; foreach (DataRow dr in ds_update.Tables[0].Rows) { if (dr["ItemCode"].ToString() == itemcode.Text) { dr["ToLocCode"] = ToLocCode.SelectedItem.Value; dr["Qty"] = qty; } } GridView_Location.EditIndex = -1; GridView_Location.DataSource = ds_update.Tables[0]; GridView_Location.DataBind(); Session["LocationDS"] = ds_update; } catch (Exception ex) { success_add_item.Visible = true; success_add_item.ForeColor = Color.Red; success_add_item.Text = ex.Message; } }
private void create_grid() { ds = new DataSet(); ds.Tables.Add(); ds.Tables[0].Columns.Add(new DataColumn("ItemCode", typeof(string))); ds.Tables[0].Columns.Add(new DataColumn("PartItemNo", typeof(string))); ds.Tables[0].Columns.Add(new DataColumn("ItemDesc", typeof(string))); ds.Tables[0].Columns.Add(new DataColumn("FromLocCode", typeof(string))); ds.Tables[0].Columns.Add(new DataColumn("ToLocCode", typeof(string))); ds.Tables[0].Columns.Add(new DataColumn("Qty", typeof(string))); DataRow dr = ds.Tables[0].NewRow(); ds.Tables[0].Rows.Add(dr); GridView_Location.DataSource = ds.Tables[0]; GridView_Location.DataBind(); Session["LocationDS"] = ds; }
protected void GridView_Location_RowEditing(object sender, GridViewEditEventArgs e) { try { DataSet ds = new DataSet(); GridView_Location.EditIndex = e.NewEditIndex; ds = (DataSet)Session["LocationDS"]; GridView_Location.DataSource = ds.Tables[0]; GridView_Location.DataBind(); } catch (Exception ex) { success_add_item.Visible = true; success_add_item.ForeColor = Color.Red; success_add_item.Text = ex.Message; } }
private void create_row_location() { DropDownList ddlitem_code = (DropDownList)GridView_Location.FooterRow.FindControl("ddlItemCode"); DropDownList ddlToLoc_code = (DropDownList)GridView_Location.FooterRow.FindControl("ddlToLoc_code"); TextBox txtFromLoc = (TextBox)GridView_Location.FooterRow.FindControl("txtFromLoc"); TextBox txtQty = (TextBox)GridView_Location.FooterRow.FindControl("txtQty"); if (ddlitem_code.SelectedIndex == 0) { success_add_item.Visible = true; success_add_item.Text = "Select Part No."; return; } if (ddlToLoc_code.SelectedIndex == 0) { success_add_item.Visible = true; success_add_item.Text = "Select To Location "; return; } if (txtQty.Text == "" || txtQty.Text == "0") { success_add_item.Visible = true; success_add_item.Text = "Quantity cannot be empty or Zer(0)"; return; } try { DataTable dt_newrow = new DataTable(); string ItemCode, LocCode = ""; ItemCode = ddlitem_code.SelectedValue.ToString().Substring(0, 8); //00000010,01B006 LocCode = ddlitem_code.SelectedValue.ToString().Substring(9, 6); //ddlitem_code.SelectedItem.Value.ToString().Length) string qry = "SELECT PartItemNo ,ItemDesc from Item Where ItemCode = '" + ItemCode + "' AND DealerCode in ('" + Session["DealerCode"] + "','COMON')"; dt_newrow = SysFunc.GetData(qry); ds = new DataSet(); ds = (DataSet)Session["LocationDS"]; DataRow row = ds.Tables[0].NewRow(); row["ItemCode"] = ItemCode; row["PartItemNo"] = dt_newrow.Rows[0]["PartItemNo"].ToString(); row["ItemDesc"] = dt_newrow.Rows[0]["ItemDesc"].ToString(); row["FromLocCode"] = LocCode; row["ToLocCode"] = ddlToLoc_code.SelectedItem.Value; row["Qty"] = txtQty.Text.Trim(); ds.Tables[0].Rows.Add(row); GridView_Location.DataSource = ds.Tables[0]; GridView_Location.DataBind(); Session["LocationDS"] = ds; } catch (Exception ex) { success_add_item.Visible = true; success_add_item.ForeColor = Color.Red; success_add_item.Text = ex.Message; } }