Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have one grid view , two text box ,two button and one drop down box , while am entering data to text box and drop down boxes (inside the grid view),that data want to store temporally in grid view after that data want to store in database.My code is attached here

C#
protected void Buttonadd_Click(object sender, EventArgs e)
    {
 if (Session["Data"] == null)
        {


            C = 1;


            dt = new DataTable();
            DataRow dr = dt.NewRow();
            dt.Columns.Add(new System.Data.DataColumn("EMPNAME", typeof(String)));
            dt.Columns.Add(new System.Data.DataColumn("EMPID", typeof(String)));
            dt.Columns.Add(new System.Data.DataColumn("DEPARTMENT", typeof(String)));
            dr[0] = Txtaddname.Text;
            dr[1] = Txtaddempid.Text;
            dr[2] = Drpadddept.SelectedItem.Text;
            dt.Rows.Add(dr);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            Session["Data"] = dt;


        }
        else
        {
            C = C + 1;


            dt = new DataTable();
            dt = (DataTable)Session["Data"];
            DataRow dr = dt.NewRow();
            dr[0] = Txtaddname.Text;
            dr[1] = Txtaddempid.Text;
            dr[2] = Drpadddept.SelectedItem.Text;
            dt.Rows.Add(dr);
            GridView1.DataSource = dt;
            GridView1.DataBind();
            Session.Remove("Data");
            Session["Data"] = dt;
Posted
Updated 27-Apr-15 20:11pm
v2
Comments
Thanks7872 28-Apr-15 5:22am    
Where is the question?
Unni R 28-Apr-15 6:27am    
how can i pass this data to database?
Harikrishna G 28-Apr-15 5:40am    
where u r facing the issue ?
Unni R 28-Apr-15 6:27am    
how can i pass this data to database?
Thanks7872 28-Apr-15 6:32am    
I don't see any code that interacts with DB. Search google and implement it. Come back when you face any problem with that code.

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