<table><tr>
<td>
Type:
</td>
<td>
<asp:DropDownList ID="ddltype" runat="server" OnSelectedIndexChanged="ddltype_SelectedIndexChanged">
<asp:ListItem Value="0">---select---</asp:ListItem>
<asp:ListItem Text="Setter" Value="1">
</asp:ListItem>
<asp:ListItem Text="Getter" Value="2"></asp:ListItem>
</asp:DropDownList>
</td>
<td>
Name:
</td>
<td>
<asp:DropDownList ID="ddlname" runat="server">
</asp:DropDownList>
</td>
</tr> </table>
如果用户在第一个下拉列表中选择setter
或getter
,我想在第二个下拉列表中填写相关名称。如何在c#页面中编写此要求的代码。请帮助我。
答案 0 :(得分:1)
public void NamesToDropdownList()
{
objhatcheryPL.type = ddltype.SelectedItem.Text;
DataTable dtname = new DataTable();
dtname = objhatcheryBAL.dtnames(objhatcheryPL);
ddlname.DataTextField = "Name";
ddlname.DataValueField = "Name";
ddlname.DataSource = dtname;
ddlname.DataBind();
ddlname.Items.Add(new ListItem("--select--", "0"));
ddlname.SelectedIndex = ddlname.Items.Count - 1;
}
protected void ddltype_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddltype.SelectedItem.Text != "--Select--")
{
NamesToDropdownList();
}
}
用这个我的代码完美运行....