前两天同事让我帮他解决一个问题,大体就是在页面中通过控件ID找到并修改DataGrid中的一个DropDownList的SelectedValue,他通过Page.FindControl无法找到。记得以前发现过这个问题,以前就是通过在Page控件树中递归查找解决的,今天顺便对asp.net的Page控件树结构研究了一下。
      下面是我递归查找的函数:
 1由Page.FindControl想到的Page控件树结构public object Myfindcontrol(Control parentcontrols,string id)
 2
      
由Page.FindControl想到的Page控件树结构<html>
由Page.FindControl想到的Page控件树结构
<body>
由Page.FindControl想到的Page控件树结构  
<h1>Welcome to my Homepage!</h1>
由Page.FindControl想到的Page控件树结构  
<form runat="server">
由Page.FindControl想到的Page控件树结构    What is your name?
由Page.FindControl想到的Page控件树结构    
<asp:TextBox runat="server" ID="txtName"></asp:TextBox>
由Page.FindControl想到的Page控件树结构    
<br />What is your gender?
由Page.FindControl想到的Page控件树结构    
<asp:DropDownList runat="server" ID="ddlGender">
由Page.FindControl想到的Page控件树结构      
<asp:ListItem Select="True" Value="M">Male</asp:ListItem>
由Page.FindControl想到的Page控件树结构      
<asp:ListItem Value="F">Female</asp:ListItem>
由Page.FindControl想到的Page控件树结构      
<asp:ListItem Value="U">Undecided</asp:ListItem>
由Page.FindControl想到的Page控件树结构    
</asp:DropDownList>
由Page.FindControl想到的Page控件树结构    
<br />
由Page.FindControl想到的Page控件树结构    
<asp:Button runat="server" Text="Submit!"></asp:Button>
由Page.FindControl想到的Page控件树结构  
</form>
由Page.FindControl想到的Page控件树结构
</body>
由Page.FindControl想到的Page控件树结构
</html>
由Page.FindControl想到的Page控件树结构

由Page.FindControl想到的Page控件树结构
参考自创建动态数据输入用户界面 ,本想自己写些东西,突然发现人家讲的已经很好,偷懒一下吧。

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
  • 2021-10-06
  • 2021-07-21
  • 2022-01-26
  • 2021-06-02
  • 2021-11-28
猜你喜欢
  • 2021-09-09
  • 2021-05-21
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-06-23
相关资源
相似解决方案