Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls

T

thegame

Filling One DataGrid Based on Selection from Another DataGrid - Both in
Separate User Controls


Hello, I have an interesting dilemma.

I have an ASPX page with two user controls (two ASCXs). Both ASCXs have
DataGrids on them. The first user control's DataGrid is populated from our
database on page load. The DataGrid also has a Select LinkButton.

What I need is for the selected row in the first DataGrid to be used as
input to another query that dynamically fills the second DataGrid. This
second DataGrid is in the second user control. I'm having trouble doing
this. Any suggestions????

In my first user control, I have the item command event for the first
DataGrid as such:

private void DataGrid1_ItemCommand(object source, DataGridCommandEventArgs
e)
{
if (e.CommandName == "SelectMasterReport")
{
// get the selected value needed using e.Item.Cells[3].Text
// code here to populate the second DataGrid?????
}
}

Thanks in advance for any help!
 
G

Guest

Ok, here is my explanation....

We have 3 parts: 1) .aspx 2). Main .ascx 3). sencondary .ascx

First thing to do (which you have done already) is load the main .ascx
(datagrid). I imagine that you are exposing the DataSource property of the
datagrid on the main .ascx control.

Next, you will have to create a bubble event within the main .ascx control
so that ItemCommand event of the datagrid will bubble up to the .aspx page.
Create properties of the data you need in order to fill the 2nd Datagrid

Now you have the event that fires in the .aspx page, capture the properties
that you set in the .ascx control and set the DataSource property of the
second .ascx control.

Seems like the only step you are missing is bubbling up the ItemCommand
event from the main .ascx control to the .aspx page......and creating and
grabbing the data from the main .ascx control and use it to set the
DataSource property of the second .ascx control.

Hope this helps !
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top