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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 露雨城市.NET2.0和Sql Server 2005开发研究

关于asp.net将动态页直接生成静态页的随笔(乱码) 我的神龙卡KTV点播软件只有一个遗憾了 关于清除Sql Server Express版本的数据库日志文件 关于微软2008技术预览大会南京站和Vista 也许是转折-放弃了5,6K的月薪 关于vs2005中ajax控件暴露模板中控件,请高手进来聊聊. - 露雨城市.NET2.0和Sql Server 2005开发研究 这个基础题,你能做对吗? 好久没有来发文章了,今天来秀一下。 在.NET2.0中如何更简单的使用委托将方法加载到事件中去 Visual C#中父窗口和子窗口之间实现控件互操作 关于如何在子窗口中选择后,在父窗口赋值并让输入框设为只读。 - 露雨城市.NET2.0和Sql Server 2005开发研究 我的新资源网站开张了,韩国模版,韩国设计资源等。 关于在插入的模版中如何为已绑定了Text属性的TextBox设置默认值 今天好高兴,通过了微软的Sql Server 2005的70-31的考试。 赠送一张微软免费考试券 VS2005中的一个小BUG:关于Dropdownlist无法Datadinding的解决方法。 如何动态设置全局theme,及在web.config中读取pages节点的内容。 讲故事谈.NET委托:一个C#睡前故事 关于的MasterPage和Theme的问题。
关于GridView中选择当前行的问题。
露雨城市.NET2.0和Sql Server 2005开发研究 · 2006-04-24 · via 博客园 - 露雨城市.NET2.0和Sql Server 2005开发研究

很多朋友问,点击GridView中自定义的一个模版内的控件,如何知道是点击的哪一行。
可能很多朋友都是熟悉了DataGrid的模式,说GridView还没有DataGrid好。
其实GridView还是非常强大的。特别是配合DetailsView来使用。

其实如何得到当前选择的行呢,很简单,使用Parent属性就可以呀。
比如我们自定义了一个LinkButton,那么当我们点击这个控件时如何知道它在GridView中所在的行呢,很简单,请看下面的代码。

1    protected void LinkButton1_Command(object sender, CommandEventArgs e)
2    {
3        LinkButton lb = (LinkButton)sender;
4        DataControlFieldCell dcf = (DataControlFieldCell)lb.Parent;
5        GridViewRow gvr = (GridViewRow)dcf.Parent;
6        GridView1.SelectedIndex = gvr.RowIndex;
7    }

是不是很简单呀,我们使用第一个Parent属性的时候就会将LinkButton的范围扩大到DataControlFieldCell(当前按钮所在表格中的列单元),然后再使用一次Parent属性,可以再将列单元的范围扩大到GridViewRow(当前列单元所在的行单元),这个时候使用行单元的RowIndex属性就可以得到当前行所在表格的序号了。

所以请大家不要随便说GridView还不如DataGrid了哦。其时asp.net2.0的新控件比1.1要多很多,而且也强大了不少。欢迎大家有什么问题再来一起交流哦。

posted on 2006-04-24 21:38  露雨城市.NET2.0和Sql Server 2005开发研究  阅读(3937)  评论()    收藏  举报