Click here to Skip to main content
15,895,788 members
Articles / Web Development / XHTML

Paging, Selecting, Deleting, Editing and Sorting in the ASP.NET GridView Control with Keyboard Shortcuts

Rate me:
Please Sign up or sign in to vote.
4.89/5 (32 votes)
5 Oct 2010CPOL8 min read 158.2K   6.3K   137  
An ASP.NET 2.0 AJAX Extender to enhance the ASP.NET GridView to page, select, delete, edit and sort rows with keyboard shortcuts.
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
Software Developer Dipl.-Ing. Rolf Cerff Software Development and IT-
Germany Germany
I'am a freelance software developer, located at Freiburg i. Br., Germany. My main domain is designing and developing Web applications based on the ASP.NET technology. Further main interests are. Sustainable and agile software architectures, Domain Driven Design (DDD). I'am a certified SCRUM Master.

Comments and Discussions