views:

45

answers:

2

I am playing about just now trying to teach myself a little bit about the entity framework.

I have a Gridview data bound to a Entity Date Source using the Entity Framework. If I select certain items in that list I then wish to redirect another page and populate another gridview with just the items selected (but with more detail, different includes/navigation properties)

This is probably the most simple thing but I have spent 2 hours banging my head on the wall trying to get this to work.

Essentially I have a continue button which when clicked should identify all the UIDs (a column in the gridview) of the rows and allow me to subset to just these rows and pass them to another page to be rebound to another datagrid

Any ideas???

+1  A: 

Well, the big picture is that you should get those IDs, pass them to the other page, and then use a query with Contains; see this question for an idea of how to use it:
http://stackoverflow.com/questions/3870666/how-search-linq-with-many-parametrs-in-one-column

Dan Dumitru
+1  A: 

Assuming you haven't used DataKeys in your GridView, this would be my approach.

Page 1

    protected void Button1_Click(object sender, EventArgs e)
    {
        var checkedItems = new List<int>();

        foreach (GridViewRow row in GridView1.Rows)
        {
            var checkbox = (CheckBox)row.FindControl("CheckBox1");

            if (checkbox.Checked)
            {
                checkedItems.Add(int.Parse(row.Cells[1].Text));
            }
        }

        Session["checkedItems"] = checkedItems;

        Response.Redirect("Page2.aspx");
    }

Page 2

    protected void Page_Load(object sender, EventArgs e)
    {
        var checkedItems = (List<int>)Session["checkedItems"];
        Session["checkedItems"] = null;

        foreach (var checkedItem in checkedItems)
        {
            Response.Write(checkedItem);
        }
    }

Using the IDs in the checkedItems List you can now query those from you DB and finally assign the Result to your GridView on the second page.

Instead of using Session you could pass the IDs via QueryString.

Dave