sending all selected items in gridview to next page


protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add(“ImgPath”, typeof(string));
dt.Columns.Add(“Name”, typeof(string));
dt.Columns.Add(“Desc”, typeof(string));
dt.Columns.Add(“Price”, typeof(string));
Session[“datatable”] = null;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl(“chkSelect”);
if (chk != null)
{
if (chk.Checked)
{
try
{
string ImgPath = ((Image)GridView1.Rows[i].Cells[0].FindControl(“image”)).ImageUrl;
string Name = ((Label)GridView1.Rows[i].Cells[0].FindControl(“lblName”)).Text;
string Desc = ((Label)GridView1.Rows[i].Cells[0].FindControl(“lb”)).Text;
string Price = ((Label)GridView1.Rows[i].Cells[0].FindControl(“lblPrice”)).Text;

if (Session[“datatable”] == null)
{
Session.Contents.Clear();
DataRow dr = dt.NewRow();
dr[0] = ImgPath;
dr[1] = Name;
dr[2] = Desc;
dr[3] = Price;
dt.Rows.Add(dr);
Session[“datatable”] = dt;
}
else
{
dt = (DataTable)Session[“datatable”];
DataRow dr = dt.NewRow();
dr[0] = ImgPath;
dr[1] = Name;
dr[2] = Desc;
dr[3] = Price;
dt.Rows.Add(dr);
Session[“datatable”] = dt;
}

}

catch (Exception ex)
{
LblId.Text = ex.Message;

}
}
}

}
Response.Redirect(“~/Home/Receive.aspx”);
}
In Receive Page
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(“ImgPath”, typeof(string));
dt.Columns.Add(“Name”, typeof(string));
dt.Columns.Add(“Desc”, typeof(string));
dt.Columns.Add(“Price”, typeof(string));
if (Session[“datatable”] != null)
{
dt = (DataTable)Session[“datatable”];
GridView1.DataSource = dt;
GridView1.DataBind();
}
else if (Session[“datatable”] == null)
Label1.Text = “NO Product is Selected…”;

}
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}

 
}   

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s