国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

Form code generator V1.1 by Steve Schofield[bate2

2024-07-21 02:28:00
字體:
來源:轉載
供稿:網友

this article revolves around being plain lazy. when it comes to creating form code based on some  database table, i hate it! this code sample goes along way in speeding this process up for me.   there still is some manual parts to finish up the form code but this takes care of remembering what columns are in the database table.    in future releases, we'll provide more functionality to further automate this but this is a big first step in my opinion!  the following four steps listed below can be followed and this will generate the asp.net code. a big thanks to dave w. webmaster of  for saving me on many things!!

define what database you want to connect to in the config.web.  this is stored in the connection string
<configuration>
    <appsettings>
        <add key="dsn" value="server=localhost;uid=sa;pwd=;database=aspfree" />
    </appsettings>
</configuration>
load the aspx page in your browser, select the table to create the form code from
select the checkboxs of which fields to be on the form
copy and paste into your code..
here is a screen shot of the file after following the above steps.



here is the code:

<%@ page language="vb" enablesessionstate="false" enableviewstate="true" trace="false" debug="false" strict="true" %>
<%@ import namespace="system.text" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.data.sqlclient" %>
<script language="vb" runat="server">
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(sender as object, e as eventargs)

          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(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(sender as object, 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



sub button1_click(sender as object, 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:button id=""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

</script>

<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" 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"
bordercolor="black"
borderwidth="1"
cellpadding="3"
font-name="verdana"
font-size="8pt"
headerstyle-backcolor="#aaaadd"
autogeneratecolumns="false"
>
<columns>
<asp:templatecolumn headertext="add?">
<itemtemplate>
<center>
<asp:checkbox id=chkadd runat="server" />
</center>
</itemtemplate>
</asp:templatecolumn>

<asp:boundcolumn headertext="name" datafield="name"/>

<asp:templatecolumn headertext="create validator?">
<itemtemplate>
<center>
<asp:checkbox id=chkvalid runat="server" />
</center>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>

<asp:button id=button1 text="create form" runat="server" />
</asp:panel>

<asp:panel id="pnltextarea" visible="false" runat="server">
<p>copy this code into a new asp.net page</p>
<textarea id=taresults cols=90 rows=40 runat="server" />
</asp:panel>

</form>
</body>
</html


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 宜阳县| 兴海县| 梨树县| 高邑县| 波密县| 长沙市| 静安区| 芦山县| 安泽县| 文成县| 大埔县| 美姑县| 施秉县| 榆中县| 深水埗区| 信丰县| 河曲县| 贡嘎县| 乐业县| 偏关县| 纳雍县| 咸丰县| 宝清县| 封开县| 松潘县| 娄烦县| 沅陵县| 浦北县| 绥德县| 建昌县| 连城县| 民县| 通海县| 定边县| 孟州市| 靖江市| 和平县| 宁南县| 浮梁县| 苏尼特左旗| 化州市|