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 =
    (ObjectDataSource)(e.Item.FindControl("odsGridViewObjectDataSource"));

    try
    {

    odsodsGridViewObjectDataSource.SelectParameters["CostID"].DefaultValue
    = DataBinder.Eval(e.Item.DataItem, "CostID").ToString();

    }



    thank you a LOT
    H5N1, Apr 27, 2006
    #1
    1. Advertising

  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
    parent:


    protected override void OnPreRender(EventArgs e)
    {
    base.OnPreRender(e);

    if ((bool)ViewState["updatingRow"])
    {
    DataList1.DataBind();
    ViewState["updatingRow"] = false;

    }

    }


    cheers
    H5N1, Apr 29, 2006
    #2
    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. priyank
    Replies:
    0
    Views:
    321
    priyank
    Jan 6, 2004
  2. =?Utf-8?B?UmljaGFyZCBTdGVlbGU=?=

    How do rebind datalist when record is updated

    =?Utf-8?B?UmljaGFyZCBTdGVlbGU=?=, Jan 18, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    669
    Bruce Barker
    Jan 18, 2006
  3. H5N1
    Replies:
    0
    Views:
    2,700
  4. Fernando Rodriguez
    Replies:
    2
    Views:
    279
    Alexander Schmolck
    Nov 21, 2003
  5. Priyank

    Datalist does not update new html code after rebind

    Priyank, Jan 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    170
    Priyank
    Jan 6, 2004
Loading...

Share This Page