The problem is that i enter the value in the
textboxes
. when i press the save button then the in the
textboxes
show null value...
id
and name are boundfield which show the value...but
textbox
always shows the
null
...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;
using IITBAL;
using IITDAL;
public partial class Faculty_Manage_Results : System.Web.UI.Page
{
public string SessionId = null;
public string SessionPassword = null;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["id"] == null || Session["password"] == null)
{
Response.Redirect("Admin Login.aspx");
}
else
{
SessionId = Session["id"].ToString();
SessionPassword = Session["password"].ToString();
GridView1.Columns.Clear();
}
if (IsPostBack)
{
}
if (!IsPostBack)
{
LoadAssignCoursesName();
}
}
protected void LoadAssignCoursesName()
{
DataTable dt = new DataTable();
dt = IITBAL.Courses.GetAssignCoursesName(SessionId);
Course_Name.DataSource = dt;
Course_Name.DataTextField = "CourseName";
Course_Name.DataBind();
}
protected void Course_Name_TextChanged(object sender, EventArgs e)
{
Semester.Items.Clear();
Semester.Items.Insert(0, new ListItem("--Select--", ""));
string ID = Course_Name.Text;
DataTable DT = new DataTable();
DT = IITBAL.Courses.GetAssignSemesterName(SessionId, ID);
Semester.DataSource = DT;
Semester.DataTextField = "Semester";
Semester.DataBind();
if (Semester.Items.Count > 1)
{
Semester.Enabled = true;
}
else
{
Semester.Enabled = false;
}
DataTable finaldt = new DataTable();
finaldt = LoadStudentsIdAndName();
int index = 0;
foreach (DataColumn col in finaldt.Columns)
{
BoundField bfield = new BoundField();
bfield.DataField = col.ColumnName;
bfield.HeaderText = col.ColumnName;
GridView1.Columns.Insert(index, bfield);
index++;
}
int quizes = LoadDesignCourseQuizez();
for (int count = 1; count <= quizes; count++)
{
var tfield = new TemplateField();
tfield.ItemTemplate = new TextBoxColumnQ();
tfield.HeaderText = "Q" + count;
GridView1.Columns.Insert(index, tfield);
index++;
}
int assignments = LoadDesignCourseAssignments();
for (int count = 1; count <= assignments; count++)
{
var tfield = new TemplateField();
tfield.ItemTemplate = new TextBoxColumnA();
tfield.HeaderText = "A" + count;
GridView1.Columns.Insert(index, tfield);
index++;
}
int sessionals = LoadDesignCourseSessionals();
for (int count = 1; count <= sessionals; count++)
{
var tfield = new TemplateField();
tfield.ItemTemplate = new TextBoxColumnS();
tfield.HeaderText = "S" + count;
GridView1.Columns.Insert(index, tfield);
index++;
}
int terminal = 1;
for (int count = 0; count < terminal; count++)
{
var tfield = new TemplateField();
tfield.ItemTemplate = new TextBoxColumnTer();
tfield.HeaderText = "Terminal";
GridView1.Columns.Insert(index, tfield);
index++;
}
int total = 1;
for (int count = 0; count < total; count++)
{
var tfield = new TemplateField();
tfield.ItemTemplate = new TextBoxColumnTot();
tfield.HeaderText = "Total";
GridView1.Columns.Insert(index, tfield);
index++;
}
int edit = 1;
for (int count = 0; count < edit; count++)
{
var templatefield = new TemplateField();
templatefield.ItemTemplate = new LinkButtonColumn();
templatefield.HeaderText = "Edit";
GridView1.Columns.Insert(index, templatefield);
index++;
}
GridView1.DataSource = finaldt;
GridView1.DataBind();
}
protected DataTable LoadStudentsIdAndName()
{
string semester = Semester.Text.ToString();
string coursename = Course_Name.Text.ToString();
DataTable dt = new DataTable();
dt = IITBAL.Results.GetStudentIdAndName(SessionId, semester, coursename);
return dt;
}
private int LoadDesignCourseQuizez()
{
string semester = Semester.Text.ToString();
string coursename = Course_Name.Text.ToString();
DataTable dt = new DataTable();
dt = IITBAL.FacultyCourses.GetDesignCourseQuizez(SessionId, coursename, semester);
int quizez = Convert.ToInt32(dt.Rows[0]["Quizez"].ToString());
return quizez;
}
private int LoadDesignCourseAssignments()
{
string semester = Semester.Text.ToString();
string coursename = Course_Name.Text.ToString();
DataTable dt = new DataTable();
dt = IITBAL.FacultyCourses.GetDesignCourseAssignments(SessionId, coursename, semester);
int assignments = Convert.ToInt32(dt.Rows[0]["Assignments"].ToString());
return assignments;
}
private int LoadDesignCourseSessionals()
{
string semester = Semester.Text.ToString();
string coursename = Course_Name.Text.ToString();
DataTable dt = new DataTable();
dt = IITBAL.FacultyCourses.GetDesignCourseSessionals(SessionId, coursename, semester);
int sessionals = Convert.ToInt32(dt.Rows[0]["Sessionals"].ToString());
return sessionals;
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
LoadStudentsIdAndName();
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void btn_click_Click(object sender, EventArgs e)
{
Response.Redirect("FacultyMainPage.aspx");
}
class TextBoxColumnQ : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox txtBox = new TextBox();
txtBox.ID = "txtBoxQ";
txtBox.Width = 30;
txtBox.MaxLength = 4;
container.Controls.Add(txtBox);
}
}
class TextBoxColumnA : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox txtBox = new TextBox();
txtBox.ID = "txtBoxA";
txtBox.Width = 30;
txtBox.MaxLength = 4;
container.Controls.Add(txtBox);
}
}
class TextBoxColumnS : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox txtBox = new TextBox();
txtBox.ID = "txtBoxS";
txtBox.Width = 30;
txtBox.MaxLength = 4;
container.Controls.Add(txtBox);
}
}
class TextBoxColumnTer : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox txtBox = new TextBox();
txtBox.ID = "txtBoxTer";
txtBox.Width = 30;
txtBox.MaxLength = 4;
container.Controls.Add(txtBox);
}
}
class TextBoxColumnTot : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
TextBox txtBox = new TextBox();
txtBox.ID = "txtBoxTot";
txtBox.Width = 30;
txtBox.MaxLength = 4;
container.Controls.Add(txtBox);
}
}
class LinkButtonColumn : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
LinkButton edit = new LinkButton();
edit.Text = "Edit";
edit.CommandName = "Edit";
edit.ID = "btn_edit";
container.Controls.Add(edit);
}
}
Problem is here below
protected void btn_save_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
string Id = row.Cells[0].Text;
string name = row.Cells[1].Text;
TextBox textBoxq = row.FindControl("txtBoxQ") as TextBox;
TextBox textBoxa = row.FindControl("txtBoxA") as TextBox;
TextBox textBoxs = row.FindControl("txtBoxS") as TextBox;
TextBox textBoxt = row.FindControl("txtBoxTer") as TextBox;
TextBox textBoxtot = row.FindControl("txtBoxTot") as TextBox;
}
}
}
when i enter the value in
textboxes
and press the save button then in the code these
textboxes shows the null value only
id
and name shows the value.
[Edit member="Tadit"]
Corrected formatting and/or grammatical issues.
Added
pre
tags.
[/Edit]