Click here to Skip to main content
15,891,253 members
Articles / Web Development / XHTML

A lightweight AJAX.NET-enabled grid control

Rate me:
Please Sign up or sign in to vote.
4.65/5 (11 votes)
28 Jun 2008CPOL10 min read 73K   2.4K   76  
A lighweight approach to creating AJAX.NET-enabled grids, with advanced functionality built in.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;


public partial class Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // uncomment the following line to always choose the default profile
        //Session["GridProfile"] = AjaxGrid.DefaultProfile;
        List<AjaxGrid.GridProfileData> profile = (List<AjaxGrid.GridProfileData>)Session["GridProfile"];
        if (profile == null)
        {
            // normally, the code to load profile data would be done from a login page
            // where the user could be uniquely identified and their profile loaded from the database
            // if a null profile in the session is detected in this page, normally redirect to the login page 
            BinaryFormatter formatter = new BinaryFormatter();
            using(MemoryStream memStream = new MemoryStream())
            {
                // example serialise to a memory stream
                formatter.Serialize(memStream,AjaxGrid.DefaultProfile);
                memStream.Seek (0, SeekOrigin.Begin);
                // example deserialise from a memory stream
                profile = (List<AjaxGrid.GridProfileData>)formatter.Deserialize(memStream);
                Session["GridProfile"] = profile;
            }
        }
        profile[AjaxGrid1.GridId].SelectProc = OnSelect;
        profile[AjaxGrid1.GridId].ValidateProc = OnValidate;
    }

    // a link cell has been seleted
    public static void OnSelect(int databaseId)
    {
        // do some actions when a link has been selected...
    }

    // a cell has been updated
    public static string OnValidate(string columnName, string value)
    {
        return null; // validation accepted
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United Kingdom United Kingdom
Check me out at LinkedIn: http://uk.linkedin.com/pub/simon-gulliver/20/303/251

Comments and Discussions