How to refresh a parent grid?

R

Roy

Greetings all,

I have a nested datagrid setup. When one updates the child grid using
edit, it also updates a field in the parent grid (the parent grid
update is done using a simple select query inside the child grid's
update sub). All is well, *however* after the update occurs the parent
grid is still displaying the old data even though the update has
occured. I was under the assumption that when I did a .databind() on
the child grid, the parent grid automatically reloaded? Well, evidently
it doesn't. :-/ In order to see the right data in the parent grid, I
have to leave the page then come back.

What do I do to get the parent grid to display the current data after
updating the child grid? I've tried many differents ways of getting
access to the parent grid from within the child grid's update sub, but
all have met with failure. Help!
 
K

Ken Cox [Microsoft MVP]

Hi Roy,

Is it that you can't get a reference to the parent grid and therefore called
call its DataBind method?

Posting some code would help us work this out.

Ken
 
R

Roy

Exactly.

The nested datagrid is in the form of a user control .ascx page and I
cannot seem to reference the parent grid from within the user control.
It pops up an error when I try to do a parentgrid.databind() or execute
the parentgrid's bind_parentgrid() sub.

I'm uncertain what I could post short of posting the entire app... What
section, specifically, would you like to have a gander at?
 
D

Danny Sikora

Roy,

I think you are having a problem similar to mine (see "parent/child"
datagrids question posted today...

Here's a snippet of code from what I'm doing, this is from the User Control.
To access the parent grid (in my case called "myHGrid") you can create a new
dataGrid and set it equal to the parent datagrid. I did this just to get the
value of the selected index of the parent DataGrid.

Sorry it's in C#, but you should get the idea.:

DataGrid myDataGrid = new DataGrid();
myDataGrid = (DataGrid) this.Parent.FindControl("myHGrid");
int myIndex = 0;
try
{
myIndex = Convert.ToInt32(myDataGrid.DataKeys[myDataGrid.SelectedIndex]);
}
catch{}

-------------------------------------------------------------------------------

Now, for your first problem I think it's just a post back thing. When you
edit your child datagrid, you're posting back to the parent page. So it will
not rebind the data for your datagrid unless you tell it to. So in the
page_load function, make sure you call your function (sub) to bind the parent
datagrid even if the page is a post back.

Also,
If you don't mind would you check out the post I put up today....perhaps you
already tackled that problem?

Thanks,

-Danny
 

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

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,294
Latest member
LandonPigo

Latest Threads

Top