谢谢各位大虾帮忙啊~!!!!!!!!!
11 个解决方案
#1
dataGridView 绑定数据集,删除时操作数据库,删除相应的数据,然后再重新绑定
#2
this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[0]);
删除第一行,这样试试
删除第一行,这样试试
#3
那我要选中那行就删那行那 并且数据库也要删除
#4
可以直接刪除DataGridView對應的后台數據源DataTable中的數據行,如
datatable.Rows.Remove(this.dataGridView1.selectedRow.RowIndex)
datatable.Rows.Remove(this.dataGridView1.selectedRow.RowIndex)
#5
你的那些都点不出来啊
#6
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
dataGridView1.Rows.RemoveAt (dataGridView1 .CurrentRow .Index )
如果你删除的那行有关于那条记录的主键,
你就可以再点击删除按钮的同时直接使用delete语句删除数据库中的数据
where 主键 = dataGridView1.SelectedRows[0].cell["主键"]);
#7
楼上的大哥们说话 帮帮忙啊
#8
没有主键啊 那我改怎么办 有没有例子让小弟看看
#9
private void btnDelete_Click(object sender, EventArgs e)
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
#10
datagridview多行删除
在sql2000里。可以选择多行进行删除,并且可以从底部向上选择。用vs做winForm用到datagridview也可达到同样的效果。下面是代
码
private void button1_Click(object sender, EventArgs e)
{
int j = dataGridView1.SelectedRows.Count;
if (MessageBox.Show("您确认要删除这" + Convert.ToString(j) + "项吗?", "系统提示",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)//给出提示
{
}
else
{
for (int i = 0; dataGridView1.SelectedRows.Count > i; )
{
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
}
wy_qqxsTableAdapter.Update(dataSet1.wy_qqxs);
}
}
DataGridView删除行,和删除表
int x = dataGridView1.SelectedRows.Count;//获得选中的行
while (x > 0)//可一次删除多行
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[x-1].Index);
x--;
}
如果想删除对应数据库内的行 数据库的表 必须要有主键
===========================================================================================
对选中的datagridview中的多行删除
datagridview绑定通过bindingsource, 代码如下:
//绑定
this.bindingsource1.DataSource = ds.Tables[0];
this.dgv.DataSource = bindingsource1;
//删除
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
for (int i = dgv.SelectedRows.Count - 1; i >= 0; i--)
{
dgv.Rows.Remove(dgv.SelectedRows[i]);
}
}
===========================================================================================
private void btnDelete_Click(object sender, EventArgs e)
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
===========================================================================================
最近用到数据库,发现C#2005默认没有DataGrid,如果需要可以自己添加。并且提供了一个更新的DataGridView。但两者操作上还是
有一些区别的。找了半天才找到一些处理数据的方法。具体做法就不说了,仅列出WinForm下DataGridView填充、更新、删除(多行
)Sql Express 2005数据库代码。
private void button1_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Fill(this.hostScanDataSet.host);
}
private void button2_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Update(this.hostScanDataSet.host);
MessageBox.Show("记录已保存!");
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult dlResult = MessageBox.Show(this, "要删除这些记录吗?", "请确认",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if (dlResult == DialogResult.Yes)
{
int j = dataGridView1.SelectedRows.Count;
int[] l = new int[j];
int i;
for (i = 0; i < j; i++)
{
l[i] = dataGridView1.SelectedRows[i].Index;
}
int k = 0;
while (k < j)
{
this.hostScanDataSet.host.Rows[l[k]].Delete();
k++;
}
this.hostTableAdapter.Update(this.hostScanDataSet.host);
}
}
===========================================================================================
protected void Button1_Click(object sender, EventArgs e)
{
string id = "";
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
if (ch.Checked)
{
id += GridView1.DataKeys[gvr.DataItemIndex].Value.ToString() + ",";
}
}
if (id == "")
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('请选择要删除的东
东');</script>");
}
else
{
id = id.Substring(0, id.Length - 1);
//删除操作
Bind();
}
}
===========================================================================================
GridView1.DataKeyNames = new string[] { "主键" };
写在LOAD中.
protected void btnDel_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
if (((CheckBox)this.GridView1.Rows[i].Cells[0].FindControl("chkSelect")).Checked)
{
OA_Business.Employer.Employer epy = new OA_Business.Employer.Employer();
epy.E_ID = int.Parse(GridView1.DataKeys[i].Value.ToString());
epy.E_Del();
}
}
BindEmployer();
}
这是一个用CheckBox选中删除的用于多选的.
在sql2000里。可以选择多行进行删除,并且可以从底部向上选择。用vs做winForm用到datagridview也可达到同样的效果。下面是代
码
private void button1_Click(object sender, EventArgs e)
{
int j = dataGridView1.SelectedRows.Count;
if (MessageBox.Show("您确认要删除这" + Convert.ToString(j) + "项吗?", "系统提示",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)//给出提示
{
}
else
{
for (int i = 0; dataGridView1.SelectedRows.Count > i; )
{
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
}
wy_qqxsTableAdapter.Update(dataSet1.wy_qqxs);
}
}
DataGridView删除行,和删除表
int x = dataGridView1.SelectedRows.Count;//获得选中的行
while (x > 0)//可一次删除多行
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[x-1].Index);
x--;
}
如果想删除对应数据库内的行 数据库的表 必须要有主键
===========================================================================================
对选中的datagridview中的多行删除
datagridview绑定通过bindingsource, 代码如下:
//绑定
this.bindingsource1.DataSource = ds.Tables[0];
this.dgv.DataSource = bindingsource1;
//删除
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
for (int i = dgv.SelectedRows.Count - 1; i >= 0; i--)
{
dgv.Rows.Remove(dgv.SelectedRows[i]);
}
}
===========================================================================================
private void btnDelete_Click(object sender, EventArgs e)
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
===========================================================================================
最近用到数据库,发现C#2005默认没有DataGrid,如果需要可以自己添加。并且提供了一个更新的DataGridView。但两者操作上还是
有一些区别的。找了半天才找到一些处理数据的方法。具体做法就不说了,仅列出WinForm下DataGridView填充、更新、删除(多行
)Sql Express 2005数据库代码。
private void button1_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Fill(this.hostScanDataSet.host);
}
private void button2_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Update(this.hostScanDataSet.host);
MessageBox.Show("记录已保存!");
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult dlResult = MessageBox.Show(this, "要删除这些记录吗?", "请确认",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if (dlResult == DialogResult.Yes)
{
int j = dataGridView1.SelectedRows.Count;
int[] l = new int[j];
int i;
for (i = 0; i < j; i++)
{
l[i] = dataGridView1.SelectedRows[i].Index;
}
int k = 0;
while (k < j)
{
this.hostScanDataSet.host.Rows[l[k]].Delete();
k++;
}
this.hostTableAdapter.Update(this.hostScanDataSet.host);
}
}
===========================================================================================
protected void Button1_Click(object sender, EventArgs e)
{
string id = "";
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
if (ch.Checked)
{
id += GridView1.DataKeys[gvr.DataItemIndex].Value.ToString() + ",";
}
}
if (id == "")
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('请选择要删除的东
东');</script>");
}
else
{
id = id.Substring(0, id.Length - 1);
//删除操作
Bind();
}
}
===========================================================================================
GridView1.DataKeyNames = new string[] { "主键" };
写在LOAD中.
protected void btnDel_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
if (((CheckBox)this.GridView1.Rows[i].Cells[0].FindControl("chkSelect")).Checked)
{
OA_Business.Employer.Employer epy = new OA_Business.Employer.Employer();
epy.E_ID = int.Parse(GridView1.DataKeys[i].Value.ToString());
epy.E_Del();
}
}
BindEmployer();
}
这是一个用CheckBox选中删除的用于多选的.
#11
学习了。。。。。。。。。。。。
#1
dataGridView 绑定数据集,删除时操作数据库,删除相应的数据,然后再重新绑定
#2
this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[0]);
删除第一行,这样试试
删除第一行,这样试试
#3
那我要选中那行就删那行那 并且数据库也要删除
#4
可以直接刪除DataGridView對應的后台數據源DataTable中的數據行,如
datatable.Rows.Remove(this.dataGridView1.selectedRow.RowIndex)
datatable.Rows.Remove(this.dataGridView1.selectedRow.RowIndex)
#5
你的那些都点不出来啊
#6
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
dataGridView1.Rows.RemoveAt (dataGridView1 .CurrentRow .Index )
如果你删除的那行有关于那条记录的主键,
你就可以再点击删除按钮的同时直接使用delete语句删除数据库中的数据
where 主键 = dataGridView1.SelectedRows[0].cell["主键"]);
#7
楼上的大哥们说话 帮帮忙啊
#8
没有主键啊 那我改怎么办 有没有例子让小弟看看
#9
private void btnDelete_Click(object sender, EventArgs e)
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
#10
datagridview多行删除
在sql2000里。可以选择多行进行删除,并且可以从底部向上选择。用vs做winForm用到datagridview也可达到同样的效果。下面是代
码
private void button1_Click(object sender, EventArgs e)
{
int j = dataGridView1.SelectedRows.Count;
if (MessageBox.Show("您确认要删除这" + Convert.ToString(j) + "项吗?", "系统提示",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)//给出提示
{
}
else
{
for (int i = 0; dataGridView1.SelectedRows.Count > i; )
{
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
}
wy_qqxsTableAdapter.Update(dataSet1.wy_qqxs);
}
}
DataGridView删除行,和删除表
int x = dataGridView1.SelectedRows.Count;//获得选中的行
while (x > 0)//可一次删除多行
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[x-1].Index);
x--;
}
如果想删除对应数据库内的行 数据库的表 必须要有主键
===========================================================================================
对选中的datagridview中的多行删除
datagridview绑定通过bindingsource, 代码如下:
//绑定
this.bindingsource1.DataSource = ds.Tables[0];
this.dgv.DataSource = bindingsource1;
//删除
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
for (int i = dgv.SelectedRows.Count - 1; i >= 0; i--)
{
dgv.Rows.Remove(dgv.SelectedRows[i]);
}
}
===========================================================================================
private void btnDelete_Click(object sender, EventArgs e)
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
===========================================================================================
最近用到数据库,发现C#2005默认没有DataGrid,如果需要可以自己添加。并且提供了一个更新的DataGridView。但两者操作上还是
有一些区别的。找了半天才找到一些处理数据的方法。具体做法就不说了,仅列出WinForm下DataGridView填充、更新、删除(多行
)Sql Express 2005数据库代码。
private void button1_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Fill(this.hostScanDataSet.host);
}
private void button2_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Update(this.hostScanDataSet.host);
MessageBox.Show("记录已保存!");
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult dlResult = MessageBox.Show(this, "要删除这些记录吗?", "请确认",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if (dlResult == DialogResult.Yes)
{
int j = dataGridView1.SelectedRows.Count;
int[] l = new int[j];
int i;
for (i = 0; i < j; i++)
{
l[i] = dataGridView1.SelectedRows[i].Index;
}
int k = 0;
while (k < j)
{
this.hostScanDataSet.host.Rows[l[k]].Delete();
k++;
}
this.hostTableAdapter.Update(this.hostScanDataSet.host);
}
}
===========================================================================================
protected void Button1_Click(object sender, EventArgs e)
{
string id = "";
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
if (ch.Checked)
{
id += GridView1.DataKeys[gvr.DataItemIndex].Value.ToString() + ",";
}
}
if (id == "")
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('请选择要删除的东
东');</script>");
}
else
{
id = id.Substring(0, id.Length - 1);
//删除操作
Bind();
}
}
===========================================================================================
GridView1.DataKeyNames = new string[] { "主键" };
写在LOAD中.
protected void btnDel_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
if (((CheckBox)this.GridView1.Rows[i].Cells[0].FindControl("chkSelect")).Checked)
{
OA_Business.Employer.Employer epy = new OA_Business.Employer.Employer();
epy.E_ID = int.Parse(GridView1.DataKeys[i].Value.ToString());
epy.E_Del();
}
}
BindEmployer();
}
这是一个用CheckBox选中删除的用于多选的.
在sql2000里。可以选择多行进行删除,并且可以从底部向上选择。用vs做winForm用到datagridview也可达到同样的效果。下面是代
码
private void button1_Click(object sender, EventArgs e)
{
int j = dataGridView1.SelectedRows.Count;
if (MessageBox.Show("您确认要删除这" + Convert.ToString(j) + "项吗?", "系统提示",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)//给出提示
{
}
else
{
for (int i = 0; dataGridView1.SelectedRows.Count > i; )
{
dataGridView1.Rows.Remove(dataGridView1.SelectedRows[0]);
}
wy_qqxsTableAdapter.Update(dataSet1.wy_qqxs);
}
}
DataGridView删除行,和删除表
int x = dataGridView1.SelectedRows.Count;//获得选中的行
while (x > 0)//可一次删除多行
{
dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[x-1].Index);
x--;
}
如果想删除对应数据库内的行 数据库的表 必须要有主键
===========================================================================================
对选中的datagridview中的多行删除
datagridview绑定通过bindingsource, 代码如下:
//绑定
this.bindingsource1.DataSource = ds.Tables[0];
this.dgv.DataSource = bindingsource1;
//删除
private void bindingNavigatorDeleteItem_Click(object sender, EventArgs e)
{
for (int i = dgv.SelectedRows.Count - 1; i >= 0; i--)
{
dgv.Rows.Remove(dgv.SelectedRows[i]);
}
}
===========================================================================================
private void btnDelete_Click(object sender, EventArgs e)
{
//判断用户是否选择一行数据,true为没选择,false为选择
if (this.dgv.Rows[this.dgv.CurrentRow.Index].Cells[0].Value.ToString()=="")
{
MessageBox.Show("请选择一项进行删除");
}
else
{
//判断用户是否点击确定按钮,true为点击,false为没有点击
if (MessageBox.Show("确认删除?","提示", MessageBoxButtons.YesNo)==DialogResult.Yes)
{
//定义数组,用循环赋值
String[] array = new String[];
for (int i = 0; i < this.dgv.SelectedRows.Count; i++)
{
String str = this.dgv.Rows[this.dgv.SelectedRows[i].Index].Cells[0].Value.ToString();
String strDelete = "Delete from students where StudentNumber='" + str + "'";
array[i] = strDelete;
}
//遍历数组
foreach (String str in array)
{
this.Update(str);
}
//这里写刷新的方法
}
}
}
===========================================================================================
最近用到数据库,发现C#2005默认没有DataGrid,如果需要可以自己添加。并且提供了一个更新的DataGridView。但两者操作上还是
有一些区别的。找了半天才找到一些处理数据的方法。具体做法就不说了,仅列出WinForm下DataGridView填充、更新、删除(多行
)Sql Express 2005数据库代码。
private void button1_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Fill(this.hostScanDataSet.host);
}
private void button2_Click(object sender, EventArgs e)
{
this.hostTableAdapter.Update(this.hostScanDataSet.host);
MessageBox.Show("记录已保存!");
}
private void button3_Click(object sender, EventArgs e)
{
DialogResult dlResult = MessageBox.Show(this, "要删除这些记录吗?", "请确认",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.RightAlign);
if (dlResult == DialogResult.Yes)
{
int j = dataGridView1.SelectedRows.Count;
int[] l = new int[j];
int i;
for (i = 0; i < j; i++)
{
l[i] = dataGridView1.SelectedRows[i].Index;
}
int k = 0;
while (k < j)
{
this.hostScanDataSet.host.Rows[l[k]].Delete();
k++;
}
this.hostTableAdapter.Update(this.hostScanDataSet.host);
}
}
===========================================================================================
protected void Button1_Click(object sender, EventArgs e)
{
string id = "";
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox ch = (CheckBox)gvr.FindControl("ItemCheckBox");
if (ch.Checked)
{
id += GridView1.DataKeys[gvr.DataItemIndex].Value.ToString() + ",";
}
}
if (id == "")
{
Page.ClientScript.RegisterStartupScript(Page.GetType(), "", "<script>alert('请选择要删除的东
东');</script>");
}
else
{
id = id.Substring(0, id.Length - 1);
//删除操作
Bind();
}
}
===========================================================================================
GridView1.DataKeyNames = new string[] { "主键" };
写在LOAD中.
protected void btnDel_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{
if (((CheckBox)this.GridView1.Rows[i].Cells[0].FindControl("chkSelect")).Checked)
{
OA_Business.Employer.Employer epy = new OA_Business.Employer.Employer();
epy.E_ID = int.Parse(GridView1.DataKeys[i].Value.ToString());
epy.E_Del();
}
}
BindEmployer();
}
这是一个用CheckBox选中删除的用于多选的.
#11
学习了。。。。。。。。。。。。