通过页面集合控件在gridview中查找控件 [英] find control inside gridview by Page Collections Controls

查看:66
本文介绍了通过页面集合控件在gridview中查找控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我们使用以下代码查找页面上的每个控件



  foreach (System.Web.UI.Control c  in  Page.Controls)
{

}





我们可以通过ID检查控制,遵循以下规则



  foreach (System.Web.UI.Control c  in  Page.Controls)
{

if (c.ID == ddlLandCost
{
}
}







但如果我想通过相同的上面的代码找到gridview中的控件,那么伙计们如果你有任何想法请帮助...因为我的逻辑依赖于上面的代码。我不想使用任何rowdatabound event ...

解决方案

  foreach (System.Web.UI.Control c  in  Page.Controls)
{
Control objChild =((Control)Page.Controls [i ]);

}

使用类似 ..


你可以找到如下控件:

(e.Item.FindControl(  txtInsuranceTypeDescription as  SysXTextBox).Text; 

其中txtInsuranceTypeDescription是一个文本框控件


E.g We use following code to find each control on page

foreach (System.Web.UI.Control c in Page.Controls)
 {

}



we can check control by Id ,in Following Code

foreach (System.Web.UI.Control c in Page.Controls)
 {

if (c.ID == "ddlLandCost")
           {
           }
}




but if I want to find control which is in gridview by same above code, guys if you have any idea please help...As my logic is depend on above code.i dont want to use any rowdatabound event...

解决方案

foreach (System.Web.UI.Control c in Page.Controls)
 {
Control objChild=((Control)Page.Controls[i]);

}

use like this..


you can find your controls like below:

(e.Item.FindControl("txtInsuranceTypeDescription") as SysXTextBox).Text;

where txtInsuranceTypeDescription is a textbox control.


这篇关于通过页面集合控件在gridview中查找控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆