Open the team site.
![team site]()
Create a sample list “Employee”.
![Open the team site]()
Add some values into the list.
![Employee]()
Open Visual Studio then create a new Visual Webpart.
![]()
Enter a valid site URL then select Deploy as a Farm solution.
![new visual webpart]()
Create a new Visual Webpart in the project.
![Select Deploy as a farm solution]()
Now open EmployeeRegistration.ascx.
Create a GridView.
![Create a new visual webpart]()
Code
- <asp:GridView ID="mygrid" runat="server" AutoGenerateColumns="false">
- <Columns>
- <asp:BoundField DataField="Name" HeaderText="
- Name" />
- <asp:BoundField DataField="Email" HeaderText="Email" />
-
-
- </Columns>
- </asp:GridView>
![Create a GridView]()
Now open EmployeeRegistration.ascx.cs.
Code
- using System;
- using System.ComponentModel;
- using System.Web.UI.WebControls.WebParts;
- using Microsoft.SharePoint;
- using System.Data;
-
- namespace BindListData.EmployeeRegistration
- {
- [ToolboxItemAttribute(false)]
- public partial class EmployeeRegistration : WebPart
- {
-
-
-
-
-
- public EmployeeRegistration()
- {
- }
-
- protected override void OnInit(EventArgs e)
- {
- base.OnInit(e);
- InitializeControl();
- }
-
- protected void Page_Load(object sender, EventArgs e)
- {
- SPWeb web = SPContext.Current.Web;
- SPList list = web.Lists["Employee"];
- SPListItemCollection items = list.Items;
- mygrid.DataSource = items.GetDataTable();
- mygrid.DataBind();
-
-
- }
- }
- }
Now deploy the webpart.
Now the result.
![result]()
![output]()
Happy SharePointing!
Regards: Vinodh.N (SharePoint developer / administrator).