寻找在TemplatedWizardStep控制 [英] Finding a control in TemplatedWizardStep

查看:233
本文介绍了寻找在TemplatedWizardStep控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个包含组合框供用户输入一个向导控制。我使用 TemplatedWizardStep 逾外观和导航控制。据我了解,访问这样的步骤内部控制需要使用中的FindControl(ID)

I am making a Wizard Control that contains combo boxes for user input. I am using TemplatedWizardStep for the control over appearance and navigation. I have learned that accessing a control inside such a step requires use of FindControl(id).

我的向导,基本上是这样的,剥出大量的格式:

My wizard looks basically like this, stripping out lots of formatting:

<asp:Wizard id="wizEntry" runat="server" >
   <WizardSteps>
      <asp:TemplatedWizardStep id="stepFoo" Title="Foo" runat="server" >
         <table id="TableFoo" runat="server" >
            <tr id="Row1">
               <td id="Row1Cell1">
                  <asp:DropDownList id="DDListBar" runat="server" ></asp:DropDownList>
</td></tr></table></asp:TemplatedWizardStep></WizardSteps></asp:Wizard>

我想获得 DDListBar 里面的向导选择的值奇才。我的研究表明,我应该叫的FindControl 向导上得到一步的话上步得到控制。我的code:

I want to get the selected value of DDListBar inside wizard wiz. My research shows that I should call FindControl on the wizard to get the step, then on the step to get the control. My code:

DropDownList ddlBar = null;
bar = (DropDownList)wizEntry.FindControl("stepFoo").FindControl("DDListBar");

当我跑这,回来为。所以,我分头的FindControl 呼叫。我决定向导步骤是被正确地发现,而不是组合框。事实上,在向导的步骤只有控制了桌子上。

When I ran this, bar came back as null. So I split up the calls to FindControl. I determined that the wizard step was being found properly, but not the combo box. In fact, the only control in the wizard step was the table.

我希望有,我还没有学会,而不是针对的FindControl在嵌套控制层次每个级别一个简单的解决方案。

I hope there's a simple solution that I have not learned, as opposed to FindControl for each level in the nested control hierarchy.

(旧版code使用长表,每行一个组合框,C#code文件中直接通过ID引用的组合框,但该表太长,而客户想要一个向导分手的数据录入成小单位。)

(The legacy code uses a long table with one combo box per row. The C# code file references those combo boxes directly by ID. But the table is Too Long, and the customer wants a wizard to break up the data entry into small units.)

编辑1:这个答案是在我的研究,到目前为止有帮助

Edit 1: This answer was helpful in my research so far.

推荐答案

由于 DDListBar 在里面嵌套的 TableFoo 服务器控件,你需要递归找到它。

Since DDListBar is nested inside TableFoo server control, you need to find it recursively.

下面是一个辅助方法。递归搜索任何控制。

Here is a helper method. It searches any control recursively.

public static Control FindControlRecursive(Control root, string id)
{
   if (root.ID == id) 
     return root;

   return root.Controls.Cast<Control>()
      .Select(c => FindControlRecursive(c, id))
      .FirstOrDefault(c => c != null);
}

用法

var ddListBar =  (DropDownList)FindControlRecursive(wizEntry, "DDListBar"); 

这篇关于寻找在TemplatedWizardStep控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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