Answered by:
GridView Multiple Row Insert With A Single Click

Question
-
Hello!! I am trying To add multiple rows in a Table as follows. But in this case the following data is retrieved using Linq and The sum of The products means Quantity & Total Price are shown in GridView from a Table and I need To add this data from GridView. Now How can I insert this data into another Table from GridView with a single click and is it possible To do??
ProductID
ProductName
Quantity
Total Price
1
T-Shirt
20
20000
2
Jeans
40
40000
Submit
- Edited by TechView-2017 Wednesday, July 23, 2014 5:41 PM
Wednesday, July 23, 2014 9:38 AM
Answers
-
Hi,
According to your description, I do not quite understand your problem. Do you want to add mutiple rows from GridView to a Table? If so, make sure that your
DataTable
contains all the column which you want to copy. Be careful withColumnName
ofDataTable
as well asDataGridView
. You can try this :
Best Wishes!public DataTable GetDataTable() { DataTable dtLocalC = new DataTable(); dtLocalC.Columns.Add("ProductID"); dtLocalC.Columns.Add("ProductName");
dtLocalC.Columns.Add("Quantity"); dtLocalC.Columns.Add("Total Price"); DataRow drLocal = null; foreach (DataGridViewRow dr in dgvSpplrfrm.Rows) { drLocal = dtLocalC.NewRow(); drLocal["splr_Slno"] = dr.Cells["ProductID"].Value; drLocal["splr_Cntctnm"] = dr.Cells["ProductName"].Value; drLocal["splr_Cntctdesig"] = dr.Cells["Quantity"].Value; drLocal["splr_Cntctmoblno"] = dr.Cells["Total Price"].Value; dtLocalC.Rows.Add(drLocal); } return dtLocalC; }
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.
- Edited by Anne Jing Thursday, July 24, 2014 6:28 AM edit
- Proposed as answer by Ioana Vasilescu Friday, August 1, 2014 8:07 PM
- Marked as answer by Anne Jing Sunday, August 3, 2014 11:44 AM
Thursday, July 24, 2014 6:26 AM
All replies
-
Hi,
According to your description, I do not quite understand your problem. Do you want to add mutiple rows from GridView to a Table? If so, make sure that your
DataTable
contains all the column which you want to copy. Be careful withColumnName
ofDataTable
as well asDataGridView
. You can try this :
Best Wishes!public DataTable GetDataTable() { DataTable dtLocalC = new DataTable(); dtLocalC.Columns.Add("ProductID"); dtLocalC.Columns.Add("ProductName");
dtLocalC.Columns.Add("Quantity"); dtLocalC.Columns.Add("Total Price"); DataRow drLocal = null; foreach (DataGridViewRow dr in dgvSpplrfrm.Rows) { drLocal = dtLocalC.NewRow(); drLocal["splr_Slno"] = dr.Cells["ProductID"].Value; drLocal["splr_Cntctnm"] = dr.Cells["ProductName"].Value; drLocal["splr_Cntctdesig"] = dr.Cells["Quantity"].Value; drLocal["splr_Cntctmoblno"] = dr.Cells["Total Price"].Value; dtLocalC.Rows.Add(drLocal); } return dtLocalC; }
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.
- Edited by Anne Jing Thursday, July 24, 2014 6:28 AM edit
- Proposed as answer by Ioana Vasilescu Friday, August 1, 2014 8:07 PM
- Marked as answer by Anne Jing Sunday, August 3, 2014 11:44 AM
Thursday, July 24, 2014 6:26 AM -
Thanks for the reply. I have a question. Yes I want To add the data from GridView. So don't we need any submission button for this??Thursday, July 24, 2014 10:11 AM
-
Hi,
You can create a button in your form. And when you click the button, try to call the GetDataTable()
method in the Button_Click event.Best Wishes!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.
- Proposed as answer by Ioana Vasilescu Friday, August 1, 2014 8:07 PM
Monday, July 28, 2014 7:25 AM