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

推荐订阅源

Google DeepMind News
Google DeepMind News
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
C
Cybersecurity and Infrastructure Security Agency CISA
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Hacker News
The Hacker News
P
Proofpoint News Feed
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
The Last Watchdog
The Last Watchdog
F
Fortinet All Blogs
S
Schneier on Security
Help Net Security
Help Net Security
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
P
Proofpoint News Feed
I
InfoQ
T
The Blog of Author Tim Ferriss
Cisco Talos Blog
Cisco Talos Blog
Stack Overflow Blog
Stack Overflow Blog
T
Troy Hunt's Blog
人人都是产品经理
人人都是产品经理
T
Threatpost
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cyber Attacks, Cyber Crime and Cyber Security
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
Forbes - Security
Forbes - Security
Vercel News
Vercel News
S
Security Affairs
美团技术团队
P
Privacy & Cybersecurity Law Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
IT之家
IT之家
U
Unit 42
Recorded Future
Recorded Future
W
WeLiveSecurity
PCI Perspectives
PCI Perspectives
P
Palo Alto Networks Blog
H
Hacker News: Front Page
S
Security @ Cisco Blogs
博客园 - 【当耐特】

博客园 - 流泉飞石

转:ADO.Net Entity Framework : (七) 多條件查詢 转载:GridView 空记录时显示 Header 代码重构相关书籍 转:恢复Reflector反编译后资源文件的办法 WPF 回车转Tab实现跳转 C#自定义快捷键实现介绍 C#程序多用户只启动一个进程的方法[转载] C#中自定义快捷键【转载】 转:[WPF] WPF资源收集 分享 转:.NET开发人员必知的八个网站 WatermarkComboBox 和 WatermarkTextBox 转:c#中线程访问winform控件的若干问题 [转] DotNet资源站点汇总 转:功能很强大的UIHelper类 转:动态修改webservice地址 转:CS结构软件自动升级实现 几个很好的url重写工具 asp.net获取应用程序路径 - 流泉飞石 - 博客园 SqlServer 查询sql执行时间
DataKeyNames工作 - 流泉飞石 - 博客园
流泉飞石 · 2009-11-26 · via 博客园 - 流泉飞石

谈谈对GridView控件DataKeyName属性的一点认识。
  页面前台有以下代码:
  <asp:GridView ID="View1" Width="100%" runat="server" AutoGenerateColumns="False" CellPadding="3" OnRowDataBound="View1_RowDataBound" CssClass="GbText" DataKeyNames="SubjectID,Mode" CellSpacing="1">
  后台有以下代码:
  protected void View1_RowDataBound(object sender,GridViewRowEventArgs e)
  {
   if(View1.DataKeys[e.Row.RowIndex].Values["Mode"].ToString().ToLower() == "false")
   {
   ......
   }
  }
  说明:
  由于为GridView控件的DataKeyNames属性设置了表的两个字段(SubjectID,Mode),因此可以在为GridView绑定数据时对库表的每个记录的指定字段值作出判断。后台代码中的e.Row.RowIndex即表示GridView的当前行(对应于库表的当前记录);而View1.DataKeys[e.Row.RowIndex].Values["Mode"].ToString()则获取当前行指定字段(Mode)的值。若前台代码只写:DataKeyNames="SubjectID'(即DataKeyNames属性只填入一个字段名),则后台只需写成: View1.DataKeys[e.Row.RowIndex].Value.ToString()) 即可。
  同样的,要动态获取当前行另一个字段的值可以这样写: View.DataKeys[e.Row.RowIndex].Values["SubjectID"].ToString())。
  总之,为GridView的DataKeyNames属性设置库表字段名的主要目的还是为了在为GridView控件绑定数据时获取当前行指定字段的值,以便作相应处理。若无此需求的话则GridView的DataKeyNames属性就可以不设置。