How to Create DataSource control using Gridview control in ASP.net:
In this article I'm trying to explain how to create DataSource controls like LinqDataSource, XMLDataSource etc.. Using Gridview control in ASP.net. During this process we can able to learn how to create DataSource controls and how to configure with Gridview control for displaying data into that. This article will help you for beginners.
Follow below steps to achieve your goal.
Design a page by right click on project and then choose Add NewItem option then Choose WebForm and give a name for that as GVDataSource.aspx. Refer below screen shot for more information.
Then open a designer page and simply drag & drop one Gridview control to the design view and select the Choose Data Source dropdown and then choose New Data Source option for creating New Data Source control purpose, as shown in below fig.
Once we choose New Data Source option, then a new Data Source Configuration wizard window will appear on the screen. Choose your Data Source type and click on OK button automatically new Data Source control has been created for that control. In below scenario I choose Linq Data Source control.
Choose your Data Context object available in dropdown menu and then click on Next button.
When I click on Next button its redirect to new window for configure data selection purpose. Choose your table name and then choose columns what do you want to display in output. In the below screen I just choose my table name as Employee and I choose columns are “employee name, job, department”, as shown in below fig.
Just click Finish button for creating Data Source control, now it’s ready to use that Data Source control while display the information into our Application.
Just see the code behind how the code looks become changes.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
<asp:BoundField DataField="Emp_Name" HeaderText="Emp_Name" ReadOnly="True"
<asp:BoundField DataField="Emp_job" HeaderText="Emp_job" ReadOnly="True"
<asp:BoundField DataField="Emp_Dep" HeaderText="Emp_Dep" ReadOnly="True"
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
Select="new (Emp_Name, Emp_job, Emp_Dep)" TableName="tblEmployees">
Now the times to execute the code in browser just press F5 on your keyboard and see the result.
I hope this article will help you those who are looking for the same and those who are new to implement Gridview control to configure with Data Source controls.
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.
No responses found. Be the first to comment...