Click here to Skip to main content
15,904,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is 1st page...............
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        DataRow dr;
        dt.Columns.Add(new System.Data.DataColumn("Name", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Address", typeof(String)));
        dt.Columns.Add(new System.Data.DataColumn("Cell", typeof(String)));
        if (Application["CurrentData"] == null)
        {
           
            for (int i = 0; i < +1; i++)
            {
             dt= (DataTable)ViewState["CurrentData"];
               
            }
            dr = dt.NewRow();
            dr[0]= TextBox1.Text;
            dr[1] = TextBox2.Text;
             dr[2]= TextBox3.Text;
            dt.Rows.Add(dr);
            Application["CurrentData"] = dt;
            Response.Redirect("Default3.aspx");

        }
       
        

    }
}

this is 2nd page:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


        DataTable dt = new DataTable();

        if (Application["CurrentData"] == null)
        {
            GridView1.DataSource = (DataTable)Application["CurrentData"];
            GridView1.DataBind();
        }
        Application["CurrentData"] = dt;
        }
    }
Posted
Updated 16-Mar-12 0:02am
v3

1 solution

On your second page there seems to be a small, but nevertheless significant error:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Default3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Try to retrieve the DataTable from the application dictionary
        DataTable dt = (DataTable)Application["CurrentData"];

        // If there is a table found in the application dictionary use it to bind 
        // to the gridview in order to display the data 
        if (dt != null)
        {
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }
        else
        {
            // The required DataTable object was not found so let's just set it to a new DataTable instance.
            Application["CurrentData"] = new DataTable();
        }
    }
}



Regards,

Manfred
 
Share this answer
 
v2
Comments
rockpune 16-Mar-12 6:23am    
still not getting

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