Sub btnDel_OnClick(ByVal sender As Object, ByVal e As EventArgs) Dim myDataGridItem_del As DataGridItem Dim chkSelected_del As System.Web.UI.WebControls.CheckBox Dim strBoardType_del As String Dim strBoardID_del As String
lblSelect.Text = "<br>You selected the Following items:<br><br>" lblStatus.Text="" For Each myDataGridItem_del In MyDataGrid.Items chkSelected_del = myDataGridItem_del.FindControl("chkSelection") If chkSelected_del.Checked Then lblSelect.visible=true strBoardType_del= CType(myDataGridItem_del.FindControl("lblBoardType"), Label).Text strBoardID_del = CType(myDataGridItem_del.FindControl("hdnBoardid"), Label).Text '-------------------------------------------- Dim MyDelCommand As OleDbCommand Dim DeleteCmd As String = "DELETE FROM [min] WHERE id = @Id" MyDelCommand = New OleDbCommand(DeleteCmd, MyConnection) MyDelCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11)) MyDelCommand.Parameters("@Id").Value = int32.parse(strBoardID_del) MyDelCommand.Connection.Open() MyDelCommand.ExecuteNonQuery() MyDelCommand.Connection.Close() '--------------------------------------------- lblStatus.Text += "The id is Deleted<b>" & strBoardType_del & "</b>" lblStatus.Text += " and the id is Deleted<b>" & strBoardID_del & "</b><br>" else lblSelect.visible=false End If Next try BindDataGrid() catch Mydatagrid.CurrentpageIndex=MyDataGrid.pagecount-1 BindDataGrid() end try End Sub
Sub btnDel_OnClick(ByVal sender As Object, ByVal e As EventArgs)
Dim myDataGridItem_del As DataGridItem
Dim chkSelected_del As System.Web.UI.WebControls.CheckBox
Dim strBoardType_del As String
Dim strBoardID_del As String
lblSelect.Text = "<br>You selected the Following items:<br><br>"
lblStatus.Text=""
For Each myDataGridItem_del In MyDataGrid.Items
chkSelected_del = myDataGridItem_del.FindControl("chkSelection")
If chkSelected_del.Checked Then
lblSelect.visible=true
strBoardType_del= CType(myDataGridItem_del.FindControl("lblBoardType"), Label).Text
strBoardID_del = CType(myDataGridItem_del.FindControl("hdnBoardid"), Label).Text
'--------------------------------------------
Dim MyDelCommand As OleDbCommand
Dim DeleteCmd As String = "DELETE FROM [min] WHERE id = @Id" MyDelCommand = New OleDbCommand(DeleteCmd, MyConnection)
MyDelCommand.Parameters.Add(New OleDbParameter("@Id", OleDbType.VarChar, 11))
MyDelCommand.Parameters("@Id").Value = int32.parse(strBoardID_del) MyDelCommand.Connection.Open()
MyDelCommand.ExecuteNonQuery()
MyDelCommand.Connection.Close()
'---------------------------------------------
lblStatus.Text += "The id is Deleted<b>" & strBoardType_del & "</b>"
lblStatus.Text += " and the id is Deleted<b>" & strBoardID_del & "</b><br>"
else
lblSelect.visible=false
End If
Next
try
BindDataGrid()
catch
Mydatagrid.CurrentpageIndex=MyDataGrid.pagecount-1
BindDataGrid()
end try
End Sub
i++改成i--
试试
cb = (CheckBox) dgi.Cells[0].Controls[1];
cell[0]改成cell[1],controls里的index也改一下试试
感觉是index的问题
cell[0].controls[0]
试试
异常详细信息: System.InvalidCastException: 指定的转换无效。源错误:
行 106: {
行 107:
行 108: cb = (CheckBox) dgi.Cells[0].Controls[0];
行 109:
行 110: if(cb.Checked==true
你去google搜索一下试试
或者看看这个
http://expert.csdn.net/Expert/topic/2995/2995178.xml?temp=.1162683
里面站点很多,你以后也用的到