ApplicationPage.aspx
ApplicationPage.cs
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0,
Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Assembly Name="CustomApplicationPages, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=d4e5777b16a5749f" %>
<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master"
Inherits="CustomApplicationPages.ApplicationPage" EnableViewState="false" EnableViewStateMac="false" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint,Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ID="Main" contentplaceholderid="PlaceHolderMain" runat="server">
<SharePoint:SPGridView runat="server"
ID="grid"
AutoGenerateColumns="false"
RowStyle-BackColor="#DDDDDD"
AlternatingRowStyle-BackColor="#EEEEEE" />
</asp:Content>
<asp:Content ID="PageTitle" contentplaceholderid="PlaceHolderPageTitle" runat="server">SharePoint GridView</asp:Content>
<asp:Content ID="PageTitleInTitleArea" contentplaceholderid="PlaceHolderPageTitleInTitleArea" runat="server">
Application Page : Using the SPGridView control
</asp:Content>
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
namespace CustomApplicationPages {
public class ApplicationPage : LayoutsPageBase {
// add control fields to match controls tags on .aspx page
protected SPGridView grid;
protected override void OnLoad(EventArgs e) {
grid = new SPGridView();
grid.AutoGenerateColumns = false ;
grid.CssClass = "ms-listviewtable";
grid.AlternatingRowStyle.CssClass = "ms-alternating";
grid.Width = new Unit(50, UnitType.Percentage);
grid.GridLines = GridLines.None;
grid.HeaderStyle.Font.Bold = true;
grid.HeaderStyle.HorizontalAlign = HorizontalAlign.Left;
DataTable table = new DataTable();
//TO DO : Populate the DataTable here <-----
SPBoundField col= new SPBoundField();
col.HeaderText = "Product Name";
col.DataField = "ProductName";
grid.Columns.Add(col);
Controls.Add(grid);
grid.DataSource = table.DefaultView;
grid.DataBind();
}
}
}
5 comments:
This code did not work for me, even after adding the missing System.data reference, the sharepoint application page fails to load.
I think you are using different datatable with diff columns.. try to add break point around DataBind - it might be broken around that line of code
Can u plz help wid using Sorting and Filtering features of SPGridView?
Check out http://www.codeproject.com/Articles/35536/Creation-of-a-SPGridview-Webpart-having-Pagination
Hallo Sandeep,
Editing is working but adding new item using the Gridview is not working. could you help me
do that ?..
Post a Comment