Asp.net multiple methods for calculating the number of controls in a Panel

Source: Internet
Author: User

Asp.net multiple methods for calculating the number of controls in a panel

Foreach (control c in panel1.controls)
{
If (c is textbox)
  {
If (c. clientid = "known id ")
{}
  }
}

'Method 2
Panel1.controls. count;

Foreach (control con in panel1.controls)
        {
If (con is checkbox)
            {
Checkbox cb = (checkbox) con;
Cb. checked = true;
            }
        }


'To find the textbox

Private void cleartextbox ()
  { 
Foreach (system. web. ui. control in this. controls)
      { 
For (int I = 0; I <control. controls. count; I ++)
           { 
If (control. controls [I] is system. web. ui. webcontrols. textbox)
             { 
System. web. ui. webcontrols. textbox tbx = (system. web. ui. webcontrols. textbox) control. controls [I];
Tbx. text = "";
             } 
           } 
      } 
   }
  
'

When the gridview row is bound
Protected void gridview1_rowdatabound (object sender, gridviewroweventargs e)
  {

For (int I = 0; I <gridview1.rows. count; I ++)
  {
// First determine whether it is a data row
If (e. row. rowtype = datacontrolrowtype. datarow)
  {
// Change the background color when the mouse stays
E. row. attributes. add ("onmouseover", "c = this. style. backgroundcolor; this. style. backgroundcolor = '# 00a9ff '");
// Restore the background color when you move the mouse away.
E. row. attributes. add ("onmouseout", "this. style. backgroundcolor = c ");

  }
  }

If (e. row. rowtype = datacontrolrowtype. datarow)
  {
// Determine the row type
If (e. row. rowstate = datacontrolrowstate. normal | e. row. rowstate = datacontrolrowstate. alternate)
  {
// Dialog box
(Linkbutton) e. row. cells [7]. controls [0]). attributes. add ("onclick", "javascript: return confirm ('are you sure you want to delete:' + e. row. cells [0]. text +? ')");

  }
  }

} %>

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.