Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Quick Screen Development in ASP.NET

0.00/5 (No votes)
20 Jul 2004 1  
Auto Generate the ASPX page quickly

Introduction

Developing the screen for various tables has been a boring activity. This is small step towards automating the screen generation for the aspx pages.

Currently this application can generate the aspx tags for SQL Server 2000 table.

The idea is

a. For every column in the table , A Label field is required on the screen.

b. For a natural column in the table, A text box is required on the screen.

c. If the column is not nullable , A required field validator needs to be placed on the screen.

d. For a foreign key, Usually a dropdown list is required.

d. Tab index and Max Length properties also need to be set.

To get the meta data for a table the following procedure is used. It gets the name of the column, Data Type, If it nullable, Size and if it is a foreign key.


SELECT
COLUMN_NAME,
DATA_TYPE,
IS_NULLABLE,
isnull(CHARACTER_MAXIMUM_LENGTH,0),

-- Identifies if it is a foreign key-------
ISNULL((SELECT 'Y' FROM SYSFOREIGNKEYS WHERE FKEYID =ID AND FKEY=COLID),'N')
as 'IsForeignKey',
Ordinal_Position

FROM
SYSCOLUMNS,
(SELECT
COLUMN_NAME,
IS_NULLABLE,
DATA_TYPE,
CHARACTER_MAXIMUM_LENGTH,
Ordinal_Position

FROM
INFORMATION_SCHEMA.COLUMNS

WHERE
TABLE_NAME =@Table_Name) AS A

WHERE
ID
IN
(SELECT
ID
FROM
SYSOBJECTS
WHERE
TYPE='U'
AND NAME =@Table_Name
)

AND
A.COLUMN_NAME =NAME
Order By
Ordinal_Position.
Now there are 4 classes in the application. Common.cs has all the common properties. Other classes for the controls are inherited from it. ToString() method is overriden to generate the aspx tag necessary for the control.
Steps to Generate the aspx code.

1. Create the stored procedures provided in your database.

2. Modify the connection information in the Form1.cs file. There are two places you have to modify the connection information . One inside GetTables() method and another inside ProcessTable(string TableName).

3. Execute the project. In the Window The combo shows the list of tables available. Enter the name of the table inside the text box and click the generate button.

4. Copy the code from the textbox below and paste inside the <form></form> tags inside your aspx page.

5. There you go.....

Currently this generates a label for every column, Text or Combo box depending on weather it is a table column or a foreign key, generates a required field validator for not nullable fields,sets the tab order and max length properties.

Let me know if there are other methods to generate aspx pages.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here