About Me

My photo
Muthupet, TamilNadu, India
SharePoint 2010

Saturday, June 2, 2012

sharepoint list and grid

c#(aspx.cs)

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace sarawebpart.Layouts.sarawebpart
{
    public partial class saraweb : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }
        public void BindData()
        {
            using (SPSite osite = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb oweb = osite.OpenWeb())
                {
                    SPList EmpList = oweb.Lists["Employee"];
                    SPListItemCollection oitemcol = EmpList.Items;
                    Grid1.DataSource = oitemcol.GetDataTable();
                    Grid1.DataBind();
                }
            }
        }

    }
}

c#(aspx)

<asp:GridView ID="Grid1" runat="server" AutoGenerateColumns="false">
    <Columns>
                <asp:BoundField DataField="Title" HeaderText="First Name" />
                 <asp:BoundField DataField="LastName" HeaderText="Last Name" />
                  <asp:BoundField DataField="Salary" HeaderText="Salary" />
                </Columns>
                <HeaderStyle BackColor="Orange" ForeColor="White" />

    </asp:GridView>

No comments:

Post a Comment