WebGrid不清楚..下边这个是gridview的例子.希望有点帮助 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim cb1 As New CheckBox Dim a As Integer For i = 0 To GridView1.Rows.Count - 1 cb1 = GridView1.Rows(i).Cells(4).FindControl("cb1") a = GridView1.Rows(i).Cells(0).Text If cb1.Checked Then cmd1.Connection = con cmd1.CommandType = Data.CommandType.Text cmd1.CommandText = "delete from tt where id='" & a & "'" cmd1.ExecuteNonQuery() End If Next GridView1.DataBind() End Sub
循环完毕后将记录下来的id删除,然后重新邦定Grid
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim cb1 As New CheckBox
Dim a As Integer
For i = 0 To GridView1.Rows.Count - 1
cb1 = GridView1.Rows(i).Cells(4).FindControl("cb1")
a = GridView1.Rows(i).Cells(0).Text
If cb1.Checked Then
cmd1.Connection = con
cmd1.CommandType = Data.CommandType.Text
cmd1.CommandText = "delete from tt where id='" & a & "'"
cmd1.ExecuteNonQuery()
End If
Next
GridView1.DataBind()
End Sub
我1年多前用过PowerDataGrid,但是发现只能绑定一条SQL语句,不知道目前得版本有没有解决这个问题!
{
CheckBox chk=(CheckBox)DataGrid1.Items[i].FindControl("chkSelect");
string 主键ID=DataGrid1.Items[i].Cells[索引].Text.Trim();
if(chk.Checked==true)
{
删除语句.........
}
}