北京最新楼市,人大风采,张学兵近况
本文实例讲述了asp.net中repeater控件用法。分享给大家供大家参考。具体实现方法如下:
repeater绑定数据:
private void bindstudent()
{
string str = configurationmanager.connectionstrings["stucnn"].connectionstring;
using (sqlconnection sqlcnn = new sqlconnection(str))
{
using (sqldataadapter da = new sqldataadapter("select * from student", sqlcnn))
{
dataset ds = new dataset();
da.fill(ds);
this.repeater1.datasource = ds;
this.repeater1.databind();
}
}
}
删除数据:
前台:
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<%--<asp:repeater id="repeater1" runat="server">
<headertemplate>
<hr />
</headertemplate>
<itemtemplate><div>
<asp:label id="lblsid" runat="server" text='<%# eval("sid") %>'></asp:label>
<asp:label id="lblsname" runat='server' text='<%# eval("sname") %>'></asp:label>
<asp:image id="imgphoto" runat="server" imageurl='<%# eval("photo") %>' /></div>
</itemtemplate>
<separatortemplate>
<hr />
</separatortemplate>
<alternatingitemtemplate>
<div style="
<asp:label id="lblsid" runat="server" text='<%# eval("sid") %>'></asp:label>
<asp:label id="lblsname" runat='server' text='<%# eval("sname") %>'></asp:label>
<asp:image id="imgphoto" runat="server" imageurl='<%# eval("photo") %>' /></div>
</alternatingitemtemplate>
<footertemplate><hr /></footertemplate>
</asp:repeater>--%>
<div>
<asp:repeater id="repeater1" runat="server"
onitemcommand="repeater1_itemcommand">
<headertemplate><table>
<tr><td style="width:100px">编号</td><td style="width:100px">姓名</td>
<td style="width:100px">图片</td><td> </td><td> </td></tr>
</headertemplate>
<itemtemplate>
<tr>
<td><%# eval("sid") %></td><td><%# eval("sname") %></td>
<td><img width="60px" height="60px" src='<%# "images/" + eval("photo") %>' /></td>
<td><asp:linkbutton id="btndelete" runat="server" text="删除" commandname='delete' commandargument='<%# eval("sid") %>'></asp:linkbutton></td>
<td><asp:linkbutton id="btnedit" runat="server" text="编辑" commandname='edit' commandargument='<%# eval("sid") %>'></asp:linkbutton></td>
</tr>
</itemtemplate>
<alternatingitemtemplate>
<tr style="
<td><%# eval("sid") %></td><td><%# eval("sname") %></td>
<td><img width="60px" height="60px" src='<%# "images/" + eval("photo") %>' /></td>
<td><asp:linkbutton id="btndelete" runat="server" text="删除" commandname='delete' commandargument='<%# eval("sid") %>'></asp:linkbutton></td>
<td><asp:linkbutton id="btnedit" runat="server" text="编辑" commandname='edit' commandargument='<%# eval("sid") %>'></asp:linkbutton></td>
</tr>
</alternatingitemtemplate>
<separatortemplate>
<tr><td colspan="5"><hr /></td></tr>
</separatortemplate>
<footertemplate></table></footertemplate>
</asp:repeater>
</div>
</form>
</body>
</html>
启用,禁用:
<%@ page language="c#" autoeventwireup="true" codefile="default2.aspx.cs" debug="true" inherits="default2" %>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:repeater id="repeater1" runat="server"
onitemcommand="repeater1_itemcommand">
<headertemplate><table><tr><th>编号</th><th>姓名</th><th>状态</th><th> </th></tr></headertemplate>
<itemtemplate>
<tr><td><%# eval("sid") %></td>
<td><%# eval("sname") %></td>
<td><%# convert.toboolean(eval("status"))?"启用":"禁用" %></td>
<td><asp:linkbutton id="btnsetstatus" runat="server" commandargument='eval("sid")' text='<%# convert.toboolean(eval("status"))?"禁用":"启用" %>' commandname='<%# convert.toboolean(eval("status"))?"false":"true" %>'></asp:linkbutton></td></tr>
</itemtemplate>
<footertemplate></table></footertemplate>
</asp:repeater>
</div>
</form>
</body>
</html>
希望本文所述对大家的asp.net程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
asp.net搭建博客,使用BlogEngine.NET+MySql搭建博客
网友评论