|
![]() |
名片设计 CorelDRAW Illustrator AuotoCAD Painter 其他软件 Photoshop Fireworks Flash |
|
注)下面的代码是页面的代码,只贴了Repeater部分的代码,因为要绑定数据,如()所以在使用之前要先导入名空间 <asp:repeater id="Repeater1" runat="server"> <HeaderTemplate> <table?border="0"> <tr?bgcolor="#999999"> <td>产品类型IDtd> <td>产品类型名称td><td>产品类型描述td> <td> td> <tr> <HeaderTemplate> <ItemTemplate> <tr?bgcolor=#ffffff> <td><img src=".iamgesattachtb.gif"> <td> <td> <td> <td>td> <td><asp:ImageButton ID="show"ImageUrl=".iamgesmore.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=".iamgesmore.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=".iamgesmore.gif",由于BLOG对代码的支持有问题,所以被自动截取掉了) 返回类别: 教程 上一教程: 利用ASP实现对表的分页浏览 下一教程: 用两种不同的方式来求实现数字字符串的最大,最小和平均值 您可以阅读与"使用REPEATER模板"相关的教程: · 使用模板实现ASP代码与页面分离 · 使用 XML 模板 · 使用XML+VBS技术在ASP中实现报表的打印 · 用ASP文件实现CPU的使用率始终保持100% · 要如何使用 ASP Error 组件? |
![]() ![]() |
快精灵印艺坊 版权所有 |
首页![]() ![]() ![]() ![]() ![]() ![]() ![]() |