ASP.NET向导控件DropDownlist SelectedIndexChanged未触发

时间:2013-06-17 19:41:07

标签: c# asp.net

当前我正在为数据输入目的构建向导控件,其中需要根据第一步中复选框列表中选择的项动态构建步骤。我正在构建向导,它在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方法在实际页面中被命中,但是在服务器控件中没有触发任何事件。

我尝试在服务器控件中的OnInit,OnLoad和OnDataBinding事件中放置AutoPostBack和SelectedIndexChanged初始值设定项,但事件永远不会触发。

我是否应该在生命周期中的另一种方法中设置SelectedIndex更改事件?我需要在页面上做些什么,所以当选择下拉列表时,正确的值会被加载到要插入的新行中吗?

非常感谢任何帮助。

0 个答案:

没有答案