1

当前我正在构建一个用于数据输入目的的向导控件,其中需要根据第一步复选框列表中选择的项目动态构建步骤。我正在构建向导,它在 OnInit 方法中动态控制,如下所示:

WizardStep initiationStep = new WizardStep() { Title = "Add New Account/Service", ID = IniationStep" };
AddContentToInitiationStep(initiationStep);

WizardStep drugAndAlcoholStep = new WizardStep() { Title = "Drug and Alcohol", ID = "DrugAndAlcStep" };
BuildDrugAndAlcoholWizardStep(drugAndAlcoholStep);

WizardStep omrtStep = new WizardStep() { Title = "OMRT", ID = "OMRTStep" };
BuildOMRTWizardStep(omrtStep);

这些步骤是预先加载的,我使用 jQuery 根据用户在复选框列表中选择的内容将它们隐藏在侧栏中。问题出在 BuildDrugAndAlcoholWizardStep 方法中。在该方法中,我使用自定义服务器控件来构建动态加载的转发器。

private void BuildDrugAndAlcoholWizardStep(WizardStep step)
{
    AdvTable drugAndAlcoholTable = new AdvTable(0, 5);

    DataTable dt = ClientRegistrationServicesDB.ClientRegistrationServices_LoadByPolicyTemplateId(Config.GetDefaultDataStore(), policyTemplateId);

    var lblCollections = new Label() { Text = "Will this client use Consolidated Billing or will they pay the site directly?", CssClass = "label_l1" };
    AdvRadioButtonList radioBtnList = new AdvRadioButtonList() { ID = "BillType" };
    radioBtnList.Items.Add(new ListItem("Consolidated Billing", "ConsolidatedBilling"));
    radioBtnList.Items.Add(new ListItem("Pay Site Directly", "PaySiteDirectly"));

    AdvTabledRepeaterClientRegistrationDrugAndAlcohol mDrugAndAlc = new AdvTabledRepeaterClientRegistrationDrugAndAlcohol();

    drugAndAlcoholTable[0, 0].Controls.Add(lblCollections);
    drugAndAlcoholTable[1, 0].Controls.Add(radioBtnList);
    drugAndAlcoholTable[2, 0].Controls.Add(AdvQuickLiterals.BR);
    drugAndAlcoholTable[3, 0].Controls.Add(mDrugAndAlc);

    step.Controls.Add(drugAndAlcoholTable);
}

在实际的转发器服务器控件中,我们有一个重写的 CreateChildControls 方法,该方法将实际控件添加到转发器:

protected override void CreateChildControls()
{
    base.CreateChildControls();

    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());
    this.Cells.Add(new TableCell());

    this.Cells[0].Controls.Add(mPolicyTemplates);
    this.Cells[1].Controls.Add(DrugPrice);
    this.Cells[2].Controls.Add(AlcoholFee);
    this.Cells[3].Controls.Add(MemberSetupFee);
    this.Cells[4].Controls.Add(AnnualMaintenanceFee);
    this.Cells[5].Controls.Add(RandomRate);
    this.Cells[6].Controls.Add(TestPanel);
    this.Cells[7].Controls.Add(StartDate);

    mPolicyTemplates.ID = "PolicyTemplates";
    DrugPrice.ID = "DrugPrice";
    AlcoholFee.ID = "AlcoholFee";
    MemberSetupFee.ID = "MemberSetupFee";
    AnnualMaintenanceFee.ID = "AnnualMaintenanceFee";
    RandomRate.ID = "RandomRate";
    TestPanel.ID = "TestPanel";
    StartDate.ID = "StartDate";

    mPolicyTemplates.AutoPostBack = true;
    mPolicyTemplates.SelectedIndexChanged += PolicyTemplates_SelectedIndexChanged;
}

问题在于 mPolicyTemplates 下拉菜单。中继器上有一个“添加新行”链接,可导致为数据输入添加新行。在该行中是策略模板的下拉列表,当在下拉列表中选择策略模板时,它被选中的行应该使用 SelectedIndexChanged 方法中的数据库调用中的数据填充,唯一的问题是它不开火。对页面进行回发,服务器控制数据以及应该添加的新行都丢失了。Init 和 Load 方法在实际页面中被命中,但在服务器控件中没有触发任何事件。

我尝试将 AutoPostBack 和 SelectedIndexChanged 初始化程序放在服务器控件的 OnInit、OnLoad 和 OnDataBinding 事件中,但该事件永远不会触发。

我是否应该在生命周期中以另一种方法设置 SelectedIndex 更改事件?Is there something I need to do on the page itself so when the drop down is selected, the correct values are loaded into the new row that is to be inserted?

任何帮助将不胜感激。

4

0 回答 0