Ajax Data Controls (Repeater, Data List and Grid View)

by Ishai Hachlili 18. February 2008 08:14

ADC is a set of data controls that try to mimic the Asp.Net controls using Asp.Net AJAX Extensions.

I'm looking at the GridView in particular, although I never really liked the Asp.Net control, the AJAX version might work well for my search pages.
For the current project I'm working on I won't be using the server side wrapper, just the client side code.

The grid view control supports paging, sorting, column dragging, links, checkboxes and in-place editing.

I'm going to try it out, see if it takes the places of my upgraded WebFXColumnList...

check it out at Ajax Data Controls - Home


AJAX | Asp.Net | Javascript

Using DiscoverParameters with the Ajax Search Page

by Ishai Hachlili 15. February 2008 19:20

This is a small upgrade to the DoSearch method in the data access layer.
Instead of using the FieldType property for each parameter, I'm using db.DiscoverParameters, and instead of adding new parameters I'm setting the values of the discovered parameters.

I didn't want to use a discovery but after starting to use the Enterprise Library's Data block, I decided to give it a try.
As you can see it's very easy to use, just one line of code, and the discovery results are supposed to be cached, so the performance hit should be too hard.

Here's the updated code:

/// <summary>
/// Performs a search
/// </summary>
/// <param name="SPName">the name of the Stored Procedure to execute</param>
/// <param name="DBName">the name of the DataBase where the stored procedure is (if not the default database)</param>
/// <param name="searchParams">The search parameters including page size</param>
/// <returns>a dataset of the search results</returns>
public DataSet DoSearch(string SPName, string DBName, IshaiHachlili.MyTakeOnDotNet.Entities.SearchParameters searchParams)
    Database db = DatabaseFactory.CreateDatabase(DBName);
    DbCommand cmd = db.GetStoredProcCommand(SPName);
    //Add form input search parameters for this search query
    foreach (QueryParameter fld in searchParams.Parameters)
        //db.AddInParameter(cmd, fld.FieldName, fld.FieldType, fld.FieldValue);
        cmd.Parameters['@' + fld.FieldName].Value = fld.FieldValue;

    //Add common parameters (all search stored procedures should have this parameters and support paging and sorting functionality)
    cmd.Parameters["@PageIndex"].Value = searchParams.PageIndex;
    cmd.Parameters["@PageSize"].Value = searchParams.PageSize;
    cmd.Parameters["@SortColumn"].Value = searchParams.SortColumn;
    cmd.Parameters["@SortOrder"].Value = searchParams.SortOrder;

    DataSet ds = db.ExecuteDataSet(cmd);

    return ds;


Enterprise Library

How To: Use connections not saved in web.config with the Data Application Block

by Ishai Hachlili 15. February 2008 18:18
While working on the search pages solution (read about it here) I realized I need to be able to save data connections in a database.

I’m using a database to manage everything that has to do with the application itself (membership, roles, search page info, etc…) but the actual data comes from other databases.

The Data Application Block supports using different connection as long as these connections are defined in the web.config file.
Because I didn’t want to make changes to the config file too often, and I also wanted users to be able to add new data connections without my help, having these connections in a database will be great.

After looking through the data block’s code, I realized I need to create a new configuration source.
I figured someone has already done this, and sure enough, a quick google search later I found out that such a solution exists right there in the enterprise library’s Quick Starts folder.

I quickly added the SqlConfiguration project to my solution and thought my problems were solved.
Unfortunately, it just didn’t work.
I also didn’t really want to save the entire connections section as on row in a table, that will make it harder to maintain. So I decided to create an implementation just for the connections section and inherit the rest for the SqlConfiguration.

The DataConnections table:

you can see the columns are the same as the connection attributes in web config.

The Configuration Source:

namespace IshaiHachlili.RapidBackOffice.Configuration.ConnectionsSqlConfigurationSource
    public class ConnectionsSqlConfigurationSource : IConfigurationSource
        private string defaultConnectionString = String.Empty;
        private const string GetConfig = "EntLib_GetConfig";
        private const string SetConfig = "EntLib_SetConfig";
        private const string RefreshSection = "EntLib_UpdateSectionDate";
        private const string RemoveSection = "EntLib_RemoveSection";

        public ConnectionsSqlConfigurationSource()
            if (ConfigurationManager.ConnectionStrings.Count > 0)
                defaultConnectionString = ConfigurationManager.ConnectionStrings[0].ConnectionString;

        public System.Configuration.ConfigurationSection GetSection(string sectionName)
            if (sectionName != "connectionStrings")
                IConfigurationSource source = new SqlConfigurationSource(defaultConnectionString, GetConfig, SetConfig, RefreshSection, RemoveSection);
                return source.GetSection(sectionName);
            ConnectionStringsSection section = new ConnectionStringsSection();

            //Get the connections from the DL
            ConnectionsDL dl = new ConnectionsDL();
            IDataReader dr = dl.GetDataConnections();
            while (dr.Read())
                string connectionName = dr["ConnectionName"].ToString();
                string connectionString = dr["ConnectionString"].ToString();
                string providerName = dr["ProviderName"].ToString();
                section.ConnectionStrings.Add(new ConnectionStringSettings(connectionName, connectionString, providerName));

            return section;

    public class ConnectionsDL
        public IDataReader GetDataConnections()
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand cmd = db.GetStoredProcCommand("GetDataConnections");
            IDataReader dr = db.ExecuteReader(cmd);
            return dr;

The GetDataConnections stored procedure simply returns all the connections in the DataConnections table.
Because I'm using the CreateDatabase() method with no DB name, the default database will be used. This is the management database for my application and the only connection that will be saved in the web.config.

Using the new configuration source in the data layer

protected Database getDatabase(string DBName)
    if (String.IsNullOrEmpty(DBName))
        return DatabaseFactory.CreateDatabase();

    IConfigurationSource source = new ConnectionsSqlConfigurationSource();
    DatabaseProviderFactory factory = new DatabaseProviderFactory(source);
    Database db = factory.Create(DBName);
    return db;

I added this method to a base class that all the classes in my data layer inherit from. now instead of using the DatabaseFactory.CreateDatabase() I use getDatabase(DBName).
As you can see, when there's no DBName, I still use the DatabaeFactory method, there's no reason to get the connections from the database when using the default connection that's saved in the web.config.
You can also add caching to avoid calling the database everytime you need to get the connections list.


Asp.Net | Enterprise Library | Sql Server

About Me

Ishai Hachlili is a web and mobile application developer.

Currently working on Play The Hunt and The Next Line

Recent Tweets

Twitter October 23, 05:22
@BenThePCGuy a standard where that doesn't matter is better. One more reason to get the #Lumia920, wireless charging, no need for microUSB

Twitter October 23, 05:21
@ManMadeMoon where they dance around the issues and don't really talk about them

Twitter October 23, 05:20
@BenThePCGuy are you a @wpdev ?

Twitter October 23, 04:17
@JonahLupton But if it's black it's usually better

Twitter October 23, 02:58
@jongalloway next time ask your 5 year old how to spell