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
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Aamir KhanPosted Jun 22, 2012, 1:29 AM
Posted Jun 21, 2012, 12:08 PM
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 KhanPosted Jun 21, 2012, 4:30 AM
Posted Jun 21, 2012, 4:22 AM
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();
}