复制代码 代码如下:<formrunat="server">
<asp:DataGridAutoGenerateColumns="false"OnItemCreated="itemcreate"DataKeyField="link_id"ID="mydg"runat="server">
<columns>
<asp:TemplateColumn>
<headertemplate>
<asp:CheckBoxID="checkall"OnCheckedChanged="chkall_onchanged"AutoPostBack="true"runat="server"></asp:CheckBox>
</headertemplate>
<itemtemplate>
<asp:CheckBoxID="checkdel"runat="server"></asp:CheckBox>
</itemtemplate>
</asp:TemplateColumn>
<asp:BoundColumnDataField="link_id"HeaderText="Link_Id"></asp:BoundColumn>
<asp:BoundColumnHeaderText="网站名称"DataField="sitename"/>
<asp:BoundColumnHeaderText="网站地址"DataField="url"/>
<asp:BoundColumnHeaderText="网站介绍"DataField="intro"/>
<asp:BoundColumnHeaderText="网站评分"DataField="grade"/>
<asp:BoundColumnHeaderText="提交时间"DataField="submit_date"></asp:BoundColumn>
</columns>
</asp:DataGrid>
<asp:LabelID="lb1"runat="server"></asp:Label>
<asp:ButtonID="btn1"Text="删除"runat="server"OnClick="btn1_onclick"></asp:Button>
<asp:ButtonID="ok"OnClick="ok_click"Text="保存修改"runat="server"></asp:Button>
<asp:ButtonID="cancel"OnClick="cancel_click"Text="取消修改"runat="server"></asp:Button>
</form>
<%@importnamespace="system.data"%>
<%@importnamespace="system.data.oledb"%>
<scriptlanguage="vb"runat="server">
dimconnasoledbconnection
dimdsasdataset
subPage_load(senderasobject,easeventargs)
ifnotispostbackthen
calldb()
else
ds=session("ds")
endif
endsub
subcalldb()
conn=newoledbconnection("provider=Microsoft.jet.oledb.4.0;datasource="&server.MapPath("wwwlink.mdb"))
dimsqlstr="select*fromlink"
conn.open()
dimadpasnewoledbdataAdapter(sqlstr,conn)
ds=newdataset()
adp.fill(ds,"link")
mydg.DataSource=ds.tables("link").defaultview
mydg.databind()
conn.close()
session("ds")=ds
endsub
subbtn1_onclick(senderasobject,easeventargs)
dimchkascheckbox
dimidasstring
dimdatagasdatagriditem
conn=newoledbconnection("provider=Microsoft.jet.oledb.4.0;datasource="&server.MapPath("wwwlink.mdb"))
dimsqlstrasstring
dimcmdasoledbcommand
dimiasinteger
'foreachdataginmydg.items
fori=0tomydg.items.count-1
'chk=ctype(datag.findcontrol("checkdel"),checkbox)
'chk=datag.findcontrol("checkdel")
chk=mydg.items(i).cells(0).findcontrol("checkdel")
ifchk.checkedthen
id=cstr(mydg.items(i).cells(1).text)
'id=cstr(mydg.datakeys(datag.itemindex))
conn.open()
sqlstr="deletefromlinkwherelink_id="&id
cmd=newoledbcommand(sqlstr,conn)
cmd.executenonquery
'ds.tables("link").rows(i).delete()
conn.close()
endif
next
'session("ds")=ds
'mydg.edititemindex=-1
'mydg.datasource=ds.tables("link").defaultview
'mydg.databind()
calldb()
endsub
subcancel_click(senderasobject,easeventargs)
calldb()
endsub
subok_click(senderasobject,easeventargs)
conn=newoledbconnection("provider=Microsoft.jet.oledb.4.0;datasource="&server.MapPath("wwwlink.mdb"))
dimadpasnewoledbdataadapter("select*fromlink",conn)
dimocbasnewoledbcommandbuilder(adp)
adp.updatecommand=ocb.getupdatecommand()
adp.deletecommand=ocb.getdeletecommand()
adp.update(ds,"link")
calldb()
endsub
dimcheckaascheckbox
subitemcreate(senderasobject,easdatagriditemeventargs)
if(e.item.itemtype=Listitemtype.Header)then
checka=e.item.findcontrol("checkall")
endif
endsub
subchkall_onchanged(senderasobject,easeventargs)
dimiasinteger
ifchecka.checked=truethen
fori=0tomydg.items.count-1
dimchkascheckbox=mydg.items(i).cells(0).findcontrol("checkdel")
chk.checked=true
next
else
fori=0tomydg.items.count-1
dimchkascheckbox=mydg.items(i).cells(0).findcontrol("checkdel")
chk.checked=false
next
endif
endsub
</script>