If i click add button , it passes to previous page and add a new record next to the existing row in gridview which is in the nextpage
how to maintain values in gridview even after passing to prev page?
If i click add button , it passes to previous page and add a new record next to the existing row in gridview which is in the nextpage
Kirtan PatelPosted Oct 11, 2009, 2:04 AM
Page 1 Code
protected void Button1_Click(object sender, EventArgs e)
{
Session["Username"] = "Test1";
Session["Password"] = "Password";
Response.Redirect("~/Default2.aspx");
}
}
Page 2 Code
// Here i assumed that you are showing data from Some DataSource so I have taken Datatable Instead :)
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Username"));
dt.Columns.Add(new DataColumn("Password"));
string Username = Session["Username"].ToString();
string Passsword = Session["Password"].ToString();
if(Username != "" && Passsword != "" )
{
//Suppose yourdataGridView is Bounded To Som Datatable dt
//then Add Row to That Dt
dt.Rows.Add(Username, Passsword);
//delete the Content in Session after Adding Row
Session["Username"] = "";
Session["Password"] = "";
}
GridView1.DataSource = dt;
DataBind();
}