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

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
H
Help Net Security
V
Visual Studio Blog
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
MyScale Blog
MyScale Blog
The Cloudflare Blog
Martin Fowler
Martin Fowler
D
Docker
腾讯CDC
F
Fortinet All Blogs
雷峰网
雷峰网
GbyAI
GbyAI
G
Google Developers Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Blog — PlanetScale
Blog — PlanetScale
Engineering at Meta
Engineering at Meta
博客园 - 聂微东
博客园 - 叶小钗

博客园 - boulder

asp.net 利用Cookie实现免登陆(c#) - boulder - 博客园 Md5Encode 算法 javascript浮动图片 - boulder - 博客园 导出Excel - boulder - 博客园 获取键盘的enter - boulder - 博客园 oracle 的float(b)转 oracle函数(关于处理小数点位数) char、varchar和varchar2的区别(转) - boulder - 博客园 生成验证码(转) - boulder - 博客园 ASP.NET 2.0利用Httphandler实现URL重写(伪URL及伪静态)(转) .net上传文件的限制 电话号码的验证表达式 GridView 在换页时保持CheckBox的选择 自定义datatable 没有装Express版Sql Server 2005就不能用WebPart ? (转) form表单 input 通过查询系统表得到纵向的表结构 Codebehind CodeFile转 解决flash的虚框问题
在DataList中找到控件
boulder · 2007-09-13 · via 博客园 - boulder

在DataList中找到自己添加的控件有两种方式,以RadioButtonList控件为例:

1.在DataList的ItemDateBound或是CreatDataBound事件中写
--rbID是RadioButtonList 控件的ID属性
Protected void DataList1_ItemDataBound(object sender,DataListItemEventArgs e)
{
   if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
     {
       RadioButtonList rbl1 = e.Item.FindControl("rbID") as RadioButtonList ;//找到RadioButtonList 
    }
}
2如果在其他地方,且DataList控件在page_load事件中绑定了,一定要保证绑定内容在
if(!IsPostBack)
{
  //绑定BindDataList();
}
因为在其他地方的可以引起页面回发得控件会在引起页面刷新,重新绑定RadioButtonList 
这样就获取不了RadioButtonList 选中的值了
代码可以这样写:
foreach(DataListItem item in DataList1.Items)
{
   RadioButtonList  rbl2 = ( RadioButtonList )item.FindControl("rbId");
   if(rbl2.SelectedIndex !=-1)
    {
     //你自己的操作
    }
}