This is a updated demo to create form wizard using an aspx page and code-behind in VB.NET |
<%@ Page Language="vb" EnableSessionState="False" EnableViewState="True" Trace="False" Debug="False" Inherits="createformcode" src="createformcode.vb" %> <HTML> <HEAD> <title></title> </HEAD> <body bgcolor="#ffffff"> <form runat="server" id="form1"> Select a tablename to create a .NET form for: <asp:dropdownlist id="tblList" runat="server" /> <asp:Button id="GetTable" Text="Get Table" onclick="GetTable_Click" runat="server" /> <asp:panel id="myPanel" runat="server" visible="false"><BR>Select the Columns used for generating the form. <asp:datagrid id="MyDataGrid" runat="server" AutoGenerateColumns="False" HeaderStyle-BackColor="#aaaadd" Font-Size="8pt" Font-Name="Verdana" CellPadding="3" BorderWidth="1" BorderColor="black"> <Columns> <asp:TemplateColumn HeaderText="Add?"> <ItemTemplate>
<asp:CheckBox id="chkAdd" runat="server" />
</ItemTemplate> </asp:TemplateColumn> <asp:BoundColumn HeaderText="Name" DataField="name" /> <asp:TemplateColumn HeaderText="Create Validator?"> <ItemTemplate>
<asp:CheckBox id="chkValid" runat="server" />
</ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid> <asp:Button id="Button1" onclick="btnSubmit_Click" runat="server" Text="Create Form"></asp:Button> </asp:panel> <asp:panel id="pnlTextarea" visible="false" runat="server"> <P>Copy this code into a new ASP.NET page</P> <TEXTAREA id="taResults" name="taResults" rows="40" cols="90" runat="server"> </asp:panel> </form> </body> </html> </TEXTAREA> </asp:panel> </form> </body> </HTML>
|
|
Imports System Imports System.Text Imports System.IO Imports System.Data Imports System.Data.SqlClient Imports System.Configuration Imports System.Web Imports System.Web.UI.WebControls Imports System.Web.UI.HTMLControls Imports Microsoft.VisualBasic
Public Class createformcode: Inherits System.Web.UI.Page
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid Protected WithEvents taResults As System.Web.UI.HtmlControls.HtmlTextArea Protected WithEvents pnlTextarea As System.Web.UI.WebControls.Panel Protected WithEvents myPanel As System.Web.UI.WebControls.Panel Protected WithEvents tblList As System.Web.UI.WebControls.DropDownList Protected WithEvents GetTable As System.Web.UI.WebControls.Button Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
Dim sqlText As String Dim ds As New DataSet() Dim dbComm As New SqlDataAdapter() Dim conn As SqlConnection Dim sqlServer As String
Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
sqlServer = GetSqlConn() conn = New SqlConnection(sqlServer) If Not IsPostBack Then sqlText = "select id, name from sysobjects where xtype='U' order by name" dbComm = New SqlDataAdapter(sqlText, conn) dbComm.Fill(ds, "AllTables") tblList.DataSource = ds.Tables("AllTables").DefaultView tblList.DataTextField = "name" tblList.DataValueField = "name" tblList.DataBind() End If End Sub
Function CreateValidator(ByVal myName As String) As String Dim mySB As StringBuilder = New StringBuilder()
REM -- use :<some text>: as placeholders mySB.Append("<asp:RequiredFieldValidator runat=""server"" id="":Name:"" ControlToValidate="":control:"" ErrorMessage="":errMsg:"" display=""Static"">This Required Field!</asp:RequiredFieldValidator>")
mySB.Replace(":Name:", "vld" & myName) 'add the validator name mySB.Replace(":control:", "at" & myName) 'add the control name mySB.Replace(":errMsg:", myName & " is required")
Return mySB.ToString()
End Function
Function GetSqlConn() As String Dim DSN As String = ConfigurationSettings.AppSettings("DSN") Return DSN End Function
Sub GetTable_Click(ByVal sender As Object, ByVal e As EventArgs) Dim sqlText As String sqlText = "SELECT syscolumns.name, syscolumns.isnullable FROM sysobjects INNER JOIN syscolumns ON sysobjects.id = syscolumns.id where sysobjects.name = '" & tblList.SelectedItem.Text & "' ORDER BY syscolumns.colid"
REM -- Connect to SQL dbComm = New SqlDataAdapter(sqlText, conn)
REM -- Fill DataSet dbComm.Fill(ds, "TestData") MyDataGrid.DataSource = ds.Tables("TestData").DefaultView MyDataGrid.DataBind()
REM -- Show the results myPanel.Visible = True
End Sub
Public Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim i As Integer Dim _item As DataGridItem Dim dr As DataRow Dim sb As StringBuilder = New StringBuilder() Dim strOutput As String
REM -- Auto Generate The Form sb.Append("<form runat=""server"" id=""form2"" name=""form2"">" & chr(13) & chr(10)) sb.Append(" <table border=1>")
For i = 0 To MyDataGrid.Items.Count - 1 REM -- Get the checkbox _item = MyDataGrid.Items(i) Dim addCheckBox As CheckBox = Ctype(_item.FindControl("chkAdd"), CheckBox) Dim validCheckBox As CheckBox = Ctype(_item.FindControl("chkValid"), CheckBox)
If addCheckBox.Checked Then sb.Append(" <tr>" & chr(13)) sb.Append(" <td>" & _item.Cells(1).Text & "</td>" & chr(13)) sb.Append(" <td>") sb.Append("<asp:textbox id=""at" & _item.Cells(1).Text & """ runat=""server"" />")
'create a validator control If validCheckBox.Checked Then sb.Append(" " & vbCrLf & CreateValidator(_item.Cells(1).Text)) End If
sb.Append("</td>" & chr(13)) ' sb.Append(" </tr>" & chr(13)) ' close out the row End If
Next sb.Append(" <tr>" & chr(13)) ' close out the row sb.Append(" <td colspan=""2""><asp:button id=""button1"" Text=""Validate Form"" runat=""Server"" /></td>" & vbCrLf) sb.Append(" </tr>" & chr(13)) ' close out the row sb.Append(" </table>" & chr(13)) sb.Append(vbCrLf & "</form>") strOutput = sb.ToString() strOutput = System.Web.HttpUtility.HtmlEncode(strOutput) taResults.Value = strOutput pnlTextarea.Visible = True End Sub
Private Sub InitializeComponent()
End Sub
End Class
| | DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP.NET Code Articles More By aspfree developerWorks - FREE Tools! | Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
| | | | Visit IBM developerWorks to try the IBM SOA Sandbox for people. The SOA Sandbox for people provides a trial environment with the necessary tooling and components required to enable consistent human and process interaction and collaboration, showing how you can improve user experience and business productivity. FREE! Go There Now!
| | | | This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
| | | | The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial of the latest release of IBM Lotus Sametime Standard V8.0. Lotus Sametime Standard V8.0 is a platform for unified communications and collaboration that combines security features with an extensible, open solution including integrated Voice over IP, geographic location awareness, mobile clients, and a robust Business Partner community offering telephony and video integration. FREE! Go There Now!
| | | | Portfolio Management is about effectively managing portfolio value by aligning portfolio investments with business goals. This complimentary e-kit provides a collection of materials that can help you understand how IBM Rational enables and automates best practices for improved governance and clear visibility into portfolio and project performance across the entire IT project lifecycle. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
| | | | As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
| | | | This demonstration gives you an overview of IBM® Rational® Build Forge Express Edition, a global offering that provides a framework to automate and execute software processes. Rational Build Forge provides a software assembly line that can support all of your tools, technologies, and platforms so you can achieve a repeatable, reliable, and traceable build and release process. FREE! Go There Now!
| | | | Download a free trial version of IBM Rational Developer for System i V7.1, which provides a complete development environment for traditional i5/OS application development. IBM Rational Developer for System i is a new eclipse-based workstation offering for i5/OS application development that provides a comprehensive Integrated Development Environment for edit/compile/debug of traditional RPG/COBOL/C/C++ i5/OS applications. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |