Hi,
i am developing the project in Asp.Net using C#.
for this i want to pass dataset from one page to another page, but i am not getting this.
will you please help me?
Thanks.
Hi,
i am developing the project in Asp.Net using C#.
for this i want to pass dataset from one page to another page, but i am not getting this.
will you please help me?
Thanks.
You can store your DataSet in Session since you need to use it in other pages. That way you can use the value of Session, cast it as a Dataset and use it as your DataSource.
DataSet ds = //Set DataSource
Session["key"] = ds;
//Then on Page2.aspx use this codes below to use the DataSet stored in Session
if (Session["key"] != null)
{
DataSet dsCurrent = (DataSet)Session["key"];
GridView1.DataSource = dsCurrent;
GridView1.DataBind();
}
If you need to pass small amounts of data from one page to another, you can pass it in the query string and the target page can retrieve it through Request.QueryString collection (GET operation).
However, if you need to pass large amount of data you cannot pass it in the query string since Internet Explorer has maximum 2048 character limit on the address of the page. In these cases, you can pass data from one page to another using POST operation.
In your source page, define a hidden variable to hold the data to pass and pass only its ID to the target page in the query string.
you can use the following code,
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PL_Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
CreateDataSet();
}
}
private void CreateDataSet()
{
DataSet ds = objTest.GetSource();
Session["sessDataSet"] = ds;
}
}
Default3.aspx
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PL_Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetValues();
}
}
private void GetValues()
{
if (Session["sessDataSet"] != null)
{
DataSet ds = (DataSet)Session["sessDataSet"];
//Here we can use the Session Value ds
}
}
}
Bookmarks