上一篇:使用递归获取网站下的所有同类型文件 >>
使用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=".\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对代码的支持有问题,所以被自动截取掉了)
最终效果如下:
下一篇:手牵手系列(一):开篇寄语 >>
相关文章:
- · 让我意外的IsNumeric()函数
- · 如何防止同一帐户重复登录系统
- · 关于view的触发器的例子
- · CIO成败的关键-ASP.NET开发工具助CIO重新定位
- · 测试Trackback II
- · 测试Trackback
- · Session使用注意事项
- · 《简单实现Crystal Report动态加载》补遗
- · 用ASP实现简单的繁简转换
- · 也谈绑定dropdownlist(3)
- · 内容管理系统的设计和选型
- · 一点准程序员工作经验总结
- · 给网站添加一个注册表 之 “类的应用”
- · asp分页的一个类
- · 提高网站在Google中的排名 ——面向搜索引擎的网站设计
- · 可缓存的CMS(网站内容管理器)系统设计
- · 把Web Control导出为Excel或Word
- · 如何实现立体的DataGrid和具有Windows效果的图片按钮
- · 一点ASP问题、差错和个人心得
- · 通过实例来实现split的理解
- · Asp.Net结合JS在图层上显示记录信息
- · Asp.net中如何处理一个站点不同Web应用通用Session的问题
- · css样式表的优先级别演示
- · 整理一个树型问题的解决方法
- · asp.net环境下的cmd命令执行
- · 常用javascript
- · 后台遍历一个HTML页面
- · 关于html上脚本语言的一点小释疑
- · 给网站添加一个注册表 之 “类的实现”
- · 给网站添加一个注册表 之 “类的设计”
- · 一个简单的上传类
- · 计数器的另一用法:自动切换首页图片
- · 性能微调提示
- · ASP.net中上传文件的操作
- · 对asp和asp程序员的一些话。。。
- · 英文版的Visual Studio.Net 2003 快捷键!
- · 如何定时运行ASP文件(转载)
- · 开发wap网站,还是碰到不少问题
