Using LinqDataSource control in ASP.net:
In this article I'm trying to explain how to work with LinqDataSource control for displaying database data to our DataControls. During this process we can able to learn how to configure LinqDataSource control and how to connect with DataControl. This is very simple to communicate with our Database.
Follow below steps to configure LinqDataSource control in our Application.
Create a WebApplication by right click on the solution and choose Webform and give a name for that as LinqDataSource.aspx
Right click on project and choose Add New Item then a new window will appear then choose Linq To Sql Classes.
When you click Ok button then one window will appear for confirmation message purpose.
Click yes, to create Linq classes under App_code folder in a project.
After creating Linq classes under App_code folder then create connection for that by right clicking the server explorer then right click on the Data Connections then choose Add connection option for adding connection to the project.
A new popup window will appear for creating new connection string purpose give a server name and choose Database name.
Click TestConnection button if connection created successfully then click on Ok button.
Now, based on your database selection what are the tables are listed out all are presented under Server Explorer DataBase name and expand tables you can able to find the list of tables under that particular database.
Now, simply drag & drop the table to the design surface of DataClasses.dbml file.
Go to application page design mode and simply drag and drop LinqDataSource control available under Data controls tab.
A new window will appear for configuring Linq DataSource control.
Click on Next button then its redirect to Configure Data section window then choose columns names by default its target to all columns, then click on Finish button.
Now, just drag and drop one Gridview control in design page and select LinqDataSource as a Choose Data Source list out in dropdown.
Choose LinqDataSource1 datasource, after that observe the Gridview design.
Then observe the Gridview source code part how it's became changed.
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
Select="new (Emp_Name, Emp_job, Emp_Dep)" TableName="tblEmployees">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
<asp:BoundField DataField="Emp_Name" HeaderText="Emp_Name" ReadOnly="True" SortExpression="Emp_Name" />
<asp:BoundField DataField="Emp_job" HeaderText="Emp_job" ReadOnly="True" SortExpression="Emp_job" />
<asp:BoundField DataField="Emp_Dep" HeaderText="Emp_Dep" ReadOnly="True" SortExpression="Emp_Dep" />
After complete this process just execute the code and see the output in output window just click on F5 button on key board.
I hope this article will help you those who are looking for the same and those who are new to implement LinqDataSource control in your applications.
This is Naveen, I completed my MCA and I have around 3 years of experience in ASP.net while implement Web Applications. For past 3 years I learn no.of Technologies while implement my applications apart from that I try to learn new technologies and I try to implement that while implement my project.
thank you naveen its helpful for us.