How can I select items in a datagrid to populate a second datagrid.

E

Eric

I currently have a datagrid that looks like the following.

Sales Table
Date Dogs Cats Fish
5/1/2004 4 4 2
5/2/2004 3 3 1
5/4/2004 2 4 1
5/5/2004 1 2 23

I want to be able to click on each number and have a seperate datagrid
pull up the individual sales records. For example, on 5/1/2004, I want
to be able to click on the 4 cats hand have the second datagrid on the
page pull the database details for those four records as shown below.

5/1/2004 - Cats
Sale QTY Customer
Cat 1 4456
Cat 2 2345
Cat 1 1994

I know how to build an handler to select rows in a datagrid but I want
to select individual items within the rows since my sales for dogs,
cats and fish are all in the same row.

Currently, as a workaround I'm using a template colum to fill the
cells as hyperlinks that just refresh the page while passing in the
variables via querystring but it's quite cumbersome to maintain page
state with this solution.

Any ideas on a clean way to do this?

Thanks

Eric
 
E

Eric

Thomas,
Thanks for the links but both these exampls allow data expansion via
selecting a row. I want to be able to select different items within a
row, each of which would yield a different datagrid. I need some sort
of handler to detect which cell in the datagrid was selected.

Thanks

Eric
 
T

Thomas Dodds

i very ugly way to do that would be to use buttoncolumns (linkbuttons) and
trap individual datgrid itemcommands ...
 
Q

q

Two otions are available.
First use the Reapter control to create and populate
an html table?
Each cell looks like this when sent to the browser
<td><a href="thispage.aspx?cellrow=ID>TheData</a></td>

Second use the DataGrid. In your .aspx
Use the DataGrid ItemDataBound event.
ItemDataBound(
object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
DataGridItem dgi = e.Item;

// hyperlink the data in cell 0.
strData = dgi.Cells[0].Text;
hlink = new System.Web.UI.WebControls.HyperLink();
hlink.NavigateUrl = strTheDatasURL;
hlink.Text = strData;
dgi.Cells[0].Controls.AddAt(0, hlink);
}

In either case use thispage.aspx?cellrow=ID as the URL
Let cellrow=ID thell your aspx code which detail is
to be diplayed.

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,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top