Click here to Skip to main content
16,020,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to edit and delete items from gridview rows without using database
Posted
Comments
Sinisa Hajnal 11-Dec-14 6:46am    
What have you tried? There are methods to remove and add rows...
Member 11220730 11-Dec-14 7:06am    
protected void btnAdd_Click(object sender, EventArgs e)
{



if (Session["Data"] == null) //Checking if the session contain any value.
{
DataTable dt = new DataTable(); //creating the columns.
dt.Columns.Add("Course");
dt.Columns.Add("Mark");
dt.Columns.Add("Percentage");
dt.Columns.Add("CourseCompletedYear");
DataRow dr = dt.NewRow(); //Create a new row and add the row values.
dr[0] = ddlCourse.SelectedItem.Text;
dr[1] = txtMark.Text;
dr[2] = txtPercentage.Text;
dr[3] = txtCourseCopmYear.Text;
dt.Rows.Add(dr);

GridViewCandidate.DataSource = dt; //Populate values to Gridview.
GridViewCandidate.DataBind();

Session["Data"] = dt; //Storing that table into session.
}
else
{
DataTable dt = new DataTable();
dt = (DataTable)Session["Data"]; //Retrieve the stored table from session.

DataRow dr = dt.NewRow(); //Adding a new row to existing table.
dr[0] = ddlCourse.SelectedItem.Text;
dr[1] = txtMark.Text;
dr[2] = txtPercentage.Text;
dr[3] = txtCourseCopmYear.Text;
dt.Rows.Add(dr);

GridViewCandidate.DataSource = dt; //Populate new table values to Gridview.
GridViewCandidate.DataBind();

Session.Remove("Data"); //Clear the session.
Session["Data"] = dt; //Store the new table to the session.
}
Member 11220730 11-Dec-14 7:07am    
how can i remove row from the gridview.?

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900