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

推荐订阅源

T
The Exploit Database - CXSecurity.com
G
Google Developers Blog
爱范儿
爱范儿
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
C
Check Point Blog
F
Fortinet All Blogs
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - 【当耐特】
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
P
Palo Alto Networks Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
M
MIT News - Artificial intelligence
Vercel News
Vercel News
博客园 - 司徒正美
Recorded Future
Recorded Future
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Webroot Blog
Webroot Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
云风的 BLOG
云风的 BLOG
D
DataBreaches.Net
Y
Y Combinator Blog
J
Java Code Geeks
B
Blog
A
About on SuperTechFans
O
OpenAI News
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
AWS News Blog
AWS News Blog
GbyAI
GbyAI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
V
V2EX
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
Help Net Security
Help Net Security
W
WeLiveSecurity
C
Cyber Attacks, Cyber Crime and Cyber Security

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

完整代码下载