Click here to Skip to main content
13,000,469 members (51,541 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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

1 solution

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

Solution 1

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

and store this table in the viewstate
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
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.170624.1 | Last Updated 11 Mar 2012
Copyright © CodeProject, 1999-2017
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