protected void DegreeRemove_Click(object sender, EventArgs e) { //create new datatable, cast datatable of viewstate DataTable dtCurrentTable = (DataTable)ViewState["CurrentTableDegree"]; DataRow drCurrentRow = null; int rowIndex = 0; if (dtCurrentTable.Rows.Count > 1) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the values DropDownList degreeList = (DropDownList)DegreeList_GridView.Rows[rowIndex].Cells[1].FindControl("DegreeList"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumberDegree"] = i; dtCurrentTable.Rows[i - 1]["Column1Degree"] = degreeList.Text; rowIndex++; } dtCurrentTable.Rows[rowIndex - 1].Delete(); ViewState["CurrentTableProgram"] = dtCurrentTable; DegreeList_GridView.DataSource = dtCurrentTable; DegreeList_GridView.DataBind(); SetPreviousDegreeData(); } }
protected void ClearFields() { ProgramName.Text = ""; CredentialType.SelectedIndex = 0; ProgramLink.Text = ""; ProgramLength.Text = ""; ProgramLengthDDL.SelectedIndex = 0; WorkOutdoors.Checked = false; ShiftWork.Checked = false; Travel.Checked = false; Activated.Checked = false; CompetitiveAdv.Text = ""; EntReqDetail.Text = ""; CategoryList.SelectedIndex = 0; ShowCoursesView.Checked = false; ShowDipPathView.Checked = false; ShowDegPathView.Checked = false; Course_Gridview.DataBind(); SetInitialCourse(); Program_GridView.DataBind(); SetInitialProgram(); DegreeList_GridView.DataBind(); SetInitialDegree(); }
private void AddNewRowToDegree() { int rowIndex = 0; if (ViewState["CurrentTableDegree"] != null) { //create new datatable, cast datatable of viewstate DataTable dtCurrentTable = (DataTable)ViewState["CurrentTableDegree"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { //extract the values DropDownList degreeList = (DropDownList)DegreeList_GridView.Rows[rowIndex].Cells[1].FindControl("DegreeList"); drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["RowNumberDegree"] = i + 1; dtCurrentTable.Rows[i - 1]["Column1Degree"] = degreeList.Text; rowIndex++; } dtCurrentTable.Rows.Add(drCurrentRow); ViewState["CurrentTableDegree"] = dtCurrentTable; DegreeList_GridView.DataSource = dtCurrentTable; DegreeList_GridView.DataBind(); } } else { Response.Write("ViewState is null"); } //Set Previous Data on Postbacks SetPreviousDegreeData(); }
//---------------------------------------// //---------DEGREE GRIDVIEW CODE----------// private void SetInitialDegree() { //Create DataTable DataTable dt = new DataTable(); DataRow dr = null; //Add initail values to DataTable dt.Columns.Add(new DataColumn("RowNumberDegree", typeof(string))); dt.Columns.Add(new DataColumn("Column1Degree", typeof(string))); dr = dt.NewRow(); dr["RowNumberDegree"] = 1; dr["Column1Degree"] = string.Empty; dt.Rows.Add(dr); dr = dt.NewRow(); //Store the DataTable in ViewState ViewState["CurrentTableDegree"] = dt; DegreeList_GridView.DataSource = dt; DegreeList_GridView.DataBind(); }