日期:2014-05-17 浏览次数:20773 次
<% sql="select * from rights" set rs=server.CreateObject("adodb.recordset") rs.open sql,conn,1,1 if not rs.eof then rights=rs.getrows() end if rs.close():set rs=nothing sql="select * from rightuser where username='小明'" set rs=server.CreateObject("adodb.recordset") rs.open sql,conn,1,1 do while not rs.eof userrights=userrights & rs("rid") & "," rs.movenext loop rs.close():set rs=nothing %> <style> table{ width:100%; border-collapse:collapse; border-spacing:0;} td{ border:1px solid red;} </style> <form action="" method="post" name="form1"> <table ><tr><td>用户</td><td>权限</td></tr> <tr><td>李明</td> <td> <%userrights="," & userrights for i=0 to ubound(rights,2) %> <input type="checkbox" name="cbox" value="<%=rights(0,i)%>" <%if instr(userrights,"," & rights(0,i) & ",")>0 then%>checked<%end if%>/><%=rights(1,i)%><input type="text" name="rtext" value="<%=rs("rname")%>"/> <% next %></td> </tr> <tr><td><input type="hidden" value="1" name="flag"><input type="submit" value="修改权限"></td></tr> </table> </form> <% If request.form("flag")=1 Then'如果提交了表单 '获取表单数据 Dim cbox cbox=Trim(request.form("cbox")) '先删除用户所有权限,再插入选中的权限 sql="delete from rightuser where username='小明'"'清空该用户的权限 conn.execute(sql) If cbox<>"" Then'有选中权限,则插入选中的权限 If InStr(cbox,",")>0 Then'当前选中多项 cbox=Split(cbox,",") For i=0 To UBound(cbox) sql="insert into rightuser(rid,username) values ("&cbox(i)&",'小明')" conn.execute(sql) next Else'当前只选中一项 sql="insert into rightuser(rid,username) values ("&cbox&",'小明')" conn.execute(sql) End If End If End If %>
sql="insert into rightuser(rid,username, rname) select rid, '小明', rname from rights where rid=" & cbox
------解决方案--------------------