Search code examples
c#asp.netentity-frameworkentitydatasource

Populating GridView using EntityDataSource and QueryString


I am new to EntityFrameWork so bear with me here. I have a webpage (page1.apsx) n page2.aspx.

Page1.aspx is showing gridview of following items:

EntityID
Name
Description

Whenever user is selecting some Entity then I am passing this EntityID to Page2.aspx. In Page2 I am having EntityDataSource and GridView. Also, the value needs to be populated is from different tables in this page. How you deal with this in EntityDataSource and populating it in GridView?

Thank you!


Solution

  • let's consider the Query String as http://www.xyz.com/Page1.aspx?EntityID=1

    In the Page2

     protected void Page_Load(object sender, EventArgs e)
            {
                DataClasses1DataContext db = new DataClasses1DataContext();
                var te = from p in db.table
                         where p.entityid=Request.Querystring["EntityID"]
                         select p;
                GridView1.DataSource = te;
                GridView1.DataBind();
    
            }