Click here to Skip to main content
15,897,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have published the site on IIS.
As the users login into the application and start entering the data the data should be maintained user wise and not be visible to other users.
As they click the save button the data of the different users gets combined into the grid.

For example: User1 added a row to the grid.
As the other users add their rows to the grid User1 has Four rows in his grid. The sessionID is different for all the users.

I am not able to understand why the data is merging.

How can I manage data for different users?

Please help, I am new to ASP.Net.
//Class
public class DataTable
{
    public static DataTable dt;

    public DataTable()
    {
      dt = new DataTable();
      dt.Columns.Add("Col1");
      dtColumns.Add("Col2");

    }
}

//Web-Page

protected void btSave_Click()
{
   //Code to add data to datatable. 
   DataTable.dt.Rows.Add(DataRows);

   Session["DataTable"] = DataTable.dt; //  saving dataTable to session.

   Grid.DataSource = (DataTable)Session["DataTable"];
}
Posted
Updated 6-Jan-11 21:49pm
v5
Comments
JF2015 7-Jan-11 2:46am    
Added code formatting.
Dalek Dave 7-Jan-11 3:49am    
Edited for Readability.

Are you creating a new instance of DataTable in every session?

If true, why you're using the static member in DataTable? I think that you're using the same datatable for every user.

Try to create a new instance of DataTable and disable the static member, It can solve the problem.

For this example, I changed the name of DataTable class, because it's the same that the original DataTable.

Ex:
//Classpublic
class MyDataTable
{
    public DataTable dt;
    public DataTable()
    {
        dt = new DataTable();
        dt.Columns.Add("Col1");
        dtColumns.Add("Col2");
    }
}

//Web-Page
protected void btSave_Click()
{   //Code to add data to datatable.
    MyDataTable dt = new MyDataTable();
    MyDataTable.dt.Rows.Add(DataRows);
    Session["DataTable"] = MyDataTable.dt;
    //  saving dataTable to session.
    Grid.DataSource = (DataTable)Session["DataTable"];
}
 
Share this answer
 
v2
Comments
Ashwani Dhiman 7-Jan-11 3:27am    
Thanks a lot.......
Dalek Dave 7-Jan-11 3:49am    
Good Answer.
Sandesh M Patil 7-Jan-11 3:50am    
nice answer
Kasson 7-Jan-11 3:57am    
Good Stuff. My 5 too.
thatraja 7-Jan-11 13:35pm    
Good answer
yes, you remove the
public static  DataTable  dt

to

public DataTable dt
 
Share this answer
 

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