#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
Protected WithEvents cmdSelectAll As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents dgMain As System.Web.UI.WebControls.DataGrid
Protected WithEvents cmdFindSelected As System.Web.UI.WebControls.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
dgMain.Columns(0).HeaderText = "选项"
dgMain.Columns(1).HeaderText = "序号"
dgMain.Columns(2).HeaderText = "标题"
cmdFindSelected.Text = "查看选中的项目"
RefreshGrid()
If Not Page.IsPostBack Then
cmdSelectAll.Text = "全部选中"
dgMain.DataBind()
End If
End Sub
#Region "处理多选"
Private Sub cmdSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSelectAll.Click
selectAll()
End Sub
Private Sub selectAll()
Dim oDataGridItem As DataGridItem
Dim chkExport As System.Web.UI.WebControls.CheckBox
If cmdSelectAll.Text = "全部选中" Then
For Each oDataGridItem In dgMain.Items
chkExport = oDataGridItem.FindControl("chkExport")
chkExport.Checked = True
Next
cmdSelectAll.Text = "全部不选"
Else
For Each oDataGridItem In dgMain.Items
chkExport = oDataGridItem.FindControl("chkExport")
chkExport.Checked = False
Next
cmdSelectAll.Text = "全部选中"
End If
End Sub
#End Region
#Region "更新DataGrid"
Private Sub RefreshGrid()
Dim oCommand As OleDbDataAdapter
Dim oDataSet As New DataSet
Try
Dim sSQL As String = "Select title,id from new_article"
oCommand = New OleDbDataAdapter(sSQL.ToString, cn)
oCommand.Fill(oDataSet, "new_article")
dgMain.DataSource = oDataSet.Tables("new_article")
cn.Close()
Catch ex As Exception
'// Place Error Handling here
End Try
End Sub
#End Region
Private Sub cmdFindSelected_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFindSelected.Click
Dim oDataGridItem As DataGridItem
Dim chkExport As System.Web.UI.WebControls.CheckBox
Dim oExArgs As New System.Collections.ArrayList
Dim sID As String
Dim chk As String
For Each oDataGridItem In dgMain.Items
chkExport = oDataGridItem.FindControl("chkExport")
If chkExport.Checked Then
chk = Nothing
sID = CType(oDataGridItem.FindControl("lbl"), Label).Text
oExArgs.Add(sID)
Dim i As Integer = 0
For i = 0 To oExArgs.Count - 1
chk += oExArgs(i) + ","
Dim delid() As String
delid = chk.Split(",")
Dim m As Integer = 0
For m = 0 To delid.Length - 2
delete(delid(m))
Next
Next
End If
Next
RefreshGrid()
dgMain.DataBind()
End Sub
Function delete(ByVal id As Integer)
Dim cmd As New OleDbCommand("delete from new_article where id=" & id, cn)
cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
End Function
End Class
浙公网安备 33010602011771号