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.
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.Step-1:
Create a WebApplication by right click on the solution and choose Webform and give a name for that as LinqDataSource.aspxStep-2:
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.Step-3:
Click yes, to create Linq classes under App_code folder in a project.Step-4:
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.Step-5:
A new popup window will appear for creating new connection string purpose give a server name and choose Database name.Step-6:
Click TestConnection button if connection created successfully then click on Ok button.Step-7:
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.Step-8:
Now, simply drag & drop the table to the design surface of DataClasses.dbml file.Step-9:
Go to application page design mode and simply drag and drop LinqDataSource control available under Data controls tab.Step-10:
A new window will appear for configuring Linq DataSource control.Step-11:
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.Step-12:
Now, just drag and drop one Gridview control in design page and select LinqDataSource as a Choose Data Source list out in dropdown.Step-13:
Choose LinqDataSource1 datasource, after that observe the Gridview design.Step-14:
Then observe the Gridview source code part how it's became changed.<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="DataClassesDataContext" EntityTypeName=""
Select="new (Emp_Name, Emp_job, Emp_Dep)" TableName="tblEmployees">
</asp:LinqDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="LinqDataSource1"
>
<Columns>
<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" />
</Columns>
</asp:GridView>Step-15:
After complete this process just execute the code and see the output in output window just click on F5 button on key board.Conclusion:
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.About Author:
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.