这是我代码,我这样做,还是只能删除一行,大家帮我看下哪里需要修改才能实现把选中的行都删除,实现批量删除if(dgvsearch.SelectedRows.Count==0)
{
MessageBox.Show("没有选中删除行!");
}
else
{
DialogResult choice = MessageBox.Show("确认删除吗?", "确认信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
for (int i = 0; i < dgvsearch.SelectedRows.Count; i++)
{
if (choice == DialogResult.Yes)
{
dbhelp.numid = Convert.ToInt32(dgvsearch.SelectedRows[0].Cells["id"].Value);//把序列号ID存入dbhelp的numid里
string sql = string.Format("delete from govinformation where id='{0}'", dbhelp.numid);
try
{
dbhelp.conn.Open();
SqlCommand comm = new SqlCommand(sql, dbhelp.conn);
int result = comm.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dbhelp.conn.Close();
}
}
}
{
MessageBox.Show("没有选中删除行!");
}
else
{
DialogResult choice = MessageBox.Show("确认删除吗?", "确认信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
for (int i = 0; i < dgvsearch.SelectedRows.Count; i++)
{
if (choice == DialogResult.Yes)
{
dbhelp.numid = Convert.ToInt32(dgvsearch.SelectedRows[0].Cells["id"].Value);//把序列号ID存入dbhelp的numid里
string sql = string.Format("delete from govinformation where id='{0}'", dbhelp.numid);
try
{
dbhelp.conn.Open();
SqlCommand comm = new SqlCommand(sql, dbhelp.conn);
int result = comm.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
dbhelp.conn.Close();
}
}
}
建议是不错,可是你回答的有些问题“dgvsearch.SelectedRows.Count是当前选中的行,肯定是1行”
肯定是 一行或者多行
dbhelp.numid = Convert.ToInt32(dgvsearch.SelectedRows[0].Cells["id"].Value);//把序列号ID存入dbhelp的改为dbhelp.numid = Convert.ToInt32(dgvsearch.SelectedRows[i].Cells["id"].Value);//把序列号ID存入dbhelp的
请问怎样用jquery实现批量删除行??