H
huobazi
Can NOt AutoPostBack for two DDL
Posted: 07-03-2003 01:35 AM
I have a usercontrol a.ascx ,put two DDL on the ascx.
in an aspx's codebehind Page_Load i use LoadControl to Load the a.ascx
in my aspx,
but the DDL BigClassList can not Post Back and Can not do the event
"BigClassList_SelectedIndexChanged" so the second DDL SmallClassList have no
items
*************************
some ascx code:
"><asp:dropdownlist ID="BigClassList" Width="100" Height="18"
AutoPostBack="True" runat="server"
OnSelectedIndexChanged="BigClassList_SelectedIndexChanged"></asp:dropdownlis
t> <asp:dropdownlist ID="SmallClassList" Width="100"
runat="server"></asp:dropdownlist>
*************************
some ascx's codebehind codes
public void Page_Load(Object sender,EventArgs e)
{
if(!IsPostBack)
{
BigClassDropDownListInit();
SmallClassDropDownListInit();
}
}
public void BigClassDropDownListInit()
{
Conn.Open();
OleDbCommand commBigClass=new OleDbCommand("select
BigClassName,ID from RootClass order by ID",Conn);
OleDbDataReader MyReaderBigClass1=commBigClass.ExecuteReader();
BigClassList.DataSource=MyReaderBigClass1;
BigClassList.DataTextField="BigClassName";
BigClassList.DataValueField="ID";
BigClassList.DataBind();
BigClassList.SelectedIndex = 0;
MyReaderBigClass1.Close();
Conn.Close();
}
public void BigClassList_SelectedIndexChanged(Object sender,EventArgs e)
{
SmallClassDropDownListInit();
}
public void SmallClassDropDownListInit()
{
Conn.Open();
string strCom="select TypeName,ID from Type ";
strCom+=" Where BigClassName ='"+BigClassList.SelectedItem.Text+"' ";
strCom+=" order by ID";
OleDbCommand commSmallClass=new OleDbCommand(strCom,Conn);
OleDbDataReader
MyReaderSmallClass1=commSmallClass.ExecuteReader();
SmallClassList.DataSource=MyReaderSmallClass1;
SmallClassList.DataTextField="TypeName";
SmallClassList.DataValueField="ID";
SmallClassList.DataBind();
SmallClassList.SelectedIndex = 0;
MyReaderSmallClass1.Close();
Conn.Close();
}
Posted: 07-03-2003 01:35 AM
I have a usercontrol a.ascx ,put two DDL on the ascx.
in an aspx's codebehind Page_Load i use LoadControl to Load the a.ascx
in my aspx,
but the DDL BigClassList can not Post Back and Can not do the event
"BigClassList_SelectedIndexChanged" so the second DDL SmallClassList have no
items
*************************
some ascx code:
"><asp:dropdownlist ID="BigClassList" Width="100" Height="18"
AutoPostBack="True" runat="server"
OnSelectedIndexChanged="BigClassList_SelectedIndexChanged"></asp:dropdownlis
t> <asp:dropdownlist ID="SmallClassList" Width="100"
runat="server"></asp:dropdownlist>
*************************
some ascx's codebehind codes
public void Page_Load(Object sender,EventArgs e)
{
if(!IsPostBack)
{
BigClassDropDownListInit();
SmallClassDropDownListInit();
}
}
public void BigClassDropDownListInit()
{
Conn.Open();
OleDbCommand commBigClass=new OleDbCommand("select
BigClassName,ID from RootClass order by ID",Conn);
OleDbDataReader MyReaderBigClass1=commBigClass.ExecuteReader();
BigClassList.DataSource=MyReaderBigClass1;
BigClassList.DataTextField="BigClassName";
BigClassList.DataValueField="ID";
BigClassList.DataBind();
BigClassList.SelectedIndex = 0;
MyReaderBigClass1.Close();
Conn.Close();
}
public void BigClassList_SelectedIndexChanged(Object sender,EventArgs e)
{
SmallClassDropDownListInit();
}
public void SmallClassDropDownListInit()
{
Conn.Open();
string strCom="select TypeName,ID from Type ";
strCom+=" Where BigClassName ='"+BigClassList.SelectedItem.Text+"' ";
strCom+=" order by ID";
OleDbCommand commSmallClass=new OleDbCommand(strCom,Conn);
OleDbDataReader
MyReaderSmallClass1=commSmallClass.ExecuteReader();
SmallClassList.DataSource=MyReaderSmallClass1;
SmallClassList.DataTextField="TypeName";
SmallClassList.DataValueField="ID";
SmallClassList.DataBind();
SmallClassList.SelectedIndex = 0;
MyReaderSmallClass1.Close();
Conn.Close();
}