关于datalist的问题

loepin 2003-12-12 08:33:46
请教datalist的selectedindex、edititemindex属性的用法。
...全文
77 23 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
xueyhfeng 2003-12-14
  • 打赏
  • 举报
回复
我写了个留言本,没写完,很乱,胡乱打个包给你吧,

邮件地址给我
loepin 2003-12-14
  • 打赏
  • 举报
回复
xueyhfeng:
有留言板的源码没?用数据库做数据源的,我对XML不懂。再次感谢一直以来你对我的帮助。

此贴马上要结了。不过分数不多,谁叫我穷啊。
loepin 2003-12-14
  • 打赏
  • 举报
回复
我改好了,以下可以运行:
<%@ Page Language="VB" ContentType="text/html" Debug="true"%>
<%@ import namespace="system"%>
<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient"%>
<script language="VB" runat="server">
sub page_load(sender as object,e as eventargs)
reg.visible=true
information.visible=false
end sub
sub retrieve()
dim myconnection as sqlconnection
myconnection=new sqlconnection("server=localhost;uid=sa;pwd=;database=lp")
myconnection.open()
dim adapter as sqldataAdapter
dim sqlstr as string
sqlstr="select * from message where id='"& username.text &"' and password='"& password.text & "'"
adapter=new sqldataadapter(sqlstr,myconnection)
dim DS as new dataset()
adapter.fill(DS,"info")
dim DT as datatable
DT=DS.tables("info")
if DT.rows.count=1 then
dim DV as dataview=DT.defaultview
display.datasource=dv
display.databind()
reg.visible=false
information.visible=true
else
response.Write("输入有误,请检查用户名和密码!")
end if
myconnection.close()
end sub
sub clickit(sender as object,e as eventargs)
retrieve()
end sub
sub datalist_itemcommand(sender as object,e as datalistcommandeventargs)
information.visible=true
reg.visible=false
select case e.commandsource.text
case "用户信息"
display.selectedindex=e.item.itemindex
retrieve()
case "关闭"
display.selectedindex=-1
retrieve()
case "修改信息"
display.editItemindex=e.Item.itemindex
retrieve()
case "取消"
display.edititemindex=-1
retrieve()
case "更新"
dim psd,repassword,ufond,grad,word as object
dim tbx as object
tbx=e.item.findcontrol("userfond")
ufond=tbx
tbx=e.item.findcontrol("gradu")
grad=tbx
tbx=e.item.findcontrol("userword")
word=tbx
tbx=e.item.findcontrol("pwd")
psd=tbx
tbx=e.item.findcontrol("repass")
repassword=tbx
if (psd.text<>repassword.text) then
response.Write("您两次输入的密码不相同,请从新输入。")
else
dim conn as sqlconnection
conn=new sqlconnection("server=localhost;uid=sa;pwd=;database=lp")
conn.open()
dim cmd as sqlcommand
dim sqlstr as string="update message set password='"& psd.text &"',fond='"& ufond.text &"',graduation='"& grad.text &"',leaveword='"& word.text &"' where id='"& username.text &"' and password='"& password.text &"'"
cmd=new sqlcommand(sqlstr,conn)
cmd.executenonquery()
response.Write("更新成功!")
try
catch exp as sqlexception
response.Write("更新失败!若需要更新,请从新开始。")
end try
conn.close()
display.edititemindex=-1
display.selectedindex=e.item.itemindex
end if
end select
end sub
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<title>the using of datalist</title>
</head>
<body>
<form runat="server">
<asp:panel id="reg" runat="server" BackColor="#aabbcc">
请输入用户姓名和密码:
<blockquote>
用户姓名:<asp:textbox id="username" runat="server"/><br>
用户密码:<asp:textbox id="password" runat="server" TextMode="Password"/><p>
<asp:button ID="btn" runat="server" Text="确认" OnClick="clickit"/>
</blockquote>
</asp:panel>
<asp:panel id="information" runat="server" BackColor="#aabbcc">
<asp:datalist id="display" runat="server" OnItemCommand="datalist_itemcommand">
<itemtemplate>
<%# container.dataitem("id") %>
<asp:linkbutton id="detail" runat="server" Text="用户信息"/>
<asp:linkbutton id="edit" runat="server" Text="修改信息"/>
</itemtemplate>
<selecteditemtemplate>
用户名字:<%# container.dataitem("id")%><br>
用户爱好:<%# container.dataitem("fond")%><br>
毕业院校:<%# container.dataitem("graduation")%><br>
用户留言:<%# container.dataitem("leaveword")%><br>
<asp:linkbutton id="title" runat="server" Text="关闭"/>
</selecteditemtemplate>
<edititemtemplate>
用户名字:<asp:label id="nameofuser" runat="server" Text='<%# container.dataitem("id")%>'/><br>
用户密码:<asp:textbox id="pwd" runat="server" TextMode="Password"/><br>
重复密码:<asp:textbox id="repass" runat="server" textmode="password"/><br>
用户爱好:<asp:textbox id="userfond" runat="server" TextMode="MultiLine"/><br>
毕业院校:<asp:textbox id="gradu" runat="server" TextMode="SingleLine"/><br>
用户留言:<asp:textbox id="userword" runat="server" TextMode="MultiLine"/><p>
<asp:linkbutton id="update" runat="server" Text="更新"/>
<asp:linkbutton id="cancel" runat="server" text="取消"/>
</edititemtemplate>
</asp:datalist>
</asp:panel>
</form>
</body>
</html>
xueyhfeng 2003-12-14
  • 打赏
  • 举报
回复
onClick ==>onServerClick

你把源代码贴一下,
loepin 2003-12-14
  • 打赏
  • 举报
回复
xueyhfeng:
我把onclick="clickit"改为onserverclick="clickit"后不再弹出那个错误提示框,不过点击[确认]按钮却没有任何反应。另外,将函数名clickit改为click也有一样的结果。
loepin 2003-12-14
  • 打赏
  • 举报
回复
我居然有一颗星了。:)
loepin 2003-12-14
  • 打赏
  • 举报
回复
loepin@yeah.net
loepin 2003-12-13
  • 打赏
  • 举报
回复
上楼:也就是说datalist.selectedindex可以显示selecteditemtemplate模版中的内容,而datalist.edititemindex则可以显示edititemtemplate模版中的内容吗?
Lostinet 2003-12-13
  • 打赏
  • 举报
回复
你可以认为这是DataBind()的参数.
在DataBind()的时候,
DataList/DataGrid 会把SelectedIndex,EditItemIndex指定的Item设置为指定的Style,
并且使Item有被选中或被编辑的功能。

loepin 2003-12-13
  • 打赏
  • 举报
回复


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>the using of datalist</title>
</head>
<body>
<form name="_ctl0" method="post" action="TMP7k7nrpu8j5.aspx" id="_ctl0">
<input type="hidden" name="__VIEWSTATE" value="dDwtMTEzNjI0OTM3O3Q8O2w8aTwxPjs+O2w8dDw7bDxpPDM+Oz47bDx0PHA8cDxsPFZpc2libGU7PjtsPG88Zj47Pj47PjtsPGk8MT47PjtsPHQ8QDA8Ozs7Ozs7Ozs+Ozs+Oz4+Oz4+Oz4+Oz7TvOVbWDiAEY+E+CJBMtppX6yQpw==" />

<div id="reg" style="background-color:#AABBCC;">

请输入用户姓名和密码:
<blockquote>
用户姓名:<input name="username" type="text" id="username" /><br>
用户密码:<input name="password" type="password" id="password" /><p>
<input name="button" id="button" type="button" value="确认" onClick="clickit" />
</blockquote>

</div>

</form>
</body>
</html>
xueyhfeng 2003-12-13
  • 打赏
  • 举报
回复
首先确保你已经在<input type="button" id="button" value="确认"/>上加了runat="server",

如果还有错误,就把你执行此页面后的html源文件贴出来(浏览器-查看-源文件)
loepin 2003-12-13
  • 打赏
  • 举报
回复
还是同样的错误!
xueyhfeng 2003-12-13
  • 打赏
  • 举报
回复
<input type="button" id="button" value="确认" onClick="clickit"/>
=======>
<input type="button" id="button" value="确认" onClick="clickit" runat="server"/>

怎么不行,还有什么错误?
loepin 2003-12-13
  • 打赏
  • 举报
回复
不行哦。
liuvb 2003-12-13
  • 打赏
  • 举报
回复
试一下:
<input type="button" id="button" value="确认" onClick="clickit" runat=server />
loepin 2003-12-13
  • 打赏
  • 举报
回复
看看这个问题:
<%@ Page Language="VB" ContentType="text/html"%>
<%@ import namespace="system"%>
<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient"%>
<script language="VB" runat="server">
sub page_load(sender as object,e as eventargs)
reg.visible=true
information.visible=false
end sub
sub retrieve()
dim myconnection as sqlconnection
myconnection=new sqlconnection("server=localhost;uid=sa;pwd=;database=lp")
myconnection.open()
dim adapter as sqldataAdapter
dim sqlstr as string
sqlstr="select * from message where id='" & username.text & "' and password='" & password.text & "'"
adapter=new sqldataadapter(sqlstr,myconnection)
dim DS as new dataset()
adapter.fill(DS,"info")
dim DT as datatable
DT=DS.tables("info")
if DT.rows.count=1 then
dim DV as dataview=DT.defaultview
display.datasource=dv
display.databind()
reg.visible=false
information.visible=true
else
response.Write("输入有误,请检查用户名和密码!")
end if
myconnection.close()
end sub
sub clickit(sender as object,e as eventargs)
retrieve()
end sub
sub datalist_itemcommand(sender as object,e as datalistcommandeventargs)
information.visible=true
reg.visible=false
select case e.commandsource.text
case "用户信息"
display.selectedindex=e.item.itemindex
retrieve()
case "关闭"
display.selectedindex=-1
retrieve()
end select
end sub
</script>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>the using of datalist</title>
</head>
<body>
<form runat="server">
<asp:panel id="reg" runat="server" BackColor="#aabbcc">
请输入用户姓名和密码:
<blockquote>
用户姓名:<asp:textbox id="username" runat="server"/><br>
用户密码:<asp:textbox id="password" runat="server" TextMode="Password"/><p>
<input type="button" id="button" value="确认" onClick="clickit"/>
</blockquote>
</asp:panel>
<asp:panel id="information" runat="server" BackColor="#9933FF">
<asp:datalist id="display" runat="server">
<itemtemplate>
<%# container.dataitem("id") %>
<asp:linkbutton id="detail" runat="server" Text="用户信息"/>
<asp:linkbutton id="edit" runat="server" Text="修改信息"/>
</itemtemplate>
<selecteditemtemplate>
用户名字:<%# container.dataitem("id") %><br>
用户爱好:<%# container.dataitem("fond") %><br>
毕业院校:<%# container.dataitem("graduation") %><br>
用户留言:<%# container.dataitem("leaveword") %><br>
<asp:linkbutton id="title" runat="server" Text="关闭"/>
</selecteditemtemplate>
<edititemtemplate>
用户名字:<asp:label id="nameofuser" runat="server"
Text=' <%# container.dataitem("id") %>' /><br>
用户密码:<asp:textbox id="pwd" runat="server" TextMode="Password"/><br>
重复密码:<asp:textbox id="repass" runat="server" textmode="password"/><br>
用户爱好:<asp:textbox id="userfond" runat="server" TextMode="MultiLine"/><br>
毕业院校:<asp:textbox id="gradu" runat="server" TextMode="SingleLine"/><br>
用户留言:<asp:textbox id="userword" runat="server" TextMode="MultiLine"/><p>
<asp:linkbutton id="update" runat="server" Text="更新"/>
<asp:linkbutton id="cancel" runat="server" text="取消"/>
</edititemtemplate>
</asp:datalist>
</asp:panel>
</form>
</body>
</html>

调试是老是弹出一个出错的对话框,有如下的提示:
该网叶的问题可能使其无法正常显示或功能不正常。以后,双击显示在状态栏中的警告图标,就可以显示上述信息。
点击上面的[隐藏详细信息]按钮后有如下显示:
行:18
字符:1
错误:'clickit'未定义
代码:0
url:……

我不明白明明已经定义了clickit,可是为什么还有这样的显示呢?请指教。谢谢。
liuvb 2003-12-13
  • 打赏
  • 举报
回复
纠正一点,
FindControl不仅仅是查找datagrid中的服务器控件
liuvb 2003-12-13
  • 打赏
  • 举报
回复
通俗一点:
FindControl就是查找用datagrid绑定的服务器控件,比如:
TextBox teJia;
teJia=(TextBox)searchproDataGrid.Items[i].FindControl("tj");
上面能够得到绑定到datagird中的textbox内的值。
loepin 2003-12-13
  • 打赏
  • 举报
回复
利用如 ItemsList.DataSource = CreateDataSource();
ItemsList.DataBind();
这样的语句是不是就可以显示出datalist中itemtemplate所规定的式样?
loepin 2003-12-13
  • 打赏
  • 举报
回复
不是很明白。
:)
加载更多回复(3)

62,243

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧