ASP

本类阅读TOP10

·asp常用数据库连接方法和技巧
·无组件生成BMP验证码
·一些常用的辅助代码 (网络收藏)
·JavaScript实现的数据表格:冻结列、调整列宽和客户端排序
·VisualStudio.NET_2003及其 MSDN 下载地址
·ASP模拟MVC模式编程
·图片以二进制流输出到网页
·MD5加密算法 ASP版
·ASP.NET编程中的十大技巧
·改进 ASP 的字符串处理性能

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
使用Repeater模板

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

(注)下面的代码是页面的代码,只贴了Repeater部分的代码,因为要绑定数据,如(<%# DataBinder.Eval

(Container.DataItem,"CategoryName") %>)所以在使用之前要先导入名空间<%@ Import Namespace="System.Data" %>

<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对代码的支持有问题,所以被自动截取掉了)

最终效果如下:Repeater配图




相关文章

相关软件