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

推荐订阅源

IT之家
IT之家
The GitHub Blog
The GitHub Blog
美团技术团队
Security Latest
Security Latest
The Cloudflare Blog
D
DataBreaches.Net
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
The Exploit Database - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
P
Proofpoint News Feed
V
Vulnerabilities – Threatpost
Schneier on Security
Schneier on Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
S
Security Affairs
腾讯CDC
H
Hacker News: Front Page
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 三生石上(FineUI控件)
C
Check Point Blog
S
Security @ Cisco Blogs
Google DeepMind News
Google DeepMind News
Cisco Talos Blog
Cisco Talos Blog
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Security Archives - TechRepublic
Security Archives - TechRepublic
I
InfoQ
量子位
Apple Machine Learning Research
Apple Machine Learning Research
AWS News Blog
AWS News Blog
TaoSecurity Blog
TaoSecurity Blog
月光博客
月光博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
D
Docker
Hugging Face - Blog
Hugging Face - Blog
I
Intezer
雷峰网
雷峰网
Engineering at Meta
Engineering at Meta
WordPress大学
WordPress大学
SecWiki News
SecWiki News
N
News and Events Feed by Topic

博客园 - 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>

完整代码下载