Populate grid from selected row of another grid

I have JOBS which have many VERSIONS, which have many PACKAGES.  I'm building a utility where I can enter JOB NUMBER, which will populate a grid with all VERSIONs for the JOB.  I want to then click a VERSION description link, which will populate another grid with the PACKAGES.

So basically,
- Enter job#, click enter to fill Grid1 with VERSIONS. (Display VersionID, Version_Description)
- Click Grid1.Version_Description to fill Grid2 with PACKAGES (Display PackageID, Package_Description)

I can't seem to find a simple example of this.  Please advise.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Something like this should give you the idea.
<asp:GridView ID="GridOuter" runat="server" DataSourceID="SqlDSGridOuter" OnRowCommand="GridOuter_RowCommand">
				<asp:Button ID="Btn1" runat="server" Text="Fill Inner Grid"
				 CommandArgument='<%# Bind("ItemNumber") %>' />
				<asp:GridView ID="GridInner" runat="server" />
<asp:SqlDataSource ID="SqlDSGridOuter" runat="server"
 ConnectionString='<%$ ConnectionStrings:DevTesting %>'
 SelectCommand="SELECT * FROM ITEMS" />

Open in new window

protected void GridOuter_RowCommand(Object sender, GridViewCommandEventArgs e)
        //find the current row and use that to find the inner gridview
        GridViewRow gRow = (GridViewRow)(((Button)e.CommandSource).NamingContainer);
        GridView GridInner = (GridView)gRow.FindControl("GridInner");

        //get the button to utilize its commandarg later
        Button Btn1 = (Button)e.CommandSource;

        //Get data for inner/nested grid and bind to it
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DevTesting"].ToString());
        SqlCommand cmd = new SqlCommand("SELECT * FROM Items2 WHERE ItemID = @ItemId", conn);
        cmd.Parameters.Add(new SqlParameter("@ItemId", Convert.ToInt32(Btn1.CommandArgument)));
        using (conn)
            GridInner.DataSource = cmd.ExecuteReader();

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BTW. For such a specific requirement that you couldn't find a link to easily this was worth more than 250 pts.
JT_SIROAuthor Commented:
OK, sorry.  I added points to this post.

I think this solution will work, but the button clicks is not firing the GridOuter_RowCommand event.  It builds without errors.  The outer grid loads fine, but my break point is never hit in GridOuter_RowCommand when I click a button from within the outer grid.  Do I need to add an event in the button or something?  Thanks -
This is what calls establishes the event.

<asp:GridView ID="GridOuter" runat="server" DataSourceID="SqlDSGridOuter" OnRowCommand="GridOuter_RowCommand">

If you have a button somewhere in the gridview it should cause that event to fire:

<templatefield><itemtemplate><asp:button id="btn" runat="server" text="MyButton" /></itemtemplate></templatefield>


<asp:buttonfield buttontype="Button"
            headertext="Select Customer"

If you're syntax is correct then try to show me some code (the gridview and the rowcommand) and I'll have a look :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.