Click here to Skip to main content
15,902,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear Friends,

I have an issue regarding the data movement from one web form to another web form. I have a grid in which there is a link to add delivery schedule for each item listed in the grid.

When I click on that link a new window gets popped up in which i can add the delivery schedule for the respective item and stores that delivery schedule data (for the item) into a session variable(Session["dt"]). And for this item when i click on the submit button on the parent web form, I captures the delivery schedule data from the session variable and enters it into the database.

But the problem arises when i have to add delivery schedule for more than one item because when i tries to add delivery schedule for second item the details for the first added delivery schedule gets overwritten by the second delivery schedule. :(

That means I am not able to maintain the previous values of the session variable. Also I don't want to add the previous details into the SQL Server Database; I just want to maintain the data into the session only.

I am not able to find any way to how to solve this problem. If anyone is having any solution to it, i would be glad and appreciate the same person.

Thanks

Varun Sareen
Posted
Updated 8-May-11 21:59pm
v2

when i tries to add delivery schedule for second item the details for the first added delivery schedule gets overwritten by the second delivery schedule

Why overwriting? It's in your hand. Check if the Session is empty or not before over-writing. Further, Session can store any object type in it. Create a list or an array (depending on your scenario/requirement for data storage) and then store this list/array in the session. Thus multiple rows data can be stored in a single session and you can access them later to commit changes.
 
Share this answer
 
Comments
Varun Sareen 10-May-11 3:45am    
Thanks Mewara,

I solved it using XML file. :-)
I solved it myself using XML file functionality.
 
Share this answer
 
<pre>protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dtToGrid = new DataTable();
dtToGrid.Columns.Add("UserName", typeof(string));
dtToGrid.Columns.Add("Password", typeof(string));
Session["dtToGrid"] = dtToGrid;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// first to show in gridview only.
DataTable dtToGrid = (DataTable)Session["dtToGrid"];
DataRow drToGrid = dtToGrid.NewRow();
drToGrid["UserName"] = TextBox1.Text.Trim();
drToGrid["Password"] = TextBox2.Text.Trim();
dtToGrid.Rows.Add(drToGrid);
GridView1.DataSource = dtToGrid;
GridView1.DataBind();
TextBox1.Text = "";
}
protected void Button2_Click(object sender, EventArgs e)
{
//save in Sql Server Table
cn.Open();

//using below statement we can maintain state of datatable.i had got it.see once my code and u can find solution.
DataTable dt = (DataTable)Session["dtToGrid"];
using (SqlBulkCopy copy = new SqlBulkCopy(cn))
{
copy.DestinationTableName = "userdetails";
copy.WriteToServer(dt);
}

}</pre>
 
Share this answer
 
v2
Comments
Varun Sareen 9-May-11 4:02am    
Dear Lakshmi,

I appreciate your quick response but your solution looks a little confusing to me :-). Do you have any other simple solution to it. Passing a data-table from one page to another Page will do but how that i don't know.

Thanks

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