ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法示例
本文实例讲述了ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法。分享给大家供大家参考,具体如下:
//gridview遍历如下:
foreach (GridViewRow row in GridView1.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("CheckBox2");
if (cb.Checked == true)
{
}
}
//datagrid遍历:
foreach (DataGridItem oItem in ItemsGrid.Items)
{
CheckBox ck1 = (CheckBox)oItem.FindControl("CheckBox");
if (ck1.Checked == true)
{
}
}
//datalist遍历
foreach (DateListItem dl in DataList1.Items)
{
CheckBox cb = (CheckBox)dl.FindControl("CheckBoxID ");
if(cb.checked)
......
}
GridView:
for(int i=0; i <GridView.Rows.Count;i++)
{
Label lbl = (Label)GridView.Rows[i].FindControl("Label9");
}
Repeater:
for(int i=0; i < Repeater.Items.Count;i++)
{
Label lbl = (Label) Repeater.Items[i].FindControl("Label9");
}
DataList:
for(int i=0; i < DataList.Items.Count;i++)
{
Label lbl = (Label) DataList.Items[i].FindControl("Label9");
}
更多关于asp.net相关内容感兴趣的读者可查看本站专题:《asp.net操作json技巧总结》、《asp.net字符串操作技巧汇总》、《asp.net操作XML技巧总结》、《asp.net文件操作技巧汇总》、《asp.net ajax技巧总结专题》及《asp.net缓存操作技巧总结》。
希望本文所述对大家asp.net程序设计有所帮助。
相关文章
MVC使用Controller代替Filter完成登录验证(Session校验)学习笔记5
这篇文章主要介绍了MVC使用Controller代替Filter完成登录验证即Session校验,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2016-09-09
Queryable.Union 方法实现json格式的字符串合并的具体实例
这篇文章介绍了Queryable.Union 方法实现json格式的字符串合并的具体实例,有需要的朋友可以参考一下2013-10-10
ASP.NET The system cannot find the file specified解决办法
这篇文章主要介绍了ASP.NET The system cannot find the file specified解决办法的相关资料,需要的朋友可以参考下2016-11-11


最新评论