0

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!

RG-3
  • 6,088
  • 19
  • 69
  • 125

2 Answers2

3

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();

        }
Nirmal
  • 1,223
  • 18
  • 32
  • @Nirmal: Where this DataClasses1DataContext is coming from? – RG-3 Mar 23 '11 at 13:48
  • DataClasses1DataContext is the DataContext Class. It get automatically generated when we have added a LINQ to SQL. I hope you are using LINQ to SQL. – Nirmal Mar 23 '11 at 14:04
  • I added a DBML file in my solution. Name is: MyLinqToSql.dbml – RG-3 Mar 23 '11 at 14:16
  • Then you can try with MyLinqToSQLDataContext instead of DataClasses1DataContext – Nirmal Mar 23 '11 at 14:17
  • And I also mapped the tables and their association. Now I am in the Page2.aspx – RG-3 Mar 23 '11 at 14:17
  • @Nirmal: I need to pull from two tables (User and Entity). What should be the LINQ statement? – RG-3 Mar 23 '11 at 14:24
  • It might be, var te = from p in db.Users JOIN e in db.Entity on p.UserID=e.EntityID where p.entityid=Request.Querystring["EntityID"] select new { p.firstname, e.description } ; – Nirmal Mar 23 '11 at 14:30
  • You can refer this if you need some more LINQ syntax. http://www.c-sharpcorner.com/UploadFile/pranayamr/5659/ – Nirmal Mar 23 '11 at 14:32
  • Sorry one mistake, the query might be, var te = from p in db.Users JOIN e in db.Entity on p.UserID equals e.EntityID where e.entityid=Request.Querystring["EntityID"] select new { p.firstname, e.description } ; Instead of "=" try "equals" – Nirmal Mar 23 '11 at 14:37
  • Yea, Nirmal thank you. I got the linq statement but it is showing me an error. Check my current answer. – RG-3 Mar 23 '11 at 15:30
0

Try Using this.

OISLinqtoSQLDataContext db = new OISLinqtoSQLDataContext();
        var tr = from r in db.Users
                 join s in db.Entities on r.UserID equals s.ID
                 where s.ID = Convert.ToInt32(Request.QueryString["EntityID"])
                 select new
                 {
                     //To Show Items in GridView!
                 };

    GridView1.DataSource = tr;
    GridView1.DataBind();
Nirmal
  • 1,223
  • 18
  • 32