欢迎光临
我们一直在努力

使用Repeater模板-ASP教程,ASP应用

建站超值云服务器,限时71元/月

注)下面的代码是页面的代码,只贴了repeater部分的代码,因为要绑定数据,如()所以在使用之前要先导入名空间

<asp:repeater id="repeater1" runat="server">

<headertemplate>

<table?border="0">

<tr?bgcolor="#999999">

<td>产品类型idtd>

<td>产品类型名称td><td>产品类型描述td>

<td>&nbsp;td>

<tr>

<headertemplate>

<itemtemplate>

<tr?bgcolor=#ffffff>

<td><img src=".iamgesattachtb.gif">

<td>

<td>

<td>

<td>td>

<td><asp:imagebutton id="show"imageurl=".\iamges\more.gif"

commandname="show" runat="server" />td>

<tr>

<itemtemplate>

<alternatingitemtemplate>

<tr bgcolor=#f5f2f7>

<td><img src=".iamgesattachtb.gif">

<td>

<td>td>

<td>td>

<td><asp:imagebutton id="imagebutton1" imageurl=".\iamge\smore.gif"

commandname="show" runat="server"/>

<td>

<tr>

alternatingitemtemplate>

<footertemplate>

<table>

<footertemplate>

asp:repeater>form>

<body>

<html>

后置代码部分:

先导入名空间:using system.data.sqlclient和using system.windows.forms;其余系统默认导入

下面是连接库的代码:

?

private void?connecdb()

{

sqlconnection con=new sqlconnection("server=localhost;database=northwind;trusted_connection=yes;");

sqldataadapter da=new sqldataadapter("select*from categories",con);

dataset ds=new dataset();

ad.fill(ds,"categories");

this.repeater1.datasource=ds;

this.repeater1.databind();//绑定到repeater控件

}

下面这段是repeater模板中的事件

private void repeater1_itemcommand(object sender,system.web.ui.webcontrols.repeatercommandeventargs e)

{

if(e.commandname=="show")

{

messagebox.show("you?click"+e.item.itemindex.tostring()+"row","a

show",messageboxbuttons.ok,messageboxicon.information,

messageboxdefaultbutton.button1,messageboxoptions.defaultdesktoponly);

}

else

{

messagebox.show("you?click?"+e.item.itemindex.tostring()+"

row","altshow",messageboxbuttons.ok,messageboxicon.information,

messageboxdefaultbutton.button1,messageboxoptions.defaultdesktoponly);

}

}

(注:1、必须在repeater模板事件中绑定上面方法到其itemcommand事件,在事件窗口中可以做到2、在上面的图片url应是 imageurl=".\iamges\more.gif",由于blog对代码的支持有问题,所以被自动截取掉了)

最终效果如下:

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 使用Repeater模板-ASP教程,ASP应用
分享到: 更多 (0)

相关推荐

  • 暂无文章