469,613 Members | 1,354 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

Cannot rebind GridView nested in DataList

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("odsGridView ObjectDataSource"));


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


thank you a LOT

Apr 27 '06 #1
1 3250
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;



Apr 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Nalaka | last post: by
1 post views Thread by staeri | last post: by
reply views Thread by ammar_fake | last post: by
2 posts views Thread by needin4mation | last post: by
7 posts views Thread by =?Utf-8?B?cGF0cmlja2RyZA==?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.