Click here to Skip to main content
15,886,422 members
Articles / Web Development / ASP.NET

Edit Individual GridView Cells in ASP.NET

Rate me:
Please Sign up or sign in to vote.
4.88/5 (84 votes)
14 Nov 2009CPOL5 min read 1.4M   26.3K   305  
Edit individual GridView cells without putting the entire row into edit mode.Examples using the SqlDataSource and ObjectDataSource controls are included.
#region Directives

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

#endregion

/// <summary>
/// Task Class
/// </summary>
public class Task : IComparable<Task>
{
    #region Constructors

	public Task()
	{
	}

    public Task(int id, string description, string assignedTo, string status)
	{
        _id = id;
        _description = description;
        _assignedTo = assignedTo;
        _status = status;
	}

    #endregion

    #region Sorting

    #region IComparable<Task> Members

    public int CompareTo(Task other)
    {
        return Id.CompareTo(other.Id);
    }

    #endregion

    public static Comparison<Task> DescriptionComparison = delegate(Task t1, Task t2) 
    {
        return t1.Description.CompareTo(t2.Description); 
    };

    public static Comparison<Task> AssignedToComparison = delegate(Task t1, Task t2)
    {
        return t1.AssignedTo.CompareTo(t2.AssignedTo);
    };

    public static Comparison<Task> StatusComparison = delegate(Task t1, Task t2)
    {
        return t1.Status.CompareTo(t2.Status);
    };

    #endregion

    #region Properties & Fields

    private int _id;
    public int Id
    {
        get
        {
            return _id;
        }
        set
        {
            if (_id < 0)
                throw new ArgumentException(@"Id must be greater than or equal to zero.");
            else
                _id = value;
        }
    }

    private string _description;
    public string Description
    {
        get
        {
            return _description;
        }
        set
        {
            _description = value;
        }
    }

    private string _assignedTo;
    public string AssignedTo
    {
        get
        {
            return _assignedTo;
        }
        set
        {
            _assignedTo = value;
        }
    }

    private string _status;
    public string Status
    {
        get
        {
            return _status;
        }
        set
        {
            _status = value;
        }
    }

    #endregion
}

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
Chief Technology Officer
Ireland Ireland
I have been designing and developing business solutions for the aviation, financial services, healthcare and telecommunications industries since 1999. My experience covers a wide range of technologies and I have delivered a variety of web and mobile based solutions.

Comments and Discussions