asp.net 统计panel里有多少个控件多种方法
foreach(control c in panel1.controls)
{
if (c is textbox)
{
if(c.clientid=="已知的id")
{}
}
}'方法二
panel1.controls.count;foreach(control con in panel1.controls)
{
if (con is checkbox)
{
checkbox cb = (checkbox)con;
cb.checked = true;
}
}
'来一个查找textbox的private void cleartextbox()
{
foreach (system.web.ui.control 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 = "";
}
}
}
}
'gridview行绑定时
protected void gridview1_rowdatabound(object sender, gridviewroweventargs e)
{for (int i = 0; i < gridview1.rows.count; i++)
{
//首先判断是否是数据行
if (e.row.rowtype == datacontrolrowtype.datarow)
{
//当鼠标停留时更改背景色
e.row.attributes.add("onmouseover", "c=this.style.backgroundcolor;this.style.backgroundcolor='#00a9ff'");
//当鼠标移开时还原背景色
e.row.attributes.add("onmouseout", "this.style.backgroundcolor=c");}
}if (e.row.rowtype == datacontrolrowtype.datarow)
{
//判断行的类型
if (e.row.rowstate == datacontrolrowstate.normal || e.row.rowstate == datacontrolrowstate.alternate)
{
//对话框
((linkbutton)e.row.cells[7].controls[0]).attributes.add("onclick", "javascript:return confirm('你确认要删除:《" + e.row.cells[0].text + "》 这本书吗?')");}
}}%>