As you understand from the title. I got gridview on my asp.net project from my database. And i got 4 textboxes under it. And 1 button.
Here is the event;
The user will input the values on textboxes, and when the user clicks the button, i must get the value into my database and i need to see it on my gridview as you know.
Like this ;
NAME MON TUE WED THU FRI SAT SUN TOTAL DAYS LATE CARD CORR
Now, how can i handle that in button click on c# side ?
Hi,
1) Double click the button in the design mode. Then an event of Click will be automatically generated.
2) And then write down codes by referring "foreach"/"for" to loop each Row for the GridView and fetch what you've inputted inside as the value and do calculating.
using (SqlCommand cmd = new SqlCommand("insert into xxx values(@p1,@p2,……,@pn)",new SqlConnection("……"))
{
………………
//Do to assign values to SqlParameter one by one.
}
Kuthay Gumus
Member
13 Points
116 Posts
Inserting Value Into Gridview and Using For Another Calculation
Dec 17, 2012 10:57 AM|LINK
Hi,
As you understand from the title. I got gridview on my asp.net project from my database. And i got 4 textboxes under it. And 1 button.
Here is the event;
The user will input the values on textboxes, and when the user clicks the button, i must get the value into my database and i need to see it on my gridview as you know.
Like this ;
NAME MON TUE WED THU FRI SAT SUN TOTAL DAYS LATE CARD CORR
------------------------------------------------------------------------------------------------------------------
Mike 10 30 40 50 20 30 40 220 null null null null
John 40 10 40 40 50 60 10 250 null null null null
DAYS : ____________
LATE : _____________
CARD: ____________
CORR:_____________
|"evaluate button"|
As you see from here, i need to take inputs and must use insert into or something..
Firstly i need this. After i will do more complicated calculations.
Now, how can i handle that in button click on c# side ?
Thanks.
deepthoughts
Contributor
7288 Points
1051 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 17, 2012 11:26 AM|LINK
After doing insertion in the database, bind the gridview again. The new changes will be reflected.
GridView1.DataBind();
Thanks.
Kuthay Gumus
Member
13 Points
116 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 17, 2012 11:28 AM|LINK
I know that mate but the problem is what will be the button click codes for inserting that values ?
sarathi125
Star
13599 Points
2691 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 17, 2012 11:53 AM|LINK
Hi,
Check this ,
http://stackoverflow.com/questions/10831554/how-to-update-a-gridview-after-saving-data
Do you want to save the data to Db and then update (Refresh) it in gridview or Into gridview first and then to DB for all teh updated rows.
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Kuthay Gumus
Member
13 Points
116 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 17, 2012 12:14 PM|LINK
I wrote all of thing what i want in first entry mate.
Of course i need to save the data which user entered.
It must be simple, isnt it ?
The user will enter the data into the text box and i will refresh and see that data in my gridview and database.
What is the button click event codes on .cs side ?
sarathi125
Star
13599 Points
2691 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 17, 2012 12:15 PM|LINK
Hi,
Ok, then check the link in my previous post.
Remember to click Mark as Answer on the post that helps to others.
My Blog :MyAspSnippets
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 18, 2012 12:51 AM|LINK
Hi,
1) Double click the button in the design mode. Then an event of Click will be automatically generated.
2) And then write down codes by referring "foreach"/"for" to loop each Row for the GridView and fetch what you've inputted inside as the value and do calculating.
Kuthay Gumus
Member
13 Points
116 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 19, 2012 09:02 PM|LINK
what should be the codes for for it ?
how can i reach the rows and insert the values into the database ?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Inserting Value Into Gridview and Using For Another Calculation
Dec 19, 2012 11:53 PM|LINK
Hi again,
Codes may be this:
using (SqlCommand cmd = new SqlCommand("insert into xxx values(@p1,@p2,……,@pn)",new SqlConnection("……")) { ……………… //Do to assign values to SqlParameter one by one. }