How to fill Gridview using Entity Framework in asp.net ?Part #2



Hi
Here is some few steps to do this task

Note: I have tested this code with asp.net 3.5 sp1, In asp.net 4.0 also process is same.

Step1: Go to solution Explore, then right click then add new item like this

Step2: Click on next like this

Step3: Select the Exact database and click on next like this

Step4: Select your table name like this

Step5: Then you will get Model.edmx file like this

Step6:Take one gridview asp.net control in default page and write the code in code behind page like this

protected void Page_Load(object sender, EventArgs e)
{
fillGrid();
}

//This code is used for fetch data from database
protected void fillGrid()
{
using (TestModel.TestEntities TE = new TestModel.TestEntities())
{
var query = from m in TE.tblEmp
orderby m.Id descending
select m;
Gridview1.DataSource = query;
Gridview1.DataBind();
}
}

Advertisement

12 thoughts on “How to fill Gridview using Entity Framework in asp.net ?Part #2

  1. hitesh January 5, 2012 / 1:19 pm

    how to fill data in gridview by entity framework in asp.net

  2. hitesh January 5, 2012 / 1:22 pm

    how to fill data in gridview by entity framework in asp.net important problem please help me

  3. hitesh January 5, 2012 / 2:42 pm

    sir i have problem
    how to insert and save data in table iby entity framework in asp.net

    please tell me the solution

    thaks and regards
    Hitesh

  4. hitesh January 5, 2012 / 2:46 pm

    sir,
    and one think is most important fill data in gridview by your method and successfully implemented but please tell me solution if multiple tables so how to fill data in gridview on same page

    please help me

    thanks and regards
    Hitesh

    • Chandra Dev January 9, 2012 / 5:01 pm

      Hi
      Please give me some time. I will write artical on this topic.

      Regards
      Chandradev

  5. hitesh January 10, 2012 / 11:52 am

    thanks a lot sir
    you give me a response
    thanks sir

    thanks and regards hitesh

  6. phkhan November 2, 2012 / 9:26 am

    Hi,
    How can we insert the data available in gridview(newly added row/rows) to the database table.

  7. phkhan November 2, 2012 / 9:27 am

    phkhan :Hi,How can we insert the data available in gridview(newly added row/rows) to the database table. in c# project(windows forms project)

  8. Chandra Dev November 2, 2012 / 9:51 am

    Hi
    Like this you add data in database

    using (TestModel.TestEntities TE = new TestModel.TestEntities())
    {

    TestModel.tblEmp objEmp = new TestModel.tblEmp();
    objEmp.EmpName = txtEmpName.Text;
    objEmp.EmpSal = txtEmpSal.Text;
    TE.AddTotblEmp(objEmp);
    TE.SaveChanges();
    lblmsg.Text = “Data has been inserted sucessfully”;
    txtEmpName.Text = “”;
    txtEmpSal.Text = “”;
    }

    }

  9. venkateswarlu March 6, 2013 / 7:41 am

    thank u sir this is helpful for me

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.