📄 newsmodify.aspx
字号:
<!--
接受来自newseditlist.aspx的id,对相应数据行进行修改
-->
<!--
通过本例得到的经验:
1、为表单中的输入控件赋初值。
2、确定下拉列表框的初选项。
-->
<%@ Page Language="VB" ContentType="text/html" debug="true" %>
<%@ Import Namespace="system.data" %>
<%@ Import Namespace="system.data.oledb" %>
<!--#include file="ckqx.aspx" -->
<html>
<head>
<title>修改新闻</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../CSS.CSS" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#CCCCCC">
<table width="549" height="400" cellpadding="0">
<tr>
<td height="263" valign="top">
<form runat="server">
<table width="549" height="22" border="0" cellpadding="0" cellspacing="0" background="../pic/002.png">
<tr>
<td><strong> <font color="#FFFFFF">修改新闻</font></strong></td>
</tr>
</table>
<table width="549" height="364" border="1" cellpadding="0" cellspacing="0" bordercolorlight="#008080" bordercolordark="#FFFFFF">
<tr>
<td height="362" valign="top" bgcolor="#FFFFFF">
<table width="545" height="305" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr valign="baseline">
<td width="48" ><div align="center">标题:</div></td>
<td> <asp:textbox BorderStyle="solid" BorderWidth="1" Font-Size="10" ID="ztitle" runat="server" TextMode="SingleLine" /> </td>
</tr>
<tr valign="baseline">
<td height="226" align="right" nowrap> <div align="center"><font color="#000000">内容:</font></div></td>
<td><asp:textbox BorderStyle="solid" BorderWidth="1" Columns="60" Font-Size="10" ID="zcontent" Rows="15" runat="server" TextMode="MultiLine" />
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><div align="center"><font color="#000000">发布人:</font></div></td>
<td><asp:dropdownlist BackColor="#00CCFF" DataTextField="btype" DataValueField="btype" Font-Size="10" ID="zsendmen" runat="server"></asp:dropdownlist>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"><div align="center"></div></td>
<td><asp:button Font-Size="10" ID="zok" runat="server" Text="修改" onclick="zmodifynews" /></td>
</tr>
</table></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
<script language="VB" runat="server">
sub page_loae(s as object,e as eventargs)
if not (checkqx("b")) then response.redirect("error.aspx")
'检查权限
end sub
sub zmodifynews(s as object,e as eventargs)
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("../office.mdb"))
conn.open()
dim objcmd as new oledbcommand()
objcmd.connection=conn
objcmd.commandtext="update news set otitle=?,ocontent=?,sendmen=? where id=" & request.querystring("id")
'objcmd.parameters.add("@otitle",oledbtype.char).value=request.form("ztitle")
objcmd.parameters.add("@otitle",oledbtype.char).value=ztitle.text
'注,这里不能使用ztitle.text属性来更新值,不知道是什么原因,待查。
'查出来了,在page_load事件中没有加入对Ispostback的检验,使得表单每次提交后都重复
'对各文本框赋初始值,使得更新无效果。此时的ztitle.text(所有文本框的值都一样)的值
'被还原成原始数据,而使用Request.form("ztitle")却仍然能得到修改后的数据。
objcmd.parameters.add("@ocontent",oledbtype.char).value=request.form("zcontent")
objcmd.parameters.add("@sendmen",oledbtype.char).value=request.form("zsendmen")
objcmd.executenonquery()
conn.close()
response.Redirect("newseditlist.aspx")
end sub
sub page_load(s as object,e as eventargs)
if not ispostback then bmlist
'当第一次打开网页时,对页面上所有的输入控件赋初值,使其值等于数据表中相应新闻的
'原始数据。
end sub
sub bmlist()
'对页面上所有的输入控件赋初值,使其值等于数据表中相应新闻的原始数据。
dim conn as new oledbconnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("../office.mdb"))
conn.open()
dim objada as new oledbdataadapter("select btype from btype",conn)
dim ds as new dataset()
objada.fill(ds,"btype")
zsendmen.datasource=ds
zsendmen.databind()
'以上代码得到部站列表,并绑定到对应的下拉列表控件
dim objcmd as new oledbcommand()
objcmd.connection=conn
objcmd.commandtext="select * from news where id=" & request.querystring("id")
dim objreader as oledbdatareader=objcmd.executereader()
'得到要修改的新闻所有数据
if not objreader.read() then
'检查是否有该条新闻存在,可避免错误输入
response.end()
else
ztitle.text=objreader.item("otitle")
'为标题文本框赋初值
zcontent.text=objreader.item("ocontent")
'为新闻内容文本框赋初值
dim lsbm as string=objreader.item("sendmen")
'保存当前新闻的发布人所在的部门
dim ii as ListItem
for each ii in zsendmen.items
'确定发布人所在部门的下拉列表框初选项
if ii.text=lsbm then ii.selected=true
next
end if
conn.close()
end sub
</script>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -