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

推荐订阅源

T
The Blog of Author Tim Ferriss
Know Your Adversary
Know Your Adversary
P
Palo Alto Networks Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Google DeepMind News
Google DeepMind News
Attack and Defense Labs
Attack and Defense Labs
Cisco Talos Blog
Cisco Talos Blog
AI
AI
L
LINUX DO - 最新话题
H
Heimdal Security Blog
Hacker News: Ask HN
Hacker News: Ask HN
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
I
Intezer
Blog — PlanetScale
Blog — PlanetScale
有赞技术团队
有赞技术团队
S
Securelist
博客园_首页
IT之家
IT之家
Schneier on Security
Schneier on Security
博客园 - 叶小钗
罗磊的独立博客
WordPress大学
WordPress大学
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
W
WeLiveSecurity
The Register - Security
The Register - Security
D
DataBreaches.Net
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
腾讯CDC
Recorded Future
Recorded Future
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tailwind CSS Blog
N
News and Events Feed by Topic
Cyberwarzone
Cyberwarzone
T
Tor Project blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com

博客园 - 什么都不知道

DataSet的Xml序列化问题 VB.NET的一个小问题 Access is denied的问题 - 什么都不知道 存储过程output参数问题 SQL Server的效率? datagrid刷新问题 使用Visio DrawingControl的应用开发(补) 突起效果的Label WinForm下TextBox的数据绑定和更新 如何在运行时加载不处于应用程序目录下的assembly 使用VSA给程序加上脚本支持 删除所有Windows组件 在ASP.NET中嵌入wml标记 c#中动态装载dll 处理大型xml文件 RedirectToMobilePage的问题 使用Visio 2003 Drawing Control开发应用(3)(4) 使用Visio 2003 Drawing Control开发应用(2) 使用Visio 2003 Drawing Control开发应用(1)
使用Radio按钮选择DataGrid行
什么都不知道 · 2004-10-06 · via 博客园 - 什么都不知道

(读自http://www.dotnetbips.com/displayarticle.aspx?id=147 有源代码下载)
这个问题的出现是因为RadioButtons控件是不能直接加在DataGrid的模板列的。因为DataGrid会给每个单选按钮生成一个唯一名,这样这些单选按钮就不是一个组的了。

解决问题的办法是,在模板列中加入一个Label控件。在DataGrid的ItemDataBound事件中写<INPUT>元素,如:

        If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
            
Dim r As Label
            r 
= e.Item.FindControl("Label2")
            r.Text 
= "<input type=radio name='myradiogroup' value=" & e.Item.Cells(1).Text & ">"
        End If


如果要获得选中的值,就要用Request.Form来获取了

         Label3.Text = Request.Form("myradiogroup")

如果在PostBack之后要保留状态,就要自己做了

        Dim i As DataGridItem
        
For Each i In DataGrid1.Items
            
If i.ItemType = ListItemType.AlternatingItem Or i.ItemType = ListItemType.Item Then
                
Dim r As Label
                r 
= i.FindControl("Label2")
                
If r.Text.IndexOf(Label3.Text) > 0 Then
                    r.Text 
= "<input type=radio name='myradiogroup' value=" & i.Cells(1).Text & " checked>"
                Else
                    r.Text 
= "<input type=radio name='myradiogroup' value=" & i.Cells(1).Text & ">"
                End If
            
End If
        
Next