Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Cannot rebind GridView nested in DataList

Reply
Thread Tools

Cannot rebind GridView nested in DataList

 
 
H5N1
Guest
Posts: n/a
 
      04-27-2006
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"));

try
{

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

}



thank you a LOT

 
Reply With Quote
 
 
 
 
H5N1
Guest
Posts: n/a
 
      04-29-2006
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView nested in DataList - refreshing corresponding DataList row after updating GridView row H5N1 ASP .Net 0 04-26-2006 11:41 PM
How do rebind datalist when record is updated =?Utf-8?B?UmljaGFyZCBTdGVlbGU=?= ASP .Net 1 01-18-2006 05:16 PM
Datalist does not update new html code after rebind priyank ASP .Net 0 01-06-2004 03:14 PM
Datalist does not update new html code after rebind Priyank ASP .Net Web Controls 0 01-06-2004 03:13 PM
Trouble with nested scopes when trying to rebind a variable Fernando Rodriguez Python 2 11-21-2003 03:40 PM



Advertisments