ListControl loses its items

Discussion in 'ASP .Net' started by TumurS, May 24, 2007.

  1. TumurS

    TumurS Guest

    My DataGrid control has footer and this footer contains a custom web user
    control. The control included via footer template at the desing time. I
    don't create it manually.
    The user control contains a DropDownList that populates data on its own Load
    event as :

    if (!IsPostBack)
    {
    ...
    rdr = cmd.ExecuteReader();
    MyLst.DataValueField = "...";
    MyLst.DataKeyField = "...";
    MyLst.DataSource = rdr;
    MyLst.DataBind();
    rdr.Close();
    conn.Close();
    }

    As you see, it populates items only one time.
    ViewState at all levels (page, control, item and etc) is enabled.
    After postbacks the the list does not lose its items if the datagrid does
    not
    do re-binding. But if my some commands force re-binding of the datagrid.
    And after re-binding, the list becomes empty. What am I doing wrong?
    Any help?
    TumurS, May 24, 2007
    #1
    1. Advertising

  2. Databinding of the grid results in databinding of the footer. Probably, it
    in turn causes databinding of all controls included in the footer and
    MyLst.DataBind() gets called.The DataSource property doesn't get restored in
    postback and that's why the ddl becomes empty after databinding.

    Try populating the ddl in the datagrid's ItemDataBound event when it is
    raised for the footer item.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "TumurS" <> wrote in message
    news:%23RaKq$...
    > My DataGrid control has footer and this footer contains a custom web user
    > control. The control included via footer template at the desing time. I
    > don't create it manually.
    > The user control contains a DropDownList that populates data on its own
    > Load
    > event as :
    >
    > if (!IsPostBack)
    > {
    > ...
    > rdr = cmd.ExecuteReader();
    > MyLst.DataValueField = "...";
    > MyLst.DataKeyField = "...";
    > MyLst.DataSource = rdr;
    > MyLst.DataBind();
    > rdr.Close();
    > conn.Close();
    > }
    >
    > As you see, it populates items only one time.
    > ViewState at all levels (page, control, item and etc) is enabled.
    > After postbacks the the list does not lose its items if the datagrid does
    > not
    > do re-binding. But if my some commands force re-binding of the datagrid.
    > And after re-binding, the list becomes empty. What am I doing wrong?
    > Any help?
    >
    >
    >
    Eliyahu Goldin, May 24, 2007
    #2
    1. Advertising

  3. TumurS

    TumurS Guest

    Yes, thank you!
    I expected something similar.
    So, is there any way to avoid rebinding?
    I.e. prevent the list from clearing?
    The list content is constant and I don't want
    to access a db every time when the datagrid
    is binded. Of course, I can store its items
    in page's ViewState and load back on the binding event.
    But may be asp.net has simpler builtin method
    to aviod rebinding?



    "Eliyahu Goldin" <> wrote in
    message news:...
    > Databinding of the grid results in databinding of the footer. Probably, it
    > in turn causes databinding of all controls included in the footer and
    > MyLst.DataBind() gets called.The DataSource property doesn't get restored
    > in postback and that's why the ddl becomes empty after databinding.
    >
    > Try populating the ddl in the datagrid's ItemDataBound event when it is
    > raised for the footer item.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "TumurS" <> wrote in message
    > news:%23RaKq$...
    >> My DataGrid control has footer and this footer contains a custom web user
    >> control. The control included via footer template at the desing time. I
    >> don't create it manually.
    >> The user control contains a DropDownList that populates data on its own
    >> Load
    >> event as :
    >>
    >> if (!IsPostBack)
    >> {
    >> ...
    >> rdr = cmd.ExecuteReader();
    >> MyLst.DataValueField = "...";
    >> MyLst.DataKeyField = "...";
    >> MyLst.DataSource = rdr;
    >> MyLst.DataBind();
    >> rdr.Close();
    >> conn.Close();
    >> }
    >>
    >> As you see, it populates items only one time.
    >> ViewState at all levels (page, control, item and etc) is enabled.
    >> After postbacks the the list does not lose its items if the datagrid does
    >> not
    >> do re-binding. But if my some commands force re-binding of the datagrid.
    >> And after re-binding, the list becomes empty. What am I doing wrong?
    >> Any help?
    >>
    >>
    >>

    >
    >
    TumurS, May 24, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce W.1
    Replies:
    2
    Views:
    1,332
    \(Laurent Jordi\)
    Mar 7, 2004
  2. Tumurbaatar S.

    ViewState error and DataGrid loses its content

    Tumurbaatar S., Jan 25, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    419
    Tumurbaatar S.
    Jan 25, 2006
  3. thunk
    Replies:
    1
    Views:
    287
    thunk
    Mar 30, 2010
  4. thunk
    Replies:
    0
    Views:
    445
    thunk
    Apr 1, 2010
  5. thunk
    Replies:
    14
    Views:
    589
    thunk
    Apr 3, 2010
Loading...

Share This Page