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

Advertisements

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

  1. hitesh Says:

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

  2. hitesh Says:

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

  3. hitesh Says:

    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 Says:

    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 Says:

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

      Regards
      Chandradev

  5. hitesh Says:

    thanks a lot sir
    you give me a response
    thanks sir

    thanks and regards hitesh

  6. phkhan Says:

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

  7. phkhan Says:

    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 Says:

    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 Says:

    thank u sir this is helpful for me

    • Chandra Dev Says:

      You are welcome.


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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: