Tuesday, January 3, 2012

SpGridView Code in Asp.Net Web Application.

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Security;
using System.Data;
using System.Configuration;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Collections.Specialized;
//using System.Security.Principal;
public partial class Default5 : System.Web.UI.Page
{
    SPGridView sgvTasks;
    DataSet dset = new DataSet();
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        sgvTasks = new SPGridView();
        sgvTasks.ID = "sgvTasks";
        sgvTasks.AutoGenerateColumns = false;
        this.Controls.Add(sgvTasks);
        BoundField bTitle = new BoundField();
        bTitle.HeaderText = "Task Name";
        bTitle.DataField = "Title";
        sgvTasks.Columns.Add(bTitle);
        BoundField bStatus = new BoundField();
        bStatus.HeaderText = "Task Status";
        bStatus.DataField = "Status";
        sgvTasks.Columns.Add(bStatus);
        BoundField bPriority = new BoundField();
        bPriority.HeaderText = "Task Priority";
        bPriority.DataField = "Priority";
        sgvTasks.Columns.Add(bPriority);
        if (!IsPostBack)
        {
            sgvTasks.DataSource = getTasks();
            sgvTasks.DataBind();
        }
    }
    public DataSet getTasks()
    {
        //Code
        return dset;
    }
}

No comments:

Post a Comment