WEBSWAPP Silverlight ASP.NET 3.5 ASP.NET 2.0 ASP.NET 1.0
Cascading Lists
ITemplate
DDL in GridView
G/V MultiSelect
Nested GridViews
RegExp
DataGrid Reorder
Events fire twice
Hyperlink Field
TextBox
UpdateParameters
MultiView
TreeView
Introdcution FormView GridView

Creating Web Server Control Templates Dynamically

In this demo I create classes that implement the ITemplate interface of the System.Web.UI namespace.

public class FormattedTemplate : ITemplate, INamingContainer

{

    System.Web.UI.WebControls.ListItemType _type;

    DataColumn _dc;

    public FormattedTemplate(System.Web.UI.WebControls.ListItemType type, DataColumn dc)

    {

        _type = type;

        _dc = dc;

    }

    public void InstantiateIn(System.Web.UI.Control container)

    {

        //implementation

    }

  

}

I then programmatically add TemplateFields to the GridView based on the attributes of DataColumns that are bound to those TemplateFields. Observe the following features in this demo:

  1. If a column holds data of type string then the template will display a TextBox upon edit and label during display. The size of the displayed field will equal the number of characters multiplied by 6 pixels.
  2. If a column holds numeric data, then, upon Edit, a TextBox with both validators for both the range of the data type and for required field if the default value on the field cannot be null.
  3. If a column holds Boolean information then, upon edit, a radiobuttonlist of Yes and No will be displayed
  4. If a column is read-only then no edit textbox will be displayed.
  5. The styles of each column would change based on the attributes; for example primary keys will be in maroon color.
  6. Each GridView cell will display the column name, datatype and size when hovered over it.

The GridView also implements sorting. It also allows multiple rows selection for deletion.