2013-07-08 48 views
0

我使用CreateWizardStep創建用戶到我的網站...我添加了新的步驟,並在步驟中放置一個CheckBoxList,但我試圖搜索此控件,但它返回空引用錯誤,下面的代碼剪輯:如何在WizardStep中找到控件?

ASPX

<asp:CreateUserWizard ID="RegisterUserWithRoles" runat="server" ContinueDestinationPageUrl="~/Default.aspx" LoginCreatedUser="False" OnActiveStepChanged="RegisterUserWithRoles_ActiveStepChanged" ActiveStepIndex="1"> 
    <WizardSteps> 
     <asp:CreateUserWizardStep runat="server" /> 
     <asp:WizardStep ID="SpecifyRolesStep" runat="server" AllowReturn="False" StepType="Step" Title="Specify Roles"> 
      <asp:CheckBox ID="RoleList" runat="server" /> 
     </asp:WizardStep> 
     <asp:CompleteWizardStep runat="server" /> 
    </WizardSteps> 
</asp:CreateUserWizard> 

C#

// Reference the SpecifyRolesStep WizardStep . 
WizardStep SpecifyRolesStep = RegisterUserWithRoles.FindControl("SpecifyRolesStep") as WizardStep; 

// Reference the RoleList CheckBoxList 
CheckBoxList RoleList = SpecifyRolesStep.FindControl("RoleList") as CheckBoxList; 

// Bind the set of roles to RoleList 
RoleList.DataSource = System.Web.Security.Roles.GetAllRoles(); 
RoleList.DataBind(); 

我怎樣才能找到StepWizard這裏面CheckBoxList控件?

回答

1

它可能爲空,因爲as關鍵字正在嘗試並且未能將複選框強制轉換爲複選框列表。

嘗試改變的RoleList到<asp:CheckBoxList ID="RoleList" runat="server"> </asp:CheckBoxList>

+0

我很多感謝!我相信我可以將複選框轉換爲複選框列表...但現在我發現它不可能執行演員... – omixam

0

你必須去的嚮導步驟之前,首先你可以訪問控制

if (Wizard1.ActiveStep.Title == "Specify Roles") 
     { 
      CheckBox RoleList = RegisterUserWithRoles.ActiveStep.FindControl("RoleList") as CheckBox; 

     } 

我發現這個在這裏: http://forums.asp.net/t/1265377.aspx/1

相關問題