Posted on 2008-07-25 14:10
『牙签』 阅读(13)
评论(0) 编辑 收藏 所属分类:
ASP.NET 1.0

<%
@ import namespace="system.data" %>

<%
@ import namespace="system.data.oledb" %>

<%
@ import namespace="databasenamespace" %>

<html>
<head>

<script runat="server">
dim myconn as oledbConnection
dim mycomm as oledbDataAdapter
dim ds as new dataset
dim connstr as string
dim sqlstr as string
dim sortField as string
dim cmdsql as oledbcommand
sub page_load(a as object,e as eventargs)
if ispostback then exit sub
if session("LoginID")<>"0" then
response.redirect("admin_index.aspx")
end if
connstr=ConfigurationSettings.AppSettings("connstr").ToString()
myconn=new oledbconnection(connstr)
if not (ispostback)
if sortField="" then
sortField="Uid"
end if
bind
end if
end sub

sub Bind()
sqlstr="select * from [User] where Ucode='"& id &"'"
mycomm=new oledbdataadapter(sqlstr,myconn)
mycomm.fill(ds,"user")
dim dv2 as dataview
dv2=ds.tables("user").defaultview
dv2.sort=sortfield
grid1.datasource=dv2
grid1.databind()
end sub

sub mygriddata_page(s as object,e as datagridPageChangedEventargs)
grid1.currentpageindex=e.newpageindex
bind
end sub
sub mygriddata_Sort(s as object,e as datagridSortCommandEventargs)
sortField=e.sortExpression
bind
end sub
sub Grid_edit( s as object ,e as datagridcommandeventargs)
grid1.edititemindex=e.item.itemindex
bind()
end sub
sub Grid_cancel( s as object ,e as datagridcommandeventargs)
grid1.edititemindex=-1
bind()
end sub
SUB GRID_UPDATE(S AS OBJECT, e AS datagridcommandeventargs)
dim code as string
dim name as string
dim job as string
dim pwd as string
dim email as string
dim phone as string
dim add as string
dim myTextBox as textbox
dim Uid as string=grid1.datakeys.item(e.item.itemindex).tostring
mytextbox=e.item.findcontrol("edit_code")
code=mytextbox.text
mytextbox=e.item.findcontrol("edit_name")
name=mytextbox.text
mytextbox=e.item.findcontrol("edit_job")
job=mytextbox.text
mytextbox=e.item.findcontrol("edit_pwd")
pwd=mytextbox.text
mytextbox=e.item.findcontrol("edit_email")
email=mytextbox.text
mytextbox=e.item.findcontrol("edit_phone")
phone=mytextbox.text
mytextbox=e.item.findcontrol("edit_add")
add=mytextbox.text
sqlstr="Update [user] set Ucode='"& code &"',Uname='" & name & "',Ujob='" & job & "',Upwd='"& pwd &"',Uemail='"& email &"',Uphone='"& phone &"',Uadd='"& add &"' where Uid =" & Uid & ""
cmdsql= new oledbcommand(sqlstr,myconn)
myconn.open()
cmdsql.ExecuteNonquery()
myconn.Close()
grid1.edititemindex=-1
bind()
END SUB
</script>

<link href="../other/css.css" rel="stylesheet" style="text/css">
</head>

<body>
<form runat="server">
<asp:datagrid id="grid1" runat="server"
Autogeneratecolumns="false" backcolor="white"
width=800 boarderwidth="1px" borderstyle="solid" bordercolor="tan" cellpadding="2" cellspacing="0"
font-name="宋体" font-size="10pt" allowpaging="true" pagesize="5" horizontalalign=center
pagerstyle-mode="numericPages" Pagestyle-nextpagetext="Next"
Pagestyle-PrevpageText="Prev" PageStyle-Horizontalalign="right"
onPageIndexChanged="myGriddata_page" allowsorting="true" onsortCommand="mygriddata_Sort"
ONEDITCOMMAND="GRID_EDIT" ONuPDATECOMMAND="GRID_UPDATE" oncancelcommand="grid_cancel" datakeyfield="Uid">
<columns>
<asp:boundcolumn headertext="按正序排列" readonly="true" datafield="uid" sortExpression="uid">
<headerstyle width="65px"></headerstyle>
</asp:boundcolumn>

<asp:editcommandcolumn edittext="修改" canceltext="返回" updatetext="确认" itemstyle-wrap="false"
headertext="修改资料" headerStyle-wrap="false"/>
<asp:templatecolumn headertext="ID">
<itemtemplate>
<asp:label text='<%# Container.dataitem("Ucode") %>' runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="edit_code" text='<%# container.dataitem("Ucode") %>' runat="server" />
</edititemtemplate>
<headerstyle width="60px"></headerstyle>
</asp:templatecolumn>

<asp:templatecolumn headertext="姓名">
<itemtemplate>
<asp:label text='<%# Container.dataitem("Uname") %>' runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="edit_name" text='<%# container.dataitem("Uname") %>' runat="server" />
</edititemtemplate>
<headerstyle width="60px"></headerstyle>
</asp:templatecolumn>

<asp:templatecolumn headertext="职 称">
<itemtemplate>
<asp:label text='<%# Container.dataitem("Ujob") %>' runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="edit_job" text='<%# container.dataitem("Ujob") %>' runat="server" />
</edititemtemplate>
<headerstyle width="200px"></headerstyle>
</asp:templatecolumn>

<asp:templatecolumn headertext="密 码">
<itemtemplate>
<asp:label text='<%# Container.dataitem("Upwd") %>' runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="edit_pwd" text='<%# container.dataitem("Upwd") %>' textmode="password" runat="server" />
</edititemtemplate>
<headerstyle width="200px"></headerstyle>
</asp:templatecolumn>

<asp:templatecolumn headertext="电子邮件">
<itemtemplate>
<asp:label text='<%# Container.dataitem("Uemail") %>' runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="edit_email" text='<%# container.dataitem("Uemail") %>' runat="server" />
</edititemtemplate>
<headerstyle width="200px"></headerstyle>
</asp:templatecolumn>

<asp:templatecolumn headertext="联系电话">
<itemtemplate>
<asp:label text='<%# Container.dataitem("Uphone") %>' runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="edit_phone" text='<%# container.dataitem("Uphone") %>' runat="server" />
</edititemtemplate>
<headerstyle width="200px"></headerstyle>
</asp:templatecolumn>

<asp:templatecolumn headertext="联系地址">
<itemtemplate>
<asp:label text='<%# Container.dataitem("Uadd") %>' runat="server" />
</itemtemplate>
<edititemtemplate>
<asp:textbox id="edit_add" text='<%# container.dataitem("Uadd") %>' runat="server" />
</edititemtemplate>
<headerstyle width="200px"></headerstyle>
</asp:templatecolumn>
</columns>
<headerStyle backcolor="darkred" forecolor="white" font-bold="true"></headerstyle>
<itemstyle forecolor="darkslateblue" ></itemstyle>
<alternatingitemstyle backcolor="beige" />
</asp:datagrid>
</form>
</body>
</html>