惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
博客园_首页
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
WordPress大学
WordPress大学
人人都是产品经理
人人都是产品经理
宝玉的分享
宝玉的分享
博客园 - 叶小钗
Jina AI
Jina AI
罗磊的独立博客
Simon Willison's Weblog
Simon Willison's Weblog
Scott Helme
Scott Helme
D
DataBreaches.Net
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Project Zero
Project Zero
Know Your Adversary
Know Your Adversary
博客园 - Franky
AWS News Blog
AWS News Blog
S
Schneier on Security
K
Kaspersky official blog
I
Intezer
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
L
LINUX DO - 热门话题
GbyAI
GbyAI
月光博客
月光博客
C
Cisco Blogs
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
GRAHAM CLULEY
P
Privacy International News Feed
P
Privacy & Cybersecurity Law Blog
Hugging Face - Blog
Hugging Face - Blog
P
Proofpoint News Feed
T
Tor Project blog
F
Fortinet All Blogs
博客园 - 三生石上(FineUI控件)
T
Threat Research - Cisco Blogs
IT之家
IT之家
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security
S
Security Affairs
V
Visual Studio Blog
C
CERT Recently Published Vulnerability Notes
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
S
SegmentFault 最新的问题
MongoDB | Blog
MongoDB | Blog
T
Troy Hunt's Blog

博客园 - BlackAngel2bAssassin

使用SQL SERVER 内部函数进行密码加密和校验小问题 还原MOSS 默认的权限级别 破译moss 2007 中的权限提升功能 后台代码中使用Post 进行跳转 在自定义HttpHandler 中使用Session asp.net 1.1 用户控件的第二种重用 FireBird 点滴之JDBC连接字串 (转贴)实现带有数据绑定的客户端脚本控制的二级联动菜单 (转贴)使用Repeater实现自定义多列数据绑定 - BlackAngel2bAssassin - 博客园 (转贴)使用PagedDataSource给Repeater、DataList增加分页 (转贴)给Repeater、Datalist和Datagrid增加自动编号列 (转贴)如何取得DataGrid绑定列和模板列中的值 重新理解.net remoting SPS 中修改用户密码的WebPart 工程 FireBird 的使用点滴(一) 使用Webpart包装ActiveX组件 制作用户修改密码Webpart 的简短步骤 一个忘却了的SharePoint 的Bug 抽取word、excel、pdf等文件[转载]
一个DataGrid 的CheckBoxColumn
BlackAngel2bAssassin · 2005-11-07 · via 博客园 - BlackAngel2bAssassin

最近,因为需要用到在DATAGRID 中放置一些CheckBox 来判断是否选中某一行。本来可以使用javascript来实现。不过使用脚本实现,调试起来十分不方便,因此做一个后台代码的CheckBox 列来控制。
需要制作自定义功能的DATAGRID 列,需要继承DataGridColumn 这个类。然后重写 InitializeCell 这个方法来进行对这个自定义的列进行控制。代码中包含了记录选中的项,和没有被选中的项,并且可以在一个DataGrid中同时使用多个这样的CheckBox 列,只需要使用时通过ID属性区分就可以。
代码如下:

 1public override void InitializeCell(TableCell cell, int columnIndex, ListItemType itemType) 
 2        {
 3          
 4            //let the base class initialize the cell
 5            base.InitializeCell(cell, columnIndex, itemType);
 6
 7            //we don't want to add a checkbox to the header.
 8            if(itemType == ListItemType.EditItem || itemType == ListItemType.Item || itemType == ListItemType.AlternatingItem || itemType == ListItemType.SelectedItem){
 9
10                HtmlInputCheckBox checkbox = new HtmlInputCheckBox();
11                //assign an ID that we can use to find the control later
12                if(_strId==String.Empty)
13                {
14                    checkbox.ID = "checkboxCol";
15                }

16                else
17                {
18                    checkbox.ID=myID;
19                }

20        
21                cell.Controls.Add(checkbox);
22
23            }

24
25        }

这里只是继承DataGridColumn 重写InitializeCell函数的部分。

如何使用的代码片段

<dgctl:CheckBoxColumn HeaderText="用户名" ID="chkUserName">
                                    
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                
</dgctl:CheckBoxColumn>
                                
<dgctl:CheckBoxColumn HeaderText="用户详细信息" ID="chkUserDetail">
                                    
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                
</dgctl:CheckBoxColumn>

完整代码下载