AutoPostBack="True" DropDownList选不到值 AutoPostBack="false" 就可以取到选多几次,DropDownList连值都不绑定了,下拉变为空
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="lstType" style="width:98%" AutoPostBack="True" runat="server" TabIndex="1" onselectedindexchanged="lstType_SelectedIndexChanged"> </asp:DropDownList><asp:DropDownList ID="lstProductType" style="width:98%" TabIndex="2" runat="server"> </asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>if ( !IsPostBack)
{
Getlist("select id,name from M_MenuHead ", lstType, "name", "id");
} private void Getlist(string strSQL, DropDownList DList, string textt, string valuee)
{
DataSet dst = new DataSet();
dst = SqlHelper.ExecuteDataset(SqlHelper.Conn, CommandType.Text, strSQL);
DList.DataSource = dst;
DList.DataTextField = textt;
DList.DataValueField = valuee;
DList.DataBind();
DList.Items.Insert(0, new ListItem("== select ==", ""));
}
{
if (lstType.SelectedValue != "")
{
Getlist("select product_type,name from M_MenuChildren where pid=" + lstType.SelectedValue + "", lstType, "name", "product_type"); }
}
你的sql语句select id,name from M_MenuHead
只读取了id和name
{
DataSet dst = new DataSet();
dst = SqlHelper.ExecuteDataset(SqlHelper.Conn, CommandType.Text, strSQL);
DList.DataSource = dst.Tables[0];
DList.DataTextField = textt;
DList.DataValueField = valuee;
DList.DataBind();
DList.Items.Insert(0, new ListItem("== select ==", ""));
}