Asp. NET in the GridView, DataList, DataGrid three Data Control foreach Traversal Usage example _ practical tips

Source: Internet
Author: User

The examples in this article describe the foreach traversal usage of the GridView, DataList, DataGrid three data controls in ASP.net. Share to everyone for your reference, specific as follows:

The GridView traversal is as follows: 
foreach (GridViewRow row in gridview1.rows)
{
  checkbox cb = (checkbox) row. FindControl ("CheckBox2");
  if (CB). Checked = = True)
  {
  }
}
//datagrid traversal:
foreach (DataGridItem oitem in Itemsgrid.items)
{
  checkbox ck1 = (checkbox) Oitem.findcontrol ("checkbox");
  if (ck1. Checked = = True)
  {
  }
}
//datalist traversal
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");
}

More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."

I hope this article will help you to ASP.net program design.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.