Cannot rebind GridView nested in DataList

Discussion in 'ASP .Net' started by H5N1, Apr 27, 2006.

  1. H5N1

    H5N1 Guest

    Hello everybody

    I'm stuck for a long time with the following problem, so I will be
    really gratefull if you could help me a bit:

    I have a GridView nested in DataList (it's located in DataList's Item
    Template together with it's data source).

    In OnRowUpdated event of child GridView I'm calling DataBind() on
    parent DataList, since I want it to reflect the changes (maybe there's
    better way to refresh the datalist?)

    I get the following error:

    "The ObjectDataSource control 'odsGridViewObjectDataSource' does not
    have a naming container. Ensure that the control is added to the page
    before calling DataBind. "

    It happens when during rebinding of datalist, rebinding of child
    gridview is called ( on ItemDataBound event), more precisly when
    FindControl is called:

    protected void DataList1_ItemDataBound(Object sender,
    System.Web.UI.WebControls.DataListItemEventArgs e) {
    odsGridViewObjectDataSource =


    = DataBinder.Eval(e.Item.DataItem, "CostID").ToString();


    thank you a LOT
    H5N1, Apr 27, 2006
    1. Advertisements

  2. H5N1

    H5N1 Guest

    I've solved the problem.

    I guess calling DataBind() on parent control on OnRowUpdated() was to
    early, so what I did was to set

    ViewState["updatingRow"] = true;

    in OnROwUpdated

    and start DataBind in the latest phase of page life cycle -
    onPreRender, when nested control was already bound programmatically to

    protected override void OnPreRender(EventArgs e)

    if ((bool)ViewState["updatingRow"])
    ViewState["updatingRow"] = false;



    H5N1, Apr 29, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.