Creating a Custom Data Field Control - Part 2
page 2 of 6
by Brian Mains
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 27914/ 45

The Custom Base Class

Previously, I illustrated code samples taken from a primitive base class I created for working with the essential functions with data control fields. However useful that was, I figured that for a certain percentage of situations I create data fields in, another level of abstraction is handy. The following is a second base class that I created (called the BaseSingleDataField), another level of abstraction is helpful to have. The methods that are abstract in this base class are illustrated below; each one has to perform a specific action.  I will discuss each one in detail.

Listing 1

public abstract Control SetupEditControl();

This method creates an instance of the control that will edit the value in insert or edit mode. This assumes that there is one instance of a control that performs the editing. It is possible to work with more, but the edited control has to be at the zero index mark.

Listing 2

public abstract string GetEditControlValue(TableCell cell);

The control representing the insert/edit interface has a value, which will be used to update the dictionary with the new value from it. However, the base class does not know how to get a value from the edit interface control, so this method is in charge of handling, extracting that value and providing it to the base class, which uses it to add the value to the dictionary.

Listing 3

public abstract void BindEditControl(object control, bool insertMode);

The data, whatever that may be, needs bound to the control. An insert mode flag determines whether the control is currently in insert mode; the row state enumeration is not needed because this only works whenever in edit mode, and read only mode is not an option. So, this method is in charge of binding the edit control with the corresponding data field value. It is up to the method to determine what field that is, and how to get the value.

Listing 4

protected abstract string GetDataItemFieldName(DataControlRowState state);

Although most data fields have a single DataField property, I did not want that to be a limitation set in the primitive base class. So, as an alternative, this class requires the overriding of a GetDataItemFieldName method that returns the name of the field to bind with. The row state is also passed because it is possible to have multiple field names, one for each state (you never know how useful that could be).

Essentially, the basic actions are the editing interface gets setup, gets bound, and returns its value. There is some additional functionality for read-only mode illustrated later.


View Entire Article

User Comments

Title: Article   
Name: bhaskar
Date: 2008-08-30 6:23:21 AM
Comment:
good






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-16 9:55:04 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search