A small example of the GridView control traversal in asp.net _ Practical tips

Source: Internet
Author: User

Copy Code code as follows:

Int intcount = this. GridView1.Rows.Count; Total number of rows
for (int i = 0; i < intcount; i++)
{
Label1.Text = ((HyperLink) gridview1.rows[i]. Cells[0]. Controls[0]). Text.tostring (). Trim ();

}


for (i = 0; i < GridViewID.Rows.Count; i++)
{
CheckBox chkvote = (checkbox) Gridview1.rows[i]. FindControl ("CheckBox2");
}


It's all about using for to traverse the Ridview control, and I'm going to use foreach to traverse the control.

Copy Code code as follows:

foreach (GridViewRow row in gridview1.rows)
{
CheckBox cb = (checkbox) row. FindControl ("CheckBox2");
if (CB). Checked==true)
{
}
}

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.