以下我学习教程的得到的代码,本身应是单击查看留言后就能展开留言,单击返回后能自动折叠,可是实际运行后,每个操作都要连续二次单击才能展开或折叠,请问这是为什么:
<%@import namespace="system.data"%>
<%@import namespace="system.data.oledb"%>
<html>
<form runat="server">
<asp:datalist id="dst" runat=server onitemcommand="ic_click">
<headertemplate>
<center>
<b>留言簿</b>
</center>
<hr width=85%>
</headertemplate>
<itemtemplate>
<%#container.dataitem("usere")%>
<%#container.dataitem("title")%>
<asp:linkbutton id="b1" runat=server text="查看留言"/>
</itemtemplate>
<selecteditemtemplate>
<center>
姓名:<%#container.dataitem("usere")%> <asp:linkbutton id="b2" runat=server text="返回"/><br>
电子邮件:<%#container.dataitem("email")%><br>
留言标题:<%#container.dataitem("title")%><br>
留言内容:<%#container.dataitem("content")%><br><br></center>
</selecteditemtemplate>
<footertemplate>
<hr>
</footertemplate>
</asp:datalist>
</form>
</html>
<script language="vb" runat=server>
sub play()
dim con as oledbconnection
dim constr as string
constr="Provider=SQLOLEDB.1;Persist Security Info=False;Server=(local);User ID=sa;Password=sa;Database=data;"
con=new oledbconnection(constr)
dim ada as oledbdataadapter
dim ds as dataset
con.open
dim sql as string
sql="select * from mail"
ada=new oledbdataadapter(sql,con)
ds=new dataset()
ada.fill(ds,"留言")
dst.datasource=ds.tables("留言")
dst.databind()
end sub
sub ic_click(sender as object,e as datalistcommandeventargs)
if e.commandsource.id="b1" then
dst.selectedindex=e.item.itemindex
elseif e.commandsource.id="b2"
dst.selectedindex=-1
end if
end sub
sub page_load(sender as object,e as eventargs)
play()
end sub
</script>