asp.net 动态生成表格

asp.net 动态生成表格,第1张

首先看你的表格生链凯成是做什么用?

通常动态创建表格有2种情况.一种就是在一个已经固定的表格情况下新增行嫌唤肢或者单元格...另一个就是完全的从后台创建一个表格.

第一个情况:你可以用普通的方式写AJAX的,在后台写C#程序.取得当前要 *** 作的表格的ID.然后创建就可以了。..至于具体的代码。你去看看.htmltable的用法.

第2个情况:如果是在C#动态创建的话。你用AJAX的用C#来写代码的话.它存在一个回传的机制,一回传你动态创建的表格就没了。所以建议全部用JS来写。...如果你要在表格里显示数据库芹世的数据,那只有JS配合AJAX读取数据库数据.

<!--#include file="DBconn.asp"-->

<SCRIPT LANGUAGE="JavaScript">

<!--

function check()

{

if(checkspace(document.userinfo.username.value)) {

document.userinfo.username.focus()

alert("用户名不能为空,请重新输入!")

return false

}

if(checkspace(document.userinfo.username.value) || document.userinfo.username.value.length <2) {

document.userinfo.username.focus()

alert("用户名长度不能小于2,请重新输入!")

return false

}

if(checkspace(document.userinfo.password.value) || document.userinfo.password.value.length <6) {

document.userinfo.password.focus()

alert("密码长洞野扒度不能小于6,请重新输入!")

return false

}

if(document.userinfo.password.value != document.userinfo.password1.value) {

document.userinfo.password.focus()

document.userinfo.password.value = ''

document.userinfo.password1.value = ''

alert("两次输入的脊凳密码不同,请重新输入!")

return false

}

if(document.userinfo.useremail.value.length!=0)

{

if (document.userinfo.useremail.value.charAt(0)=="." ||

document.userinfo.useremail.value.charAt(0)=="@"||

document.userinfo.useremail.value.indexOf('@', 0) == -1 ||

document.userinfo.useremail.value.indexOf('.', 0) == -1 ||

document.userinfo.useremail.value.lastIndexOf("@")==document.userinfo.useremail.value.length-1 ||

document.userinfo.useremail.value.lastIndexOf(".")==document.userinfo.useremail.value.length-1)

{

alert("Email地址格式不正确!")

document.userinfo.useremail.focus()

return false

}

}

else

{

alert("Email不能为空!")

document.userinfo.useremail.focus()

return false

}

}

function checkspace(checkstr) {

var str = ''

for(i = 0i <checkstr.lengthi++) {

str = str + ' '

}

return (str == checkstr)

}

//-->

</script>

<body oncontextmenu=self.event.returnValue=false onselectstart="return false">

<link href="CSS/css.css" rel="stylesheet" type="text/css">

<table width="495" border="纳昌0" align="center" cellpadding="2" cellspacing="1" >

<tr bgcolor="#cCcCcC">

<td height="34" colspan="2"><div align="left"><font color="#0033CC"><strong>填写用户信息</strong></font>...</div></td>

</tr>

<form action="user_reg.asp?action=save" method="post" name="userinfo" id="userinfo" >

<tr bgcolor="#F5F5F5">

<td width="82" align="right"><font color="#cb6f00">用 户 名:</font></td>

<td width="402"><input name="username" class="wenbenkuang" type="text" id="username" size="28">

用户名长度不能小于2。</td>

</tr>

<tr bgcolor="#F5F5F5">

<td><div align="right"><font color="#cb6f00">密码:</font></div></td>

<td><input name="password" type="password" class="wenbenkuang" id="password2" size="28" />

长度必须大于6个字符。</td>

</tr>

<tr bgcolor="#F5F5F5">

<td><div align="right"><font color="#cb6f00">确认密码:</font></div></td>

<td><input name="password1" type="password" class="wenbenkuang" id="password12" size="28" /></td>

</tr>

<tr bgcolor="#F5F5F5">

<td><div align="right"><font color="#cb6f00">E-Mail:</font></div></td>

<td><input name="useremail" type="text" class="wenbenkuang" id="useremail" size="28" />

请您正确填写E-mail地址,</td>

</tr>

<tr bgcolor="#F5F5F5">

<td><div align="right"><font color="#cb6f00">密码提示: </font></div></td>

<td><input name="quesion" type="text" class="wenbenkuang" id="quesion" size="28" /></td>

</tr>

<tr bgcolor="#F5F5F5">

<td><div align="right"><font color="#cb6f00">密码答案: </font></div></td>

<td><input name="answer" type="text" class="wenbenkuang" id="answer" size="28" /></td>

</tr>

<tr bgcolor="#F5F5F5">

<td><div align="right"><font color="#cb6f00">相关图片: </font></div></td>

<td><input name="picture" type="file" class="wenbenkuang" id="picture" size="28" /></td>

</tr>

<tr bgcolor="#F5F5F5">

<td></td>

<td><input onclick="return check()" class="wenbenkuang" type="submit" name="Submit3" style="height:20font:9ptBORDER-BOTTOM: #cccccc 1px grooveBORDER-RIGHT: #cccccc 1px grooveBACKGROUND-COLOR: #eeeeee"value="提 交">

<input type="reset" name="Submit5" class="wenbenkuang" style="height:20font:9ptBORDER-BOTTOM: #cccccc 1px grooveBORDER-RIGHT: #cccccc 1px grooveBACKGROUND-COLOR: #eeeeee" value="清 除" /></td>

</tr>

<tr>

<td height="5"></td>

</tr>

</form>

</table>

</body>

<%

dim action

action=request.QueryString("action")

select case action

case "save"

call saveuser()

end select

sub saveuser()

dim strSQLname,UserName,Email,strSQLeEmail

UserName=trim(request.form("username"))

Email=trim(request.form("useremail"))

strSQLname="select UserName from User_Table where UserName='"&UserName&"'"

strSQLeEmail="select Email from User_Table where Email='"&Email&"'"

set rs=server.CreateObject("adodb.recordset")

rs.open strSQLname,conn,1,1

if not rs.eof and not rs.bof then

%>

<table width=500 height=30 border=0 align=center cellpadding=0 cellspacing=1>

<tr>

<td width="500" bgcolor=#FFFFFF>友情提示·您输入的用户名已经被注册,请选用其他的用户名!

<a href=javascript:history.go(-1) style="text-decoration:none"><font color=red>[点击返回更改]</font></a>

</td>

</tr>

</table>

<%

response.End()

rs.close

set rs=nothing

end if

set rs=server.CreateObject("adodb.recordset")

rs.open strSQLeEmail,conn,1,1

if not rs.eof and not rs.bof then

%>

<table width=500 height=30 border=0 align=center cellpadding=0 cellspacing=1>

<tr>

<td width="500" bgcolor=#FFFFFF>友情提示·您输入的邮件已经被注册,请选用其他的邮件!

<a href=javascript:history.go(-1) style="text-decoration:none"><font color=red>[点击返回更改]</font></a>

</td>

</tr>

</table>

<%

response.End()

rs.close

set rs=nothing

end if

set rs=server.CreateObject("adodb.recordset")

rs.open "select * from User_Table",conn,1,3

if not rs.eof and not rs.bof then

rs.addnew

rs("UserName")=trim(request.form("username"))

rs("PassWord")=trim(request.form("password"))

rs("Email")=trim(request.form("useremail"))

rs("Phone")=trim(request.form("quesion"))

rs("Adress")=trim(request.form("answer"))

rs("Picture")=trim(request.form("picture"))

rs.update

rs.close

set rs=nothing

'set upload=new upload_5xsoft

' set file=upload.file("picture")

' dim upfilename,ufn,upfileext,ufp

' upfilename = split(file.FileName,"\")

' ufn = split(file.FileName,".")

' upfileext = ufn(ubound(ufn))

' if upfileext<>"jpg" and upfileext<>"jpeg" and upfileext<>"gif" and upfileext<>"JPG" and upfileext<>"JPEG" and upfileext<>"GIF" and upfileext<>"png" and upfileext<>"PNG"then

' response.write "错误:上传的文件格式不对! <a href='javascript:history.go(-1)'>退回上一步</a>"

' response.end

' end if

' ufp=upfilename(ubound(upfilename))//保存的文件名称

' file.saveas Server.mappath("images/"&ufp)//文件的保存路径

%>

<table width=500 height=30 border=0 align=center cellpadding=0 cellspacing=1>

<tr>

<td width="500" bgcolor=#FFFFFF>友情提示·恭喜你已经注册成功!

<a href=uesr_login.asp style="text-decoration:none"><font color=red>[点击马上登陆]</font></a></td>

</tr>

</table>

<%

end if

end sub

%>

<%

dim excelstring

dim excelstr

dim excelstr2

dim head

excelstring = ""

head = "Sn" &"," &"Reason" &"如伏中," &"Empid" &"," &"Empname" &"," &"Ext" &"," &"Depname" excel="creat"

If excel<>""

Then

Set rs2 = Server.CreateObject ("ADODB.Recordset")

sql2 = "Select * from value_table "

rs2.open sql2,conn,1,3 do while not rs2.eof excelstr =" " &rs2(0) &""",""" &rs2(1) &""",""" &rs2(2) &""",""" &rs2(3) &""",""" &rs2(4) &""",""" &rs2(5) &"""" excelstr2 = excelstr2 &Chr(13) &excelstr rs2.movenext loop excelstring = head &Chr(13)&excelstr2 'response.Write(excelstring) 'rs2.close

Set rs2=Nothing

set fs = CreateObject("scripting.FileSystemObject")

set exc = fs.OpenTextFile(server.MapPath("excel.csv"),2,True) exc.write(excelstring) if fs.FileExists(Server.MapPath("excel.csv"))

then Response.Write("<a href=excel.csv>报表已经生厅卜成,点击查看</a>") 'Response.write(excelstring) else Response.Write("生成报表失败渣山!") end if End if%>


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12410571.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存