欢迎来到代码驿站!

.NET代码

当前位置:首页 > 软件编程 > .NET代码

ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法示例

时间:2021-07-03 08:27:35|栏目:.NET代码|点击:

本文实例讲述了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程序设计有所帮助。

上一篇:asp.net 请求输入到输出的全过程及httpHandler和httpModuler详细介绍

栏    目:.NET代码

下一篇:ASP.NET与数据库相关技巧

本文标题:ASP.NET中GridView、DataList、DataGrid三个数据控件foreach遍历用法示例

本文地址:http://www.codeinn.net/misctech/151994.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有