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

推荐订阅源

AWS News Blog
AWS News Blog
Jina AI
Jina AI
量子位
V
V2EX
The GitHub Blog
The GitHub Blog
阮一峰的网络日志
阮一峰的网络日志
The Cloudflare Blog
博客园 - 【当耐特】
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
L
LangChain Blog
博客园_首页
aimingoo的专栏
aimingoo的专栏
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
T
Tailwind CSS Blog
M
MIT News - Artificial intelligence
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
博客园 - 聂微东
G
Google Developers Blog
C
CERT Recently Published Vulnerability Notes
K
Kaspersky official blog
NISL@THU
NISL@THU
Hacker News: Ask HN
Hacker News: Ask HN
腾讯CDC
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hackread – Cybersecurity News, Data Breaches, AI and More
酷 壳 – CoolShell
酷 壳 – CoolShell
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
H
Hacker News: Front Page
Webroot Blog
Webroot Blog
有赞技术团队
有赞技术团队
W
WeLiveSecurity
Martin Fowler
Martin Fowler
S
Security @ Cisco Blogs
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
WordPress大学
WordPress大学
雷峰网
雷峰网
PCI Perspectives
PCI Perspectives
月光博客
月光博客
SecWiki News
SecWiki News
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
C
Cyber Attacks, Cyber Crime and Cyber Security

博客园 - zqf620

.Net PetShop 3.0中购物车总价计算的bug .NET PetShop 3.0 FAQ novalidate选项无效的问题 .NET方向高级开发人员面试时应该事先考虑的问题 (zt) UML中的图 从一组数中每次抽取出一个数,并规定了每个数出现的概率 从一个表中随即抽取100条记录 PL/SQL User's Guide and Reference, Release 2 (9.2) chm版 下载 Oracle中实现自动增长列 在开发过程中运用UML 输出到html页面的字符串的格式化 在DataGrid控件中编辑数据项 DataGrid控件的分页 DTD简介 W3C XML Schema (XSD) XML相关技术概览 将web窗体页文件(test.aspx)转换成用户控件文件(test.ascx) access作为后台数据库遇到的访问权限问题 HTML实体
在DataGrid控件中获取数据项中各列的数据内容
zqf620 · 2007-01-20 · via 博客园 - zqf620


在DataGrid控件中,一般只是在绑定列或模版列中进行数据显示。
在编写DataGrid控件(控件名为dg1)的事件的处理方法时,通常希望获取数据项某列的数据。
除了SelectedInexChanged事件外,其它事件的处理方法的参数e都是DataGridCommandEventArgs类的实例。通过e实例,可以获取引发事件的数据项中数据。

1.获取绑定列中的数据
1)处于非编辑状态、或者数据项处于编辑状态但该绑定列只读
  e.Item.Cells[列索引].Text

2)处于编辑状态
绑定列如果处于编辑状态,则会显示为TextBox控件形式
  ((TextBox)(e.Item.Cells[列索引].Controls[0])).Text

2.获取模版列中的数据
在模版列中可以放置一个或多个控件(右键"编辑模版"菜单),这些控件可以绑定数据源中的数据
要获取绑定到模版列中某控件上的数据,首先要知道该控件的id,然后用FindControl方法获得该控件的引用。
  ((控件类型)(e.Item.Cells[列索引].FindControl("控件id"))).控件的属性
eg:((CheckBox)(e.Item.Cells[3].FindControl("cbSex"))).Checked