Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
How to add text box values to grid view by clicking on a add button and after that if we click a save button then the values from grid view must store in sql server database
 
step1:text box values must go into grid view after clicking a add button
step2: there is another button save if we click on this the values from grid view should store in database
Posted 11-Mar-12 0:05am
Edited 11-Mar-12 0:24am
v4

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
To Do this
1st:create datatable
2nd:add row to datatable
3rd: bind to gridview and store that talbe in viewsate and repeat from step 1(by converting viewstate value back to datatable)
 

1st step:
create data table following way...
DataTable table = new DataTable();
add columns how many you want and give the names which you are binding to the gridvieww
 
table.Columns.Add("Ename", typeof(int));
table.Columns.Add("Sname", typeof(string));
table.Columns.Add("Department", typeof(string));
table.Columns.Add("DateOfJoin", typeof(string));
 
2nd step:
onclick of the button take the values entered in the textbox and add to the columns of the datatable.
 
table.Rows.Add(txtname.text.trim(),txtsname.text.trim() ,txtDptName.text.trim(),txtdate.text.trim() );
 
at the end bind this table to the gridview
grdEmpdetails.datasource=table;
 
and store this table in the viewstate
viewstate["dtTable"]=talbe;
again
3rd:onlcick of the button you have to convert viewstate value back to datatable and add the new row and again bind that to gridview..
 
Its Done
  Permalink  
Comments
fresherincode at 22-Mar-12 8:18am
   
Thank u very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 225
1 OriginalGriff 145
2 manoj kumar choubey 115
3 _Amy 115
4 Sergey Alexandrovich Kryukov 105
0 OriginalGriff 7,320
1 Sergey Alexandrovich Kryukov 6,043
2 Maciej Los 3,749
3 Peter Leow 3,408
4 DamithSL 2,555


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 11 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100