protected void LinkButton1_Click(object sender, EventArgs e) { LinkButton lb = (LinkButton)sender; GridViewRow gvRow = (GridViewRow)lb.NamingContainer; int rowID = gvRow.RowIndex; if (ViewState["CurrentTable"] != null) { DataTable dt = (DataTable)ViewState["CurrentTable"]; if (dt.Rows.Count > 1) { if (gvRow.RowIndex < dt.Rows.Count - 1) { //Remove the Selected Row data and reset row number dt.Rows.Remove(dt.Rows[rowID]); ResetRowID(dt); } } //Store the current data in ViewState for future reference ViewState["CurrentTable"] = dt; //Re bind the GridView for the updated data GridviewResourceDetail.DataSource = dt; GridviewResourceDetail.DataBind(); } //Set Previous Data on Postbacks SetPreviousData(); }
private void AddNewRowToGrid() { if (ViewState["CurrentTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1; //add new row to DataTable dtCurrentTable.Rows.Add(drCurrentRow); //Store the current data to ViewState for future reference ViewState["CurrentTable"] = dtCurrentTable; for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++) { //extract the DropDownList Selected Items DropDownList ddl = (DropDownList)GridviewResourceDetail.Rows[i].Cells[1].FindControl("ResourceTypeID"); TextBox box2 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("NoOfResources"); DropDownList ddl1 = (DropDownList)GridviewResourceDetail.Rows[i].Cells[3].FindControl("ddlPrimary"); DropDownList ddl2 = (DropDownList)GridviewResourceDetail.Rows[i].Cells[4].FindControl("ddlSecondry"); DropDownList ddl3 = (DropDownList)GridviewResourceDetail.Rows[i].Cells[5].FindControl("ddlTernary"); TextBox box3 = (TextBox)GridviewResourceDetail.Rows[i].Cells[6].FindControl("StartDate"); TextBox box4 = (TextBox)GridviewResourceDetail.Rows[i].Cells[7].FindControl("EndDate"); //box3.Attributes["min"] = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"); //box4.Attributes["min"] = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"); dtCurrentTable.Rows[i]["ResourceTypeID"] = ddl.SelectedValue; dtCurrentTable.Rows[i]["NoOfResources"] = box2.Text.Trim(); dtCurrentTable.Rows[i]["PrimarySkill"] = ddl1.SelectedValue; dtCurrentTable.Rows[i]["SecondrySkill"] = ddl2.SelectedValue; dtCurrentTable.Rows[i]["TernarySkill"] = ddl3.SelectedValue; dtCurrentTable.Rows[i]["StartDate"] = box3.Text.Trim(); dtCurrentTable.Rows[i]["EndDate"] = box4.Text.Trim(); } //Rebind the Grid with the current data to reflect changes GridviewResourceDetail.DataSource = dtCurrentTable; GridviewResourceDetail.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on Postbacks SetPreviousData(); }
private void SetInitialRow() { DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("RowNumber", typeof(string))); dt.Columns.Add(new DataColumn("ResourceTypeID", typeof(Int32))); //for DropDownList selected item dt.Columns.Add(new DataColumn("NoOfResources", typeof(float))); //for TextBox value dt.Columns.Add(new DataColumn("PrimarySkill", typeof(string))); dt.Columns.Add(new DataColumn("SecondrySkill", typeof(string))); //for List selected item dt.Columns.Add(new DataColumn("TernarySkill", typeof(string))); //for List selected item dt.Columns.Add(new DataColumn("StartDate", typeof(string))); //for Start Date dt.Columns.Add(new DataColumn("EndDate", typeof(string))); //for End Date //Set the Default value. //dt.Columns["NoOfResources"].DefaultValue = 5; dr = dt.NewRow(); dr["RowNumber"] = 1; //dr["NoOfResources"] = 5; dr["StartDate"] = string.Empty; dr["EndDate"] = string.Empty; dt.Rows.Add(dr); //Store the DataTable in ViewState for future reference ViewState["CurrentTable"] = dt; //Bind the Gridview GridviewResourceDetail.DataSource = dt; GridviewResourceDetail.DataBind(); //After binding the gridview, we can then extract and fill the DropDownList with Data DropDownList ddl = (DropDownList)GridviewResourceDetail.Rows[0].Cells[1].FindControl("ResourceTypeID"); DropDownList ddl1 = (DropDownList)GridviewResourceDetail.Rows[0].Cells[3].FindControl("ddlPrimary"); DropDownList ddl2 = (DropDownList)GridviewResourceDetail.Rows[0].Cells[4].FindControl("ddlSecondry"); DropDownList ddl3 = (DropDownList)GridviewResourceDetail.Rows[0].Cells[5].FindControl("ddlTernary"); //ListBox ddl2 = (ListBox)GridviewResourceDetail.Rows[0].Cells[3].FindControl("SkillID1"); TextBox box3 = (TextBox)GridviewResourceDetail.Rows[0].Cells[6].FindControl("StartDate"); TextBox box4 = (TextBox)GridviewResourceDetail.Rows[0].Cells[7].FindControl("EndDate"); //box3.Attributes["min"] = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"); //box4.Attributes["min"] = DateTime.Now.AddDays(7).ToString("yyyy-MM-dd"); ClsCommon.ddlGetRoleforDemand(ddl); ClsCommon.ddlGetSkillddl(ddl1, "Select Primary Skill"); ClsCommon.ddlGetSkillddl(ddl2, "Select Secondry Skill"); ClsCommon.ddlGetSkillddl(ddl3, "Select Ternary Skill"); //ClsCommon.ddlGetSkillDDL(ddl1); //ClsCommon.ddlGetSkill(ddl2); }
private void SetInitialRow() { DataTable dt = new DataTable(); DataRow dr = null; dt.Columns.Add(new DataColumn("RowNumber", typeof(string))); dt.Columns.Add(new DataColumn("ResourceTypeID", typeof(Int32))); //for DropDownList selected item dt.Columns.Add(new DataColumn("NoOfResources", typeof(Int32))); //for TextBox value dt.Columns.Add(new DataColumn("SkillID", typeof(string))); //for List selected item dt.Columns.Add(new DataColumn("StartDate", typeof(string))); //for Start Date dt.Columns.Add(new DataColumn("EndDate", typeof(string))); //for End Date //Set the Default value. dt.Columns["NoOfResources"].DefaultValue = 5; dr = dt.NewRow(); dr["RowNumber"] = 1; //dr["Column1"] = string.Empty; dr["NoOfResources"] = 5; dr["StartDate"] = string.Empty; dr["EndDate"] = string.Empty; dt.Rows.Add(dr); //Store the DataTable in ViewState for future reference ViewState["CurrentTable"] = dt; //Bind the Gridview GridviewResourceDetail.DataSource = dt; GridviewResourceDetail.DataBind(); //After binding the gridview, we can then extract and fill the DropDownList with Data DropDownList ddl = (DropDownList)GridviewResourceDetail.Rows[0].Cells[1].FindControl("ResourceTypeID"); ListBox ddl1 = (ListBox)GridviewResourceDetail.Rows[0].Cells[3].FindControl("SkillID"); //DropDownList ddl2 = (DropDownList)GridviewResourceDetail.Rows[0].Cells[4].FindControl("DropDownList2"); ClsCommon.ddlGetDesignation(ddl); ClsCommon.ddlGetSkill(ddl1); }
protected void Add_Resource_Demand(object sender, EventArgs e) { try { DataTable data = new DataTable(); CPT_ResourceDemand resourceDemandDetails = new CPT_ResourceDemand(); List <CPT_ResourceMaster> lstdetils = new List <CPT_ResourceMaster>(); lstdetils = (List <CPT_ResourceMaster>)Session["UserDetails"]; resourceDemandDetails.RequestID = ClsCommon.GetRandomNumber(111111, 999999).ToString(); resourceDemandDetails.AccountID = Convert.ToInt32(AccountMasterID.SelectedValue); resourceDemandDetails.CityID = Convert.ToInt32(CityID.SelectedValue); resourceDemandDetails.OpportunityID = Convert.ToInt32(OpportunityID.SelectedValue); resourceDemandDetails.SalesStageID = Convert.ToInt32(SalesStageMasterID.SelectedValue); resourceDemandDetails.ProcessName = processName.Text.Trim(); resourceDemandDetails.DateOfCreation = DateTime.Now; resourceDemandDetails.DateOfModification = DateTime.Now; resourceDemandDetails.ResourceRequestBy = lstdetils[0].EmployeeMasterID; resourceDemandDetails.StatusMasterID = Convert.ToInt32(StatusMasterID.SelectedValue); resourceDemandDetails.PriorityID = Convert.ToInt32(PriorityID.SelectedValue); ResourceDemandBL insertResourceDemand = new ResourceDemandBL(); insertResourceDemand.Insert(resourceDemandDetails); if (ViewState["CurrentTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1; //add new row to DataTable dtCurrentTable.Rows.Add(drCurrentRow); //Store the current data to ViewState for future reference ViewState["CurrentTable"] = dtCurrentTable; for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++) { //extract the DropDownList Selected Items DropDownList ddl = (DropDownList)GridviewResourceDetail.Rows[i].Cells[1].FindControl("ResourceTypeID"); //TextBox box1 = (TextBox)GridviewResourceDetail.Rows[i].Cells[1].FindControl("TextBox1"); TextBox box2 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("NoOfResources"); dtCurrentTable.Rows[i]["ResourceTypeID"] = ddl.SelectedValue; dtCurrentTable.Rows[i]["NoOfResources"] = box2.Text.Trim(); ListBox ddl1 = (ListBox)GridviewResourceDetail.Rows[i].Cells[3].FindControl("SkillID"); // Update the DataRow with the DDL Selected Items string message = ""; foreach (var z in ddl1.GetSelectedIndices()) { message += ddl1.Items[z].Value + ","; } message = message.Remove(message.Length - 1).Trim(); dtCurrentTable.Rows[i]["SkillID"] = message; Skill = message.Split(','); id.Add(Skill); //dtCurrentTable.Rows[i]["SkillID"] = id; TextBox box3 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("StartDate"); TextBox box4 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("EndDate"); dtCurrentTable.Rows[i]["StartDate"] = box3.Text.Trim(); dtCurrentTable.Rows[i]["EndDate"] = box4.Text.Trim(); } //Rebind the Grid with the current data to reflect changes GridviewResourceDetail.DataSource = dtCurrentTable; GridviewResourceDetail.DataBind(); } data = dtCurrentTable; } CPT_ResourceDetails demandDetails = new CPT_ResourceDetails(); ResourceDetailsBL insertDemandDetails = new ResourceDetailsBL(); for (int i = 0; i < data.Rows.Count - 1; i++) { demandDetails.RequestID = resourceDemandDetails.RequestID; demandDetails.ResourceTypeID = Convert.ToInt32(data.Rows[i]["ResourceTypeID"]); demandDetails.NoOfResources = Convert.ToInt32(data.Rows[i]["NoOfResources"]); demandDetails.SkillID = data.Rows[i]["SkillID"].ToString().Trim(); demandDetails.StartDate = Convert.ToDateTime(data.Rows[i]["StartDate"]); demandDetails.EndDate = Convert.ToDateTime(data.Rows[i]["EndDate"]); insertDemandDetails.Insert(demandDetails); } Response.Redirect("ResourceDemand.aspx"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void AddNewRowToGrid() { if (ViewState["CurrentTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1; //add new row to DataTable dtCurrentTable.Rows.Add(drCurrentRow); //Store the current data to ViewState for future reference ViewState["CurrentTable"] = dtCurrentTable; for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++) { //extract the DropDownList Selected Items DropDownList ddl = (DropDownList)GridviewResourceDetail.Rows[i].Cells[1].FindControl("ResourceTypeID"); //TextBox box1 = (TextBox)GridviewResourceDetail.Rows[i].Cells[1].FindControl("TextBox1"); TextBox box2 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("NoOfResources"); dtCurrentTable.Rows[i]["ResourceTypeID"] = ddl.SelectedValue; //dtCurrentTable.Rows[i]["Column1"] = box1.Text; dtCurrentTable.Rows[i]["NoOfResources"] = box2.Text.Trim(); ListBox ddl1 = (ListBox)GridviewResourceDetail.Rows[i].Cells[3].FindControl("SkillID"); // Update the DataRow with the DDL Selected Items string message = ""; foreach (var z in ddl1.GetSelectedIndices()) { message += ddl1.Items[z].Value + ","; } message = message.Remove(message.Length - 1).Trim(); dtCurrentTable.Rows[i]["SkillID"] = message; Skill = message.Split(','); id.Add(Skill); //dtCurrentTable.Rows[i]["SkillID"] = id; TextBox box3 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("StartDate"); TextBox box4 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("EndDate"); dtCurrentTable.Rows[i]["StartDate"] = box3.Text.Trim(); dtCurrentTable.Rows[i]["EndDate"] = box4.Text.Trim(); } //Rebind the Grid with the current data to reflect changes GridviewResourceDetail.DataSource = dtCurrentTable; GridviewResourceDetail.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on Postbacks SetPreviousData(); }
protected void Add_Resource_Demand(object sender, EventArgs e) { try { DataTable data = new DataTable(); CPT_ResourceDemand resourceDemandDetails = new CPT_ResourceDemand(); List <CPT_ResourceMaster> lstdetils = new List <CPT_ResourceMaster>(); lstdetils = (List <CPT_ResourceMaster>)Session["UserDetails"]; resourceDemandDetails.RequestID = ClsCommon.GetRandomNumber(111111, 999999).ToString(); resourceDemandDetails.AccountID = Convert.ToInt32(AccountMasterID.SelectedValue); int CityID = ResourceDemandBL.getCityID(Convert.ToInt32(AccountMasterID.SelectedValue)); resourceDemandDetails.CityID = CityID; resourceDemandDetails.OpportunityID = Convert.ToInt32(OpportunityID.SelectedValue); resourceDemandDetails.SalesStageID = Convert.ToInt32(SalesStageMasterID.SelectedValue); resourceDemandDetails.ProcessName = processName.Text.Trim(); resourceDemandDetails.DateOfCreation = DateTime.Now; resourceDemandDetails.DateOfModification = DateTime.Now; resourceDemandDetails.ResourceRequestBy = lstdetils[0].EmployeeMasterID; resourceDemandDetails.StatusMasterID = 19; resourceDemandDetails.PriorityID = 27; AccountName = AccountMasterID.SelectedItem.Text.Trim(); ResourceDemandBL insertResourceDemand = new ResourceDemandBL(); //insertResourceDemand.Insert(resourceDemandDetails); if (ViewState["CurrentTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumber"] = dtCurrentTable.Rows.Count + 1; //add new row to DataTable dtCurrentTable.Rows.Add(drCurrentRow); //Store the current data to ViewState for future reference ViewState["CurrentTable"] = dtCurrentTable; for (int i = 0; i < dtCurrentTable.Rows.Count - 1; i++) { //extract the DropDownList Selected Items DropDownList ddl = (DropDownList)GridviewResourceDetail.Rows[i].Cells[1].FindControl("ResourceTypeID"); DropDownList ddl1 = (DropDownList)GridviewResourceDetail.Rows[i].Cells[3].FindControl("ddlPrimary"); DropDownList ddl2 = (DropDownList)GridviewResourceDetail.Rows[i].Cells[4].FindControl("ddlSecondry"); DropDownList ddl3 = (DropDownList)GridviewResourceDetail.Rows[i].Cells[5].FindControl("ddlTernary"); //TextBox box1 = (TextBox)GridviewResourceDetail.Rows[i].Cells[1].FindControl("TextBox1"); TextBox box2 = (TextBox)GridviewResourceDetail.Rows[i].Cells[2].FindControl("NoOfResources"); TextBox box3 = (TextBox)GridviewResourceDetail.Rows[i].Cells[6].FindControl("StartDate"); TextBox box4 = (TextBox)GridviewResourceDetail.Rows[i].Cells[7].FindControl("EndDate"); dtCurrentTable.Rows[i]["ResourceTypeID"] = ddl.SelectedValue; dtCurrentTable.Rows[i]["NoOfResources"] = box2.Text.Trim(); dtCurrentTable.Rows[i]["PrimarySkill"] = ddl1.SelectedValue; dtCurrentTable.Rows[i]["SecondrySkill"] = ddl2.SelectedValue; dtCurrentTable.Rows[i]["TernarySkill"] = ddl3.SelectedValue; dtCurrentTable.Rows[i]["StartDate"] = box3.Text.Trim(); dtCurrentTable.Rows[i]["EndDate"] = box4.Text.Trim(); lstRoles.Add(ddl.SelectedItem.Text); lstSkills.Add(ddl1.SelectedItem.Text + "," + ddl2.SelectedItem.Text + "," + ddl3.SelectedItem.Text); lstStartDate.Add(box3.Text.Trim()); lstEnddate.Add(box4.Text.Trim()); } //Rebind the Grid with the current data to reflect changes GridviewResourceDetail.DataSource = dtCurrentTable; GridviewResourceDetail.DataBind(); } data = dtCurrentTable; } ResourceDetailsBL insertDemandDetails = new ResourceDetailsBL(); List <CPT_ResourceDetails> lstdetails = new List <CPT_ResourceDetails>(); for (int i = 0; i < data.Rows.Count - 1; i++) { CPT_ResourceDetails details = new CPT_ResourceDetails(); details.RequestID = resourceDemandDetails.RequestID; details.ResourceTypeID = Convert.ToInt32(data.Rows[i]["ResourceTypeID"]); details.NoOfResources = (float)Convert.ToDouble(data.Rows[i]["NoOfResources"]); details.SkillID = data.Rows[i]["PrimarySkill"].ToString().Trim() + "," + data.Rows[i]["SecondrySkill"].ToString().Trim() + "," + data.Rows[i]["TernarySkill"].ToString().Trim(); details.StartDate = Convert.ToDateTime(data.Rows[i]["StartDate"]); details.EndDate = Convert.ToDateTime(data.Rows[i]["EndDate"]); lstdetails.Add(details); resourceDemandDetails.CPT_ResourceDetails = lstdetails; //insertDemandDetails.Insert(demandDetails); } insertResourceDemand.Insert(resourceDemandDetails); EmailNew(lstSkills, lstRoles, processName.Text.Trim(), lstStartDate, lstEnddate, AccountName); // Email(); Response.Redirect("ResourceDemand.aspx"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }