Create form Wizard using VS.NETThis is a updated demo to create form wizard using an Visual Studio.NET |
<%@ Page Language="vb" EnableSessionState="False"EnableViewState="True" Trace="False" Debug="False"Strict="True" CodeBehind="createformcode.aspx.vb"AutoEventWireup="false" Inherits="aspfree.createformcode" %> <HTML> <HEAD> <title></title></SCRIPT> </HEAD> <body bgcolor="#ffffff"> <form runat="server"id="form1"> Select a tablename tocreate a .NET form for: <asp:dropdownlistid="tblList" runat="server" /> <asp:Buttonid="GetTable" Text="Get Table" onclick="GetTable_Click"runat="server" /> <asp:panelid="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:TemplateColumnHeaderText="Add?"> <ItemTemplate> <asp:CheckBoxid="chkAdd" runat="server" /> </ItemTemplate> </asp:TemplateColumn> <asp:BoundColumnHeaderText="Name" DataField="name" /> <asp:TemplateColumnHeaderText="Create Validator?"> <ItemTemplate> <asp:CheckBoxid="chkValid" runat="server" /> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:datagrid> <asp:Button id="Button1" onclick="Button1_Click"runat="server" Text="Create Form"></asp:Button> </asp:panel> <asp:panelid="pnlTextarea" visible="false" runat="server"> <P>Copythis code into a new ASP.NET page</P> <TEXTAREAid="taResults" rows="40" cols="90"runat="server"></asp:panel>
</form> </body> </html> </TEXTAREA> </asp:panel> </form> </body> </HTML> | |
asdf Imports System Imports System.Text Imports System.IO Imports System.Data Imports System.Data.SqlClient Imports Microsoft.VisualBasic Imports System.Configuration
Public Class createformcode Inherits System.Web.UI.Page Protected WithEvents tblList As System.Web.UI.WebControls.DropDownList Protected WithEvents GetTable As System.Web.UI.WebControls.Button Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents myPanel As System.Web.UI.WebControls.Panel Protected WithEvents pnlTextarea As System.Web.UI.WebControls.Panel Protected WithEvents taResults As System.Web.UI.HtmlControls.HtmlTextArea
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub
#End Region Dim sqlText As String Dim ds As New DataSet() Dim dbComm As New SqlDataAdapter() Dim conn As SqlConnection Dim sqlServer As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.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 RequiredField!</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 JOINsyscolumns 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
Sub Button1_Click(ByVal sender As Object, ByVal e As 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>" & Chr(13))
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(" " & Chr(13) & 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:buttonid=""button1"" Text=""Validate Form""runat=""Server"" /></td>" & Chr(13)) sb.Append(" </tr>" & Chr(13)) ' close out the row sb.Append(" </table>" & Chr(13)) sb.Append(Chr(13) & "</form>") strOutput = sb.ToString() strOutput = System.Web.HttpUtility.HtmlEncode(strOutput) taResults.Value = strOutput pnlTextarea.Visible = True 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 Articles More By aspfree developerWorks - FREE Tools! | 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!
| | | | Join this webcast, to learn how the Rational Process Library can help with compliance issues, drive process improvement, and assist in service-oriented architecture (SOA) or Agile development. We will take a peek into the Rational Process Library with content around software and systems engineering (including RUP), operations and systems management, program and portfolio management, and asset and SOA governance. FREE! Go There Now!
| | | | Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
| | | | Building a software-as-a-service solution requires addressing a few key technical challenges. In this webcast, we'll focus on the role of IBM Tivoli Directory Server and WebSphere Portlet Factory in creating a Software as a Service solution. We will demonstrate how to use Tivoli Directory Server to prevent the user population of one tenant from accessing the virtual portal and portlet components of another tenant. We will also use the dynamic profile capability of WebSphere Portlet Factory to create multiple highly customized applications from one code base. FREE! Go There Now!
| | | | Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
| | | | Visit IBM developerWorks to download IBM DB2 Express-C 9.5, a no-charge version of DB2 Express 9 database server. DB2 Express-C offers the same core data server base features as other DB2 Express editions and provides a solid base to build and deploy applications developed using C/C++, Java, .NET, PHP, and other programming languages. FREE! Go There Now!
| | | | Download the IBM WebSphere Portal V6.1 beta code and learn more about the rich features and enhancements in IBM WebSphere Portal V6.1. WebSphere Portal provides a composite application or business mashup framework and the advanced tooling needed to build flexible, SOA-based solutions, and scalability to meet the needs of any size organization. FREE! Go There Now!
| | | | Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
| | | | Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |