Cannot rebind GridView nested in DataList

H

H5N1

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
 
H

H5N1

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top