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 +? ')");
}
}
} %>