Add CheckBox control for DataGrid

xiaoxiao2021-03-05  21

Add CheckBox control CheckBoxDataGrid.aspx program code DataGrid <% @ Page Language = "vb" AutoEventWireup = "false" Codebehind = "CheckBoxDataGrid.aspx.vb" Inherits = "aspxWeb.CheckBoxDataGrid"%>

Adding an example of checkbox control for DataGrid

After the code CheckBoxDataGrid.aspx.vb Imports System.Data Imports System.Data.OleDb Public Class CheckBoxDataGrid Inherits System.Web.UI.Page Protected WithEvents cmdSelectAll As System.Web.UI.WebControls.Button Protected WithEvents dgMain As System.Web.UI .WebControls.DataGrid Protected WithEvents cmdFindSelected As System.Web.UI.WebControls.Button Dim oDataView As DataView Protected WithEvents Label1 As System.Web.UI.WebControls.Label Dim sConnectionString As String = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source = "_ server.mappath (" test.mdb ") #Region" Web form designer generated code "'this call is required by the Web Form Designer.

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 = "Option" DGMain.Columns (1) .Headertext = "Sequence" DGMain.columns (2) .Headertext = "CMDFindSelected.Text =" View selected item "refreshgrid () if not page.ispostback then cmdselectall. Text = "select all" dgMain.DataBind () End If End Sub #Region "multi-selection process" Private Sub cmdSelectAll_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles cmdSelectAll.Click selectAll () End Sub Private subsectall () Dim OdataGridItem As DataGriditem Dim Chkexport as system.Web.ui.WebControls.checkbox if cmdselectall.text = "All Selected" Then For Each OdataGridit em In dgMain.Items chkExport = oDataGridItem.FindControl ( "chkExport") chkExport.Checked = True Next cmdSelectAll.Text = "Select None" Else For Each oDataGridItem In dgMain.Items chkExport = oDataGridItem.FindControl ( "chkExport") chkExport. checked = False Next cmdSelectAll.Text = "select all" End If End Sub #End Region #Region "update DataGrid" Private Sub RefreshGrid () Dim oConnection As OleDbConnection Dim oCommand As OleDbDataAdapter Dim oDataSet As New DataSet () Try Dim sSQL As String = "SELECT TOP 5 * from testtable order by id" Oconnection =

转载请注明原文地址:https://www.9cbs.com/read-37924.html

New Post(0)