单击确定按钮 gridView选中行插入表.net
时间: 2023-08-15 13:33:47 浏览: 96
您可以按照以下步骤来实现在单击确定按钮时,将 gridView 中选中的行插入表中:
1. 在单击确定按钮的事件处理程序中,使用以下代码获取选中的行:
```
GridViewRow selectedRow = gridView.SelectedRow;
```
2. 然后,使用以下代码将选中的行的数据插入表中:
```
string connectionString = "your_connection_string_here";
string insertQuery = "INSERT INTO your_table_name_here (column1, column2, column3) VALUES (@value1, @value2, @value3)";
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand(insertQuery, connection);
command.Parameters.AddWithValue("@value1", selectedRow.Cells[0].Text);
command.Parameters.AddWithValue("@value2", selectedRow.Cells[1].Text);
command.Parameters.AddWithValue("@value3", selectedRow.Cells[2].Text);
connection.Open();
command.ExecuteNonQuery();
}
```
请确保将 "your_connection_string_here" 和 "your_table_name_here" 替换为您自己的连接字符串和表名。还要根据您的表格结构更改 insertQuery 中的列名和参数名称。
3. 最后,使用以下代码重新绑定 gridView,以显示更新后的数据:
```
gridView.DataBind();
```
这样,当用户单击确定按钮时,选中的行将被插入表中,并且 gridView 将显示更新后的数据。
阅读全文
相关推荐













