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

推荐订阅源

V2EX - 技术
V2EX - 技术
T
Troy Hunt's Blog
The Last Watchdog
The Last Watchdog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Secure Thoughts
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 司徒正美
TaoSecurity Blog
TaoSecurity Blog
博客园 - Franky
有赞技术团队
有赞技术团队
Google Online Security Blog
Google Online Security Blog
罗磊的独立博客
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
NISL@THU
NISL@THU
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Recent Commits to openclaw:main
Recent Commits to openclaw:main
K
Kaspersky official blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
W
WeLiveSecurity
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
O
OpenAI News
V
V2EX
AI
AI
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
美团技术团队
C
Cyber Attacks, Cyber Crime and Cyber Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Security Archives - TechRepublic
Security Archives - TechRepublic
博客园 - 三生石上(FineUI控件)
G
GRAHAM CLULEY
月光博客
月光博客
T
Threatpost
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Vulnerabilities – Threatpost
Last Week in AI
Last Week in AI
爱范儿
爱范儿
C
CXSECURITY Database RSS Feed - CXSecurity.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Cloudbric
Cloudbric
酷 壳 – CoolShell
酷 壳 – CoolShell
The Hacker News
The Hacker News
N
News | PayPal Newsroom
Know Your Adversary
Know Your Adversary

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

完整代码下载