Can NOt AutoPostBack for two DDL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • huobazi

    Can NOt AutoPostBack for two DDL

    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_S electedIndexCha nged" so the second DDL SmallClassList have no
    items
    *************** **********
    some ascx code:

    "><asp:dropdown list ID="BigClassLis t" Width="100" Height="18"
    AutoPostBack="T rue" runat="server"
    OnSelectedIndex Changed="BigCla ssList_Selected IndexChanged"></asp:dropdownlis
    t> &nbsp;&nbsp; <asp:dropdownli st ID="SmallClassL ist" Width="100"
    runat="server"> </asp:dropdownlis t>
    *************** **********
    some ascx's codebehind codes


    public void Page_Load(Objec t sender,EventArg s e)

    {

    if(!IsPostBack)

    {

    BigClassDropDow nListInit();

    SmallClassDropD ownListInit();

    }

    }

    public void BigClassDropDow nListInit()

    {

    Conn.Open();

    OleDbCommand commBigClass=ne w OleDbCommand("s elect
    BigClassName,ID from RootClass order by ID",Conn);

    OleDbDataReader MyReaderBigClas s1=commBigClass .ExecuteReader( );

    BigClassList.Da taSource=MyRead erBigClass1;

    BigClassList.Da taTextField="Bi gClassName";

    BigClassList.Da taValueField="I D";

    BigClassList.Da taBind();

    BigClassList.Se lectedIndex = 0;

    MyReaderBigClas s1.Close();

    Conn.Close();

    }

    public void BigClassList_Se lectedIndexChan ged(Object sender,EventArg s e)

    {

    SmallClassDropD ownListInit();

    }

    public void SmallClassDropD ownListInit()

    {

    Conn.Open();

    string strCom="select TypeName,ID from Type ";

    strCom+=" Where BigClassName ='"+BigClassLis t.SelectedItem. Text+"' ";

    strCom+=" order by ID";

    OleDbCommand commSmallClass= new OleDbCommand(st rCom,Conn);

    OleDbDataReader
    MyReaderSmallCl ass1=commSmallC lass.ExecuteRea der();

    SmallClassList. DataSource=MyRe aderSmallClass1 ;

    SmallClassList. DataTextField=" TypeName";

    SmallClassList. DataValueField= "ID";

    SmallClassList. DataBind();

    SmallClassList. SelectedIndex = 0;

    MyReaderSmallCl ass1.Close();

    Conn.Close();

    }


  • huobazi

    #2
    Re: Can NOt AutoPostBack for two DDL

    a uscontrol test.ascx have a dropdownlist web control the dropdownlist's
    AutoPostBack property is set "true"
    but when i use Loadcontrol("te st.ascx") in a aspx fiel's Page_Load event the
    dropdownlist which in the ascx can not run good it can not autopostback and
    can not call the OnselectedChang e event. help me pls~~


    "mike C." <mike@mike.mike > дÈëÏûÏ¢ÐÂÎÅ
    :uWHN7FMQDHA.24 60@TK2MSFTNGP10 .phx.gbl...[color=blue]
    > Why don't you put a break point at BigClassList_Se lectedIndexChan ged() to
    > see if program goes there.
    >
    >
    > "huobazi" <huobazi@Aspxbo y.com> wrote in message
    > news:O$vFMvLQDH A.3880@tk2msftn gp13.phx.gbl...[color=green]
    > > 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[/color]
    > a.ascx[color=green]
    > > in my aspx,
    > > but the DDL BigClassList can not Post Back and Can not do the[/color][/color]
    event[color=blue][color=green]
    > > "BigClassList_S electedIndexCha nged" so the second DDL SmallClassList[/color][/color]
    have[color=blue]
    > no[color=green]
    > > items
    > > *************** **********
    > > some ascx code:
    > >
    > > "><asp:dropdown list ID="BigClassLis t" Width="100" Height="18"
    > > AutoPostBack="T rue" runat="server"
    > >[/color]
    >[/color]
    OnSelectedIndex Changed="BigCla ssList_Selected IndexChanged"></asp:dropdownlis[color=blue][color=green]
    > > t> &nbsp;&nbsp; <asp:dropdownli st ID="SmallClassL ist" Width="100"
    > > runat="server"> </asp:dropdownlis t>
    > > *************** **********
    > > some ascx's codebehind codes
    > >
    > >
    > > public void Page_Load(Objec t sender,EventArg s e)
    > >
    > > {
    > >
    > > if(!IsPostBack)
    > >
    > > {
    > >
    > > BigClassDropDow nListInit();
    > >
    > > SmallClassDropD ownListInit();
    > >
    > > }
    > >
    > > }
    > >
    > > public void BigClassDropDow nListInit()
    > >
    > > {
    > >
    > > Conn.Open();
    > >
    > > OleDbCommand commBigClass=ne w OleDbCommand("s elect
    > > BigClassName,ID from RootClass order by ID",Conn);
    > >
    > > OleDbDataReader MyReaderBigClas s1=commBigClass .ExecuteReader( );
    > >
    > > BigClassList.Da taSource=MyRead erBigClass1;
    > >
    > > BigClassList.Da taTextField="Bi gClassName";
    > >
    > > BigClassList.Da taValueField="I D";
    > >
    > > BigClassList.Da taBind();
    > >
    > > BigClassList.Se lectedIndex = 0;
    > >
    > > MyReaderBigClas s1.Close();
    > >
    > > Conn.Close();
    > >
    > > }
    > >
    > > public void BigClassList_Se lectedIndexChan ged(Object sender,EventArg s e)
    > >
    > > {
    > >
    > > SmallClassDropD ownListInit();
    > >
    > > }
    > >
    > > public void SmallClassDropD ownListInit()
    > >
    > > {
    > >
    > > Conn.Open();
    > >
    > > string strCom="select TypeName,ID from Type ";
    > >
    > > strCom+=" Where BigClassName ='"+BigClassLis t.SelectedItem. Text+"' ";
    > >
    > > strCom+=" order by ID";
    > >
    > > OleDbCommand commSmallClass= new OleDbCommand(st rCom,Conn);
    > >
    > > OleDbDataReader
    > > MyReaderSmallCl ass1=commSmallC lass.ExecuteRea der();
    > >
    > > SmallClassList. DataSource=MyRe aderSmallClass1 ;
    > >
    > > SmallClassList. DataTextField=" TypeName";
    > >
    > > SmallClassList. DataValueField= "ID";
    > >
    > > SmallClassList. DataBind();
    > >
    > > SmallClassList. SelectedIndex = 0;
    > >
    > > MyReaderSmallCl ass1.Close();
    > >
    > > Conn.Close();
    > >
    > > }
    > >
    > >[/color]
    >
    >[/color]


    Comment

    Working...