Click here to Skip to main content
Click here to Skip to main content

"One size fits all" solution for freezing a Grid's header rows, why not?

By , 23 Jan 2013
 
Freezing_TableHeader_Demo.zip
GridHeaderFreezingDemo.suo
GridHeaderFreezingDemo
App_Code
App_Data
NORTHWND.MDF
NORTHWND_log.ldf
bin
AjaxControlToolkit.dll
GridHeaderFreezing.dll
CSS
Images
asc.gif
bg.gif
desc.gif
Images
collapse.gif
collapse_disabled.gif
expand.gif
expand_disabled.gif
gradient_background.png
grid_header_background.gif
icon_calendar.gif
icon_freeze.png
icon_freeze_inactive.png
InProcess.gif
loading.gif
stripped_background.gif
Thumbs.db
JS
Thumbs.db
using System;
using System.Data;
using System.Reflection;
using System.Collections.Generic;

/// <summary>
/// Summary description for DataHelper
/// </summary>
public class DataHelper
{
	public DataHelper()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    /// <summary>
    /// Populates an instance of the entity.
    /// </summary>
    /// <param name="entity">The instance of the entity to populate.</param>
    /// <param name="record">The current Datareader record.</param>
    public static void PopulateEntity<T>(T entity, IDataRecord record)
    {
        if (record != null && record.FieldCount > 0)
        {
            Type type = entity.GetType();

            for (int i = 0; i < record.FieldCount; i++)
            {
                if (DBNull.Value != record[i])
                {
                    PropertyInfo property = type.GetProperty(record.GetName(i), BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                    if (property != null)
                    {
                        property.SetValue(entity, record[property.Name], null);
                    }
                }
            }
        }
    }

    /// <summary>
    /// Populates a List of entities of type T.
    /// </summary>
    /// <param name="dr">The DataReader with data of entities.</param>
    /// <returns></returns>
    public static List<T> PopulateEntities<T>(IDataReader dr)
    {
        List<T> entities = new List<T>();
        while (dr.Read())
        {
            T ent = Activator.CreateInstance<T>();
            PopulateEntity<T>(ent, dr);
            entities.Add(ent);
        }
        return entities;
    }
}

By viewing downloads associated with this article you agree to the Terms of use 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)

About the Author

Pham Dinh Truong
Technical Lead SmartWeb Inc.
Vietnam Vietnam
Member
I have been working in ASP.NET for more than 6 years. I've also been working on Java and Windows-based application development for more than 4 years. My core competences include ASP.NET Web Development, Design Patterns, UnitTest, SubSonic, Ajax, Asynchronous and Multi-threading. I'm particularly interested in building smart software with great Usability and rich User Experience.
 
Visit my blog at:
http://ontheflyweb.blogspot.com

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 24 Jan 2013
Article Copyright 2013 by Pham Dinh Truong
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid