How to Bind Gridview Data Control using LINQ - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial

How to Bind Gridview Data Control using LINQ

Introduction: in this post I will explain how we can bind Gridview data control using LINQ.
Bind Gridview

I have created a table name APPLICANT_DETAIL. Here APPLICANT_ID is primary key.

Now go to Visual studio>File>New website> empty web site. Now go to Solution Explorer, right click on website>Add new item>Linq to Sql classes.
Bind Gridview

Now you see App_code folder will added to application and a dataclasses added with extension .dbml in App_code folder.

Now check the web.config file of application. It self create a connectionstring for database.
Bind Gridview

Now connect the database to server explorer. After that drag and drop the table from database.
Add a web form to application. Go to Solution Explorer, right click on website>Add new item> Web from and drag and drop Gridview Data control from Toolbox.
<asp:GridView ID="grdapplicantdetail" runat="server" AutoGenerateColumns="False" DataKeyNames="APPLICANT_ID">
                <asp:TemplateField HeaderText="CANDIADTE NAME">
                        <asp:Label ID="lblname" runat="server" Text='<%# Eval("APPLICANT_NAME") %>'></asp:Label>
                <asp:TemplateField HeaderText="CANDIDATE QUALIFICATION">
                        <asp:Label ID="ldlqualification" runat="server" Text='<%# Eval("APPLICANT_QUALIFICATION") %>'></asp:Label>
                <asp:TemplateField HeaderText="CANDIDATE PROFILE FOR JOB">
                        <asp:Label ID="lblprofile" runat="server" Text='<%# Eval("JOB_PROFILE") %>'></asp:Label>
                            <EmptyDataTemplate>No Data Available</EmptyDataTemplate>

After that go to .aspx.cs page.
DataClassesDataContext db = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)
    private void Bindgrid()
            var bind = from g in db.APPLICANT_DETAILs
                       select g;
            grdapplicantdetail.DataSource = bind;
        catch (Exception ex)

Go to .aspc.vb page.

Dim db As New DataClassesDataContext()
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        End If
    End Sub
    Private Sub Bindgrid()
            Dim bind = From g In db.APPLICANT_DETAILs
            grdapplicantdetail.DataSource = bind
        Catch ex As Exception
        End Try
    End Sub

Now debug the project and check the result.

Related Articles on LINQ:

Ø  What is LINQ? Its advantage, disadvantage and types

Howto Bind Dropdownlist in using LINQ?

Is it helpful?

If yes post your comment to admire my work. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+