Click here to Skip to main content
12,449,098 members (51,842 online)
Rate this:
 
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
Updated 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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 11 Mar 2012
Copyright © CodeProject, 1999-2016
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