为DataGrid添加CheckBox控件

为DataGrid添加CheckBox控件

http://lucky_elove.www1.dotnetplayground.com/

查看例子

CheckBoxDataGrid.aspx

<xmp><%@ Page Language="vb" AutoEventWireup="false" Codebehind="CheckBoxDataGrid.aspx.vb" Inherits="aspxWeb.CheckBoxDataGrid" %> <html> <head> 为DataGrid添加CheckBox控件的例子 <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0"> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </head> <body ms_positioning="GridLayout"> <asp:datagrid autogeneratecolumns="False" id="dgMain" width="98%" runat="server"> <selecteditemstyle font-size="9pt" font-names="宋体"></selecteditemstyle> <edititemstyle font-size="9pt" font-bold="True" backcolor="Info" forecolor="Red" font-names="宋体"> </edititemstyle><alternatingitemstyle font-size="9pt" backcolor="White" forecolor="ControlText" font-names="宋体"> </alternatingitemstyle><itemstyle font-size="9pt" backcolor="WhiteSmoke" forecolor="ControlText" font-names="宋体"> <headerstyle horizontalalign="Center" verticalalign="Middle" font-bold="True" backcolor="Control" forecolor="Black"> </headerstyle> <columns> <asp:templatecolumn headertext="操作"> <headerstyle horizontalalign="Center" width="50px"></headerstyle> <itemtemplate> <asp:checkbox id="chkExport" runat="server"> </asp:checkbox></itemtemplate> <edititemtemplate> <asp:checkbox enabled="true" id="chkExportON" runat="server"> </asp:checkbox></edititemtemplate> </asp:templatecolumn> <asp:boundcolumn readonly="True" headertext="序号" datafield="id"> <headerstyle width="50px"></headerstyle> </asp:boundcolumn> <asp:templatecolumn sortexpression="demo" headertext="标题"> <itemtemplate> <asp:label text="&lt;%# Server.HTMLEncode(DataBinder.Eval(Container.DataItem, " title"))%="">" id="lblColumn" width="80%" runat="server"> </asp:label></itemtemplate> </asp:templatecolumn> </columns> </itemstyle></asp:datagrid> <asp:button text="全部选中" id="cmdSelectAll" runat="server"></asp:button> <asp:button text="查看选中的项目" id="cmdFindSelected" runat="server"></asp:button>
<asp:label id="Label1" runat="server"></asp:label> </body> </html> </xmp>

后代码 CheckBoxDataGrid.aspx.vb

<xmp>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. <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 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 = 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 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 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 End Class </xmp>
【通信原理 入坑之路】—— 详解IQ调制以及星座图原理 文章目录一. IQ调制与解调的原理与过程二.PSK(相移键控)和IQ调制的关系:2.1 用IQ调制实现QPSK调制 一. IQ调制与解调的原理与过程 IQ调制的定义是:“IQ调制就是数据分为两路,分别进行载波调制,两路载波相互正交。I是in-phase(同相), q是 quadrature(正交)” 我们通过下面的示意图介绍IQ调制的过程: 首先,信号分成两路:I路和Q路(为了方便理解我们把这两... 阅读详情

相关推荐

告别裸机:在FreeRTOS上为STM32移植SOEM EtherCAT主站的思路与实战

本文详细介绍了在FreeRTOS环境下为STM32移植SOEM EtherCAT主站的工程实践。通过重构任务调度模型、优化内存管理和中断响应,成功将通信周期抖动控制在±100ns以内,满足工业控制系统的严苛实时性要求。文章包含完整的移植策略、性能优化方法和实测数据,为开发者提供了一套可靠的EtherCAT主站解决方案。

weixin_30342363的博客 389

DataGrid中CheckBox操作

 一、实现全选或多选,并将ID值记入到控件hFlatID中   1、记录ID值的控件:           2、DataGrid代码:        <asp:DataGrid ID="dg" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True"

鲁班学艺 992

Halcon实战:基于图像清晰度自动筛选最佳对焦图片

本文详细介绍了如何使用Halcon实现基于图像清晰度的自动筛选最佳对焦图片技术。通过分析灰度值统计和标准差等核心指标,结合实战代码示例,帮助开发者高效处理工业检测中的对焦问题,提升自动化检测的准确性和效率。

weixin_27015733的博客 444

在DataGrid中利用CheckBox全选所有行

                                                    在DataGrid中利用CheckBox全选所有行 效果图:背景:asp.net中的DataGrid用复选框全选或全不选其中所有行思路:因为经常有这方面的需求,以往都是在客户端写脚本,通用性差。所以我想把该功能写成一个控件,以达到复用的效果。功能包括:1、DataGr

soarheaven的专栏 3676

2025年全国青少年信息素养大赛初赛真题(算法创意实践挑战赛C++初中组:文末附答案)

2025年全国青少年信息素养大赛初赛真题(算法创意实践挑战赛C++初中组:文末附答案)

王老师青少年编程 3399

educoder实训——计算几何形状的表面积与体积

educoder python实训

qq_41234663的博客 1230

DATAGRID 加入全选反选的按钮

 我们知道DataGrid是非常强大的一个ASP.NET组件,我们可以用它表示非常丰富的信息.在论坛里经常可以看见一些网友问一些关于该控件的问题,我虽不是什么高手但是对DataGrid还是有一些了解,加上我比较喜欢学习所以我今天就将DataGrid和CheckBox的组合使用做一个简单的描述.我们可能在写程序的时候都遇到这种情况:需要选择一个列表的所有项或者取消所有项的选择来删除这些列以及如何

拓荒者的跋涉 1129

Android实现TextToSpeech控件实现语音播报--朗读文字 (附完整源码)

Android实现TextToSpeech控件实现语音播报--朗读文字 (附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 1121

CheckBox在DataGrid上选择复选框

CheckBox在DataGrid上选择教程 »在DataGrid上选择CheckBox本教程将向您介绍如何在DataGrid上放置复选框列。通过复选框,用户可以选择一次选择/取消选择网格行。观看演示要添加复选框列,我们只需添加一个带有复选框属性的列并将其设置为true。代码看起来像这样:&lt;table id = “tt” title = “复选框选择” class = “easyui-dat...

qq_40435659的博客 1637

微信小程序 - 最新详细实现调起手机摄像头拍摄身份证人像面和国徽面取景框功能,在拍照相机上增加身份证证件照的轮廓或自定义文字,支持替换扫描拍摄辅助线图片及文本,小程序实现拍照身份证时带取景轮廓框拍摄!

微信小程序,身份证,证件照,人像,证件照提示框模板,vue身份证拍照框,摄像机相机里有引导内容,取景框拍摄,微信小程序实现拍照界面自定义实现,自拍人相框拍摄,取景框,户口簿取景框,画布指定区域生成图片,微信小程序身份证正反面拍照如何加入辅助图片引导照片,身份证取景框拍摄,服务器,上传,正反面,调起手机摄像头:拍摄身份证的正反面,自定义身份证取景框,在相机上绘制“身份证轮廓“与提示文字,拍摄身份证时出现人像框怎么实现,在相机上增加图片和文字,微信小程序怎么给调起的相机加入自定义图片,小程序实现给相机上面

🏆 前端领域优质创作者 1万+

企业级大模型落地:私有化部署的安全合规全流程实战指南

摘要:本文针对企业在大模型私有化部署中面临的数据泄露、合规风险及系统稳定性难题,提出一套覆盖数据安全、模型合规、审计追踪与灾备方案的全流程解决方案。通过双加密管道(国密SM4传输加密+AES-GCM存储加密)、SGX可信执行环境等技术,实现数据全生命周期保护;结合等保2.0三级要求与《生成式AI服务管理暂行办法》,提供合规性实施细则;并给出本地GPU集群、混合云、边缘推理盒子三种企业级部署方案及成本模型。

专注于人工智能、软件开发、工控自动化、工厂数字化及智能化等领域,希望和大家共同进步! 924

DataGridView 添加checkbox

DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn(); newColumn.HeaderText = "选择"; dataGridView1.Columns.Add(newColumn); 这样添加的列是放在最后一列,也许你希望它在其它列,例如第二列,那么可以: dataGridView1.Col

资料汇总整理-仅供个人学习使用 1349

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

datagrid控件中添加checkbox控件列

为DataGrid空间添加CheckBox控件列,首先需要为DataGrid控件添加一模版列,然后向模版列中添加CheckBox控件在System.Web.UI.WebControls命名空间中有一个DataGridItem类,用来表示DataGrid控件中的项。在该类中有一个FindControl方法,用来在当前的命名容器中搜索指定id参数的服务器控件,其使用方法如下:public

johncools的博客 2780

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

datagrid控件中添加了checkbox控件的使用

首先创建的表中,定义bool类型一列Check,DataGrid的数据源为DataTable ///         /// 选择全部        ///         public void SelectAll()        {            for (int i = 0; i true,表示选中            {                staff.Tab

ITmygirl的专栏 460

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

在DataGrid页眉上添加全选的CheckBox控件

很简单的方法,就是用js实现: 页面: <asp:datagrid id="dgUserList" runat="server" Width="640px" BorderColor="White" PagerStyle-HorizontalAlign="Right" AllowPaging="True" AllowSorting="True" AutoGenerateC...

a52202261的博客 83

[收藏]为DataGrid添加CheckBox控件

作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年5月23日 8点26分11秒为DataGrid添加CheckBox控件,并实现“全选”功能。这里是实现的例子VB.NET 版本CheckBoxDataGrid.aspx<%@ Page Language="vb" AutoEventWireup="false" Codebehind="CheckBoxDataGrid

goody9807的专栏 1285
上一篇: 在ASP.NET中实现多文件上传
下一篇: 让你的Mozilla支持XML数据岛
java2000_test
博客等级 码龄19年 10粉丝 320原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值