前台:
<tr>
<td style="padding-left: 10px;">
<asp:DropDownList ID="DropDownList1" runat="server" Width="140px" DataTextField="typeName"
DataValueField="typeid" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged1">
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="padding-left: 10px;">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Inline" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" Height="23px" Width="140px" AutoPostBack="True"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged1">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td style="padding-left: 10px;">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" Height="23px" Width="140px">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList2" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
后台:
private void bindfirst()
{
DataTable dt = typeinfo_BLL.GetList("t_typeid = 3").Tables[0];
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "typeName";
DropDownList1.DataValueField = "typeid";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("--请选择类别--", "-1"));
dt = null;
}
private void bindSecond(int id)
{
DataTable dt = typeinfo_BLL.GetList("t_typeid = " + id).Tables[0];
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "typeName";
DropDownList2.DataValueField = "typeid";
DropDownList2.DataBind();
DropDownList2.Items.Insert(0, new ListItem("--请选择类别--", "-1"));
dt = null;
}
private void bindThrid(int id)
{
DataTable dt = typeinfo_BLL.GetList("t_typeid = " + id).Tables[0];
DropDownList3.DataSource = dt;
DropDownList3.DataTextField = "typeName";
DropDownList3.DataValueField = "typeid";
DropDownList3.DataBind();
DropDownList3.Items.Insert(0, new ListItem("--请选择类别--", "-1"));
dt = null;
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
DataTable dt = typeinfo_BLL.GetList("t_typeid = " + DropDownList1.SelectedValue).Tables[0];
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "typeName";
DropDownList2.DataValueField = "typeid";
DropDownList2.DataBind();
bindSecond(Convert.ToInt32(DropDownList1.SelectedValue));
dt = null;
}
protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
{
DataTable dt = typeinfo_BLL.GetList("t_typeid = " + DropDownList2.SelectedValue).Tables[0];
DropDownList3.DataSource = dt;
DropDownList3.DataTextField = "typeName";
DropDownList3.DataValueField = "typeid";
DropDownList3.DataBind();
bindThrid(Convert.ToInt32(DropDownList2.SelectedValue));
dt = null;
}