protected void LinkButtonDeleteRow_Click(object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; GridViewRow gvRow = (GridViewRow)lb.NamingContainer; int rowID = gvRow.RowIndex + 1; if (ViewState["CurrentTable"] != null) { DataTable dt = (DataTable)ViewState["CurrentTable"]; if (dt.Rows.Count > 0) { if (gvRow.RowIndex <= dt.Rows.Count - 1) { //Remove the Selected Row data dt.Rows.Remove(dt.Rows[rowID - 1]); } } //Store the current data in ViewState for future reference ViewState["CurrentTable"] = dt; //Re bind the GridView for the updated data GvStockBrandTypeDetail.DataSource = dt; GvStockBrandTypeDetail.DataBind(); } //Set Previous Data on Postbacks SetPreviousData(); }
private void AddNewRowToGrid() { int rowIndex = 0; if (ViewState["CurrentTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the TextBox values TextBox TxtWorkDescrition = (TextBox)GvStockBrandTypeDetail.Rows[rowIndex].Cells[1].FindControl("TxtWorkDescrition"); TextBox TxtRESULT_1_1 = (TextBox)GvStockBrandTypeDetail.Rows[rowIndex].Cells[2].FindControl("TxtRESULT_1_1"); TextBox TxtRESULT_1_2 = (TextBox)GvStockBrandTypeDetail.Rows[rowIndex].Cells[3].FindControl("TxtRESULT_1_2"); DropDownList DdlPrintFlag1 = (DropDownList)GvStockBrandTypeDetail.Rows[rowIndex].Cells[4].FindControl("DdlPrintFlag1"); TextBox TxtRESULT_2_1 = (TextBox)GvStockBrandTypeDetail.Rows[rowIndex].Cells[5].FindControl("TxtRESULT_2_1"); TextBox TxtRESULT_2_2 = (TextBox)GvStockBrandTypeDetail.Rows[rowIndex].Cells[6].FindControl("TxtRESULT_2_2"); DropDownList DdlPrintFlag2 = (DropDownList)GvStockBrandTypeDetail.Rows[rowIndex].Cells[7].FindControl("DdlPrintFlag2"); TextBox TxtRESULT_3_1 = (TextBox)GvStockBrandTypeDetail.Rows[rowIndex].Cells[8].FindControl("TxtRESULT_3_1"); TextBox TxtRESULT_3_2 = (TextBox)GvStockBrandTypeDetail.Rows[rowIndex].Cells[9].FindControl("TxtRESULT_3_2"); DropDownList DdlPrintFlag3 = (DropDownList)GvStockBrandTypeDetail.Rows[rowIndex].Cells[10].FindControl("DdlPrintFlag3"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["SRNO"] = i + 1; dtCurrentTable.Rows[i - 1]["DESC_NAME"] = TxtWorkDescrition.Text; dtCurrentTable.Rows[i - 1]["RESULT_1_1"] = TxtRESULT_1_1.Text; dtCurrentTable.Rows[i - 1]["RESULT_1_2"] = TxtRESULT_1_2.Text; dtCurrentTable.Rows[i - 1]["PRINT_FLAG_1"] = DdlPrintFlag1.Text; dtCurrentTable.Rows[i - 1]["RESULT_2_1"] = TxtRESULT_2_1.Text; dtCurrentTable.Rows[i - 1]["RESULT_2_2"] = TxtRESULT_2_2.Text; dtCurrentTable.Rows[i - 1]["PRINT_FLAG_2"] = DdlPrintFlag2.Text; dtCurrentTable.Rows[i - 1]["RESULT_3_1"] = TxtRESULT_3_1.Text; dtCurrentTable.Rows[i - 1]["RESULT_3_2"] = TxtRESULT_3_2.Text; dtCurrentTable.Rows[i - 1]["PRINT_FLAG_3"] = DdlPrintFlag3.Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState["CurrentTable"] = dtCurrentTable; GvStockBrandTypeDetail.DataSource = dtCurrentTable; GvStockBrandTypeDetail.DataBind(); } } else { Response.Write("ViewState is null"); } SetPreviousData(); }
public void FillStockBrandTypeDetailGrid() { try { DataTable Dt = new DataTable(); Dt = STOCK_BRANDTYPDETLogicLayer.GetAllSTOCK_BRANDTYPEDETAILSDetailByCompany((Session["COMP_CODE"].ToString())); GvStockBrandTypeDetail.DataSource = Dt; GvStockBrandTypeDetail.DataBind(); } catch (Exception) { throw; } }
private void ClearSetInitialRow() { DataTable table = new DataTable(); DataRow dr = null; table.Columns.Add("SRNO", typeof(string)); table.Columns.Add("DESC_NAME", typeof(string)); table.Columns.Add("RESULT_1_1", typeof(string)); table.Columns.Add("RESULT_1_2", typeof(string)); table.Columns.Add("RESULT_2_1", typeof(string)); table.Columns.Add("RESULT_2_2", typeof(string)); table.Columns.Add("RESULT_3_1", typeof(string)); table.Columns.Add("RESULT_3_2", typeof(string)); table.Columns.Add("PRINT_FLAG_1", typeof(string)); table.Columns.Add("PRINT_FLAG_2", typeof(string)); table.Columns.Add("PRINT_FLAG_3", typeof(string)); dr = table.NewRow(); dr["SRNO"] = 1; dr["DESC_NAME"] = string.Empty; dr["RESULT_1_1"] = string.Empty; dr["RESULT_1_2"] = string.Empty; dr["RESULT_2_1"] = string.Empty; dr["RESULT_2_2"] = string.Empty; dr["RESULT_3_1"] = string.Empty; dr["RESULT_3_2"] = string.Empty; dr["PRINT_FLAG_1"] = string.Empty; dr["PRINT_FLAG_2"] = string.Empty; dr["PRINT_FLAG_3"] = string.Empty; table.Rows.Add(dr); //ViewState["CurrentTable"] = table; GvStockBrandTypeDetail.DataSource = table; GvStockBrandTypeDetail.DataBind(); }
protected void GvStocktBrandTypeMaster_RowCommand(object sender, GridViewCommandEventArgs e) { try { if (e.CommandName == "Deletea") { #region DELETE clear(); DataSet ds = STOCK_BRANDTYPEMASLogicLayer.GetAllIDWiseSTOCK_BRANDTYPEMASDetail(e.CommandArgument.ToString()); DataTable dt = ds.Tables[0]; DataTable dtBal = ds.Tables[1]; if (dt.Rows.Count > 0) { DivEntry.Visible = true; DivView.Visible = false; HfCompCode.Value = dt.Rows[0]["COMP_CODE"].ToString(); HfBrandTypeCode.Value = dt.Rows[0]["BRANDTYPE_CODE"].ToString(); // HfSrNo.Value = dt.Rows[0]["SRNO"].ToString(); TxtBrandTypeName.Text = dt.Rows[0]["BRANDTYPE_NAME"].ToString(); if (dtBal.Rows.Count > 0) { GvStockBrandTypeDetail.DataSource = dtBal; GvStockBrandTypeDetail.DataBind(); } } btnSave.Visible = false; btnDelete.Visible = true; Btncalldel.Visible = true; BtncallUpd.Visible = false; BtnJobComplainMas.Enabled = true; BtnBrandComplainMaster.Enabled = true; BtnViewReports.Enabled = true; ControllerDisable(); GvStockBrandTypeDetail.Enabled = false; #endregion } if (e.CommandName == "Edita") { #region EDIT clear(); DataSet ds = STOCK_BRANDTYPEMASLogicLayer.GetAllIDWiseSTOCK_BRANDTYPEMASDetail(e.CommandArgument.ToString()); DataTable dt = ds.Tables[0]; DataTable dtBal = ds.Tables[1]; if (dt.Rows.Count > 0) { DivEntry.Visible = true; DivView.Visible = false; HfCompCode.Value = dt.Rows[0]["COMP_CODE"].ToString(); HfBrandTypeCode.Value = dt.Rows[0]["BRANDTYPE_CODE"].ToString(); // HfSrNo.Value = dt.Rows[0]["SRNO"].ToString(); TxtBrandTypeName.Text = dt.Rows[0]["BRANDTYPE_NAME"].ToString(); ViewState["CurrentTable"] = dtBal; if (dtBal.Rows.Count > 0) { GvStockBrandTypeDetail.DataSource = dtBal; GvStockBrandTypeDetail.DataBind(); } BtncallUpd.Text = "UPDATE"; #endregion } #region CHECK UPDATE RIGHTS if (Session["UPDATE"] != null) { if (Session["UPDATE"].ToString() == "Y") { ControllerEnable(); } else { ControllerDisable(); } } #endregion Btncalldel.Visible = false; BtncallUpd.Visible = true; btnSave.Visible = true; BtnJobComplainMas.Enabled = true; BtnBrandComplainMaster.Enabled = true; BtnViewReports.Enabled = true; UserRights(); GvStockBrandTypeDetail.Enabled = true; } if (e.CommandName == "Viewa") { #region SET TEXT ON VIEW clear(); DataSet ds = STOCK_BRANDTYPEMASLogicLayer.GetAllIDWiseSTOCK_BRANDTYPEMASDetail(e.CommandArgument.ToString()); DataTable dt = ds.Tables[0]; DataTable dtBal = ds.Tables[1]; if (dt.Rows.Count > 0) { DivEntry.Visible = true; DivView.Visible = false; HfCompCode.Value = dt.Rows[0]["COMP_CODE"].ToString(); HfBrandTypeCode.Value = dt.Rows[0]["BRANDTYPE_CODE"].ToString(); // HfSrNo.Value = dt.Rows[0]["SRNO"].ToString(); TxtBrandTypeName.Text = dt.Rows[0]["BRANDTYPE_NAME"].ToString(); if (dtBal.Rows.Count > 0) { GvStockBrandTypeDetail.DataSource = dtBal; GvStockBrandTypeDetail.DataBind(); } } #endregion ControllerDisable(); btnSave.Visible = false; Btncalldel.Visible = false; BtncallUpd.Visible = false; BtnJobComplainMas.Enabled = true; BtnBrandComplainMaster.Enabled = true; BtnViewReports.Enabled = true; UserRights(); GvStockBrandTypeDetail.Enabled = false; } } catch (Exception ex) { lblmsg.Text = ex.Message.ToString(); } }