Dear Friends,
I have a gridview with 2 columns, ID & quantity.
and a Button outside Gridview named 'Save'.
how can i save the values from Gridview(ID & quantity), on button Click event of Save Button
Pls reply.
Regards,
aamir
How to Save Datagrid values on Button Click Event
4 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted Jun 21, 2012, 12:22 AM EDT
You can iterate all the items in the grid and send it to database.
The database insertion operation may be for each records or you can bulk insert using sqldataadapter also.
foreach (DataGridItem dgi in gv.Items)
{
string id = dgi.Cells[0].Text;
string name = dgi.Cells[1].Text;
SqlConnection conn = new SqlConnection(Common.GetConnectionString("SqlConnectionString"));
conn.Open();
SqlCommand comm = new SqlCommand("insert into table1 values (" + id + ",'" + qty+ "')", conn);
comm.ExecuteNonQuery();
conn.Close();
}
Aamir Khan186 pointsPosted Jun 21, 2012, 12:30 AM EDT
Former memberPosted Jun 21, 2012, 8:08 AM EDT
foreach (DataGridItem dgi in gv.Items)
{
string id = dgi.Cells[0].Text;
string name = dgi.Cells[1].Text;
SqlConnection conn = new SqlConnection(Common.GetConnectionString("SqlConnectionString"));
conn.Open();
SqlCommand comm = new SqlCommand("insert into table1 values (" + id + ",'" + qty+ "')", conn);
comm.ExecuteNonQuery();
conn.Close();
}
Aamir Khan186 pointsPosted Jun 21, 2012, 9:29 PM EDT