How to bind gridview using Linq to SQL
By bryan tugade
We can easily bind gridview using linq to sql. Assuming that your using AdventureWorks as your database.
Imports System.Data.Linq
Imports Microsoft.VisualBasic
Partial Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Dim adventureContext = New adventureWorks()
Try
Dim xemployee = (From employee In adventureContext.Employees Select employee.Title)
GridView1.DataSource = xemployee
GridView1.DataBind()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
End Class
Here's the result...
That's it. Happy Coding.
Related FAQs
In C#, we can select and deselect checkbox in gridview in onPostback event of checkbox in gridview header.
We can hover on gridview row using javascript onmouseover event. We can also change the color in code behind.
This snippet shows how to connect to SQLExpress and execute stored procedure.
We can find checkbox inside gridview by using Findcontrol.
Here's a clever way to create CRUD function using adapter and dataset.
We can find checkbox inside gridview by using Findcontrol.
How to bind gridview using Linq to SQL (1505 Views)