Click here to Skip to main content
15,880,891 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi guys,
So just wondering. I got a few pages where by each pages have a gridview(lets called this sourcegridview). So in these sourcegridview, I have put a column of checkboxes for each row. Every time I checked a checkbox, that particular row will be added to another gridview(lets called this gridview CompiledGridview). I did this by transferring the checked row into a datatable and bind it with the CompiledGridview. So my question is, how to maintain the data added to the CompiledGridview? Because I have to navigate to each of my webpages and select the record that I want to be added to the CompiledGridview and everytime I navigate to a different web page, the data in the CompiledGridview is gone. One of the way is Session but how to bind it? because I have multiple sourcegridview.

Any help is greatly appreciated! :)
Posted

1 solution

As you said, if you want to store it at session, you can create a class like this:
C#
public class Class1
{
    public static DataTable TableSession
    {
        get
        {
            if (HttpContext.Current.Session["dt"] == null)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("checked");
                dt.Columns.Add("name");
                HttpContext.Current.Session["dt"] = dt;
            }
            return (DataTable)HttpContext.Current.Session["dt"];
        }
        set
        {
            HttpContext.Current.Session["dt"] = value;
        }
    }
}

and access it anywhere like this:
C#
protected void Page_Load(object sender, EventArgs e)
{
    sourcegridview.DataSource = Class1.TableSession;
    sourcegridview.DataBind();

    Class1.TableSession.Rows.Add("1", "new data");

    CompiledGridview.DataSource = Class1.TableSession;
    CompiledGridview.DataBind();
}
 
Share this answer
 
Comments
nizam15 1-Jan-14 22:08pm    
Hi adriancs.
Sorry for the late reply. Got a problem with my laptop. Thanks for the suggestion! Will try it out. By they way is it possible for me to insert all the data I have stored in a datatable into a SQL table?
adriancs 1-Jan-14 22:21pm    
database = SQL database = SQL table
are you referring to System.Data.DataTable?
nizam15 2-Jan-14 2:37am    
yup~i am referring to System.Data.Datatable. Now I stored my data in a Data.Datatable. So I was wondering if there is anyway for me to transfer that data into a SQL database table.
adriancs 2-Jan-14 2:43am    
by executing INSERT, UPDATE and DELETE of SQL statements.
nizam15 2-Jan-14 2:56am    
Is it the same as inserting normal data? because the data is already in the datatable right so just want to copy those data into a SQL table.

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