Open the team site.
Create a sample list “Employee”.
Add some values into the list.
Open Visual Studio then create a new Visual Webpart.
Enter a valid site URL then select Deploy as a Farm solution.
Create a new Visual Webpart in the project.
Now open EmployeeRegistration.ascx.
Create a GridView.
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>
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.
Happy SharePointing!
Regards: Vinodh.N (SharePoint developer / administrator).