2012-03-13 72 views
0

我有两个数据绑定下拉列表控件。第一个(dropdownlist1)直接从表中拉取。第二个(dropdownlist2)也从表中抽取,但​​是使用WHERE子句中dropdownlist1中的选定值。ASP.NET,dropdownlist1选择更改时刷新dropdownlist2?

用户在dropdownlist1中进行选择后,如何更新/刷新dropdownlist2? (使用VB,如果代码完成)

我试着将dropdownlist1的“Auto Postback”属性设置为“true”,最终这种方法起作用。唯一的问题是,如果我不断更改dropdownlist1中的选择,dropdownlist2中的可用选项将被复制。

这两个dropdownlist控件都包含在使用模板的CreateUserWizard控件中。我试过在Dropdownlist1的SelectedIndexChanged事件中使用FindControl,然后在dropdownlist2上使用DataBind(),但是在dropdownlist1中做出选择后没有发生变化。

任何想法?

SelectedIndexChanged事件

Protected Sub AssignedManager_SelectedIndexChanged(sender As Object, e As System.EventArgs) 
    CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("AssignedSupervisor").DataBind() 
End Sub 

*以上,AssignedManager是第一个下拉列表和AssignedSupervisor是第二个下拉列表*

+0

可以PLZ发表您的'SelectedIndexChanged'事件? – 2012-03-13 09:20:38

+0

上面的代码! – sevenyearsrust 2012-03-13 09:25:32

+0

您可以使用AppendDataBoundItems或您的下拉列表的视图状态属性。 – 2012-03-13 15:58:21

回答

0
Protected Sub AssignedManager_SelectedIndexChanged(sender As Object, e As System.EventArgs) 
    CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("AssignedSupervisor").DataSource 
    = GetDataSource(Ctype(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("FirstDropDownID"),Dropdownlist).SelectedValue) 

    CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("AssignedSupervisor").DataBind() 
End Sub 

Protected function GetDataSource(string id) as DataTable 
    'This function should return datatable based on the value (id) from the first dropdownlist 
End Function