【发布时间】:2012-05-13 16:27:21
【问题描述】:
如何在asp.net上制作动态下拉列表?
我有一个下拉列表:
<asp:DropDownList ID="FirstParameter" runat="server">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
</asp:DropDownList>
一个标签和另一个下拉列表:
<asp:Label ID="SecondParameter_Label" runat="server" Text=""></asp:Label>
<asp:DropDownList ID="SecondParameter" runat="server">
</asp:DropDownList>
当我更改 FirstParameter 下拉列表上的选择时,SecondParameter_Label 上的文本应根据选择而更改,因此对于 SecondParameter 下拉列表,应根据所选值与数据过滤器绑定在第一个下拉列表中。
我已经尝试过这段代码,但它不起作用:
Protected Sub FirstParameter_SelectedIndexChanged(sender As Object, e As System.EventArgs) Handles FirstParameter.SelectedIndexChanged
'Change the label text
SecondParameter_Label.Text = ReportType_Dropdownlist.SelectedItem.Value
'Bind value to the SecondParameter dropdownlist
SecondParameter.DataSource = dataTableName '--> Assumed that I already have the DataTable called from a class
SecondParameter.DataTextField = "NameofDatabaseColumn"
SecondParameter.DataValueField = "NameofDatabaseColumn"
SecondParameter.DataBind()
End Sub
我已尝试先更改SecondParameter_Label 文本,但仍然无法正常工作。我该怎么做?
【问题讨论】:
标签: asp.net dynamic drop-down-menu selectedindexchanged