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 are required by the Web Form Designer.
<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-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
Dgmain.columns (0). HeaderText = "Options"
Dgmain.columns (1). HeaderText = "ordinal"
Dgmain.columns (2). HeaderText = "title"
Cmdfindselected.text = "View Selected items"
Refreshgrid ()
If not Page.IsPostBack Then
Cmdselectall.text = "All selected"
Dgmain.databind ()
End If
End Sub
#Region "Process multiple selections"
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 = "All selected" Then
For each odatagriditem in Dgmain.items
Chkexport = Odatagriditem.findcontrol ("Chkexport")
chkexport.checked = True
Next
Cmdselectall.text = "All not selected"
Else
For each odatagriditem in Dgmain.items
Chkexport = Odatagriditem.findcontrol ("Chkexport")
chkexport.checked = False
Next
Cmdselectall.text = "All selected"
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 * out testtable ORDER by id"
oconnection = New OleDbConnection (sConnectionString)
Ocommand = New OleDbDataAdapter (ssql.tostring, oconnection)
Ocommand.fill (Odataset, "TestTable")
oDataView = New DataView (odataset.tables ("TestTable"))
Dgmain.datasource = oDataView
Oconnection.close ()
Catch ex as Exception
'//Place Error handling
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
Label1.Text = ""
For each odatagriditem in Dgmain.items
Chkexport = Odatagriditem.findcontrol ("Chkexport")
If chkexport.checked Then
Label1.Text = ""
SID = CType (Odatagriditem.findcontrol ("Lblcolumn"), Label). Text
Oexargs.add (SID)
Dim i as Integer = 0
For i = 0 to Oexargs.count-1
Label1.Text + = Oexargs (i) + ","
Next
End If
Next
End Sub
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Data.OleDb;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Namespace EMeng.Exam.DataGridCheckBox
{
<summary>
Summary description of the Datagridcheckbox.
"The Wonderful World of Mengxian"
</summary>
public class DataGridCheckBox:System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Cmdselectall;
protected System.Web.UI.WebControls.Button cmdfindselected;
protected System.Web.UI.WebControls.DataGrid Dgmain;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
DataView oDataView;
string sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data source="
+ HttpContext.Current.Server.MapPath (".. /.. /aspxweb.mdb.ascx ");
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
Dgmain.columns[0]. HeaderText = "option";
DGMAIN.COLUMNS[1]. HeaderText = "serial number";
DGMAIN.COLUMNS[2]. HeaderText = "title";
Cmdfindselected.text = "View selected items";
Refreshgrid ();
if (!this. IsPostBack)
{
Cmdselectall.text = "All selected";
Dgmain.databind ();
}
}
#region Web Form Designer generated code
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This.cmdSelectAll.Click + = new System.EventHandler (This.cmdselectall_click);
This.cmdFindSelected.Click + = new System.EventHandler (This.cmdfindselected_click);
This. Load + = new System.EventHandler (this. Page_Load);
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.