本文主要是介绍复选框、布尔型数据在列表、添加、修改、查询中的显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1、 数据库数据结构
2、程序代码
<title>asp checkbox</title>
</head>
<body>
<%
action=Request("action")
If action="list" Then
listinfo
ElseIf action="add" Then
addinfo
ElseIf action="insert" Then
insertInfo
ElseIf action="edit" Then
keyId=request("keyId")
editinfo keyId
ElseIf action="update" Then
updateinfo
End If
%>
<%'列表页面
Sub listinfo()
Set rs=Server.CreateObject("ADODB.RecordSet")
trainType2=Request("trainType2")
strsql="select keyid,student_name,trainType1,trainType2,trainType3 from stu_Ejjz where 1=1"
If len(request("trainType2"))>0 Then
strsql=strsql&"and trainType2='"&trainType2&"'"
End If
rs.Open strsql,con,1,3
%>
<form action="?action=list">
<input type="hidden" name="action" value="list" />
视频<select name="trainType2">
<option value="">请选择</option>
<option value="1" <%=isSelect(1,trainType2)%> >是</option>
<option value="0" <%=isSelect(0,trainType2)%> >否</option>
</select>
<input type="submit" value="查询" />
</form>
<a href="aspcheckbox.asp?action=add">增加</a>
<table border=1 bordercolor="#000000" cellpadding="0" cellspacing="0" >
<tr>
<td>姓名</td>
<td>面授</td>
<td>视频</td>
<td>网络</td>
<td>冲刺</td>
</tr>
<%
Do While Not rs.Eof
%>
<tr>
<td align="center"><a href="aspcheckbox.asp?action=edit&keyid=<%=rs("keyid")%>"><%=rs("student_name")%></a></td>
<td align="center"><%=displayIsChecked(rs("trainType1"))%></td>
<td align="center"><%=displayIsChecked(rs("trainType2"))%></td>
<td align="center"><%=displayIsChecked(rs("trainType3"))%></td>
<td align="center"><%=displayIsChecked(rs("trainType3"))%></td>
</tr>
<%
rs.MoveNext
Loop
rs.Close
set rs=nothing
%>
</table>
<%
End Sub
%>
<%'添加新记录页面
Sub addinfo()
%>
<form action="?action=insert" method="post">
<table border="1" bordercolor="#000000">
<tr>
<td>姓名</td><td><input type="text" name="student_name" /></td>
</tr>
<tr>
<td>学习方式</td>
<td>
面授<input type="checkbox" name="trainType1" value="1" />
视频<input type="checkbox" name="trainType2" value="1" />
冲刺<input type="checkbox" name="trainType3" value="1" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交" /></td>
</tr>
</table>
<%
End Sub
%>
<%'编辑记录页面
Sub editinfo(keyid)
If keyid="" Or keyid=null Or isEmpty(keyid) Then
Response.Write("参数错误!!!")
Response.End()
Else
Set rs=Server.CreateObject("ADODB.RecordSet")
strSql="Select * From stu_Ejjz where keyid="&keyid
rs.Open strSql,con,1,3
If Not rs.Eof Then
%>
<form action="?action=update" method="post">
<input type="hidden" name="keyid" value="<%=rs("keyid")%>" />
<table border="1" bordercolor="#000000">
<tr>
<td>姓名</td><td><input type="text" name="student_name" value="<%=rs("student_name")%>" /></td>
</tr>
<tr>
<td>学习方式</td>
<td>
面授<input type="checkbox" name="trainType1" value="1" <%=checkBoxValue(rs("trainType1"))%>/>
网络<input type="checkbox" name="trainType2" value="1" <%=checkBoxValue(rs("trainType2"))%>/>
冲刺<input type="checkbox" name="trainType3" value="1" <%=checkBoxValue(rs("trainType3"))%>/>
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="提交" /></td>
</tr>
</table>
<%
rs.Close
Set rs=Nothing
End If
End If
End Sub
%>
<% '添加新数据逻辑层
Sub insertInfo()
student_name=Request.Form("student_name")
trainType1=Request.Form("trainType1")
trainType2=Request.Form("trainType2")
trainType3=Request.Form("trainType3")
sqlstr="insert into stu_Ejjz (student_name,trainType1,trainType2,trainType3) values('"&student_name&"','"&trainType1&"','"&trainType2&"','"&trainType3&"')"
con.execute(sqlstr)
%>
添加成功!!!<a href="aspcb.asp?action=list">返回</a>
<%
End Sub
%>
<% '更新数据逻辑层
Sub updateInfo()
keyid=Request("keyId")
student_name=Request.Form("student_name")
trainType1=Request.Form("trainType1")
trainType2=Request.Form("trainType2")
trainType3=Request.Form("trainType3")
sqlstr="update stu_Ejjz set student_name='"&student_name&"',trainType1='"&trainType1&"',trainType2='"&trainType2&"',trainType3='"&trainType3&"' where keyId="&keyid
con.execute(sqlstr)
%>
更新成功!!!<a href="aspcb.asp?action=list">返回</a>
<%
End Sub
%>
<%
'从数据库读出布尔型数据显示在页面
Function checkBoxValue(booleanValue)
If booleanValue=true Then
checkBoxValue="checked"
Else
checkBoxValue=""
End If
End Function
'列表上显示勾
Function displayIsChecked(booleanValue)
If booleanValue=true Then
displayIsChecked="√"
Else
displayIsChecked=" "
End If
End Function
'查询页面传参数,在新页面下拉列表中的显示判断
Function isSelect(strValue,strText)
If strText="" Then
Exit Function
ElseIf Int(strValue)=Int(strText) Then
isSelect="selected"
Else
isSelect=""
End If
End Function
%>
</body>
</html>
这篇关于复选框、布尔型数据在列表、添加、修改、查询中的显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!