繁体中文
设为首页
加入收藏
当前位置:ASP技术首页 >> ASP基础 >> 使用Repeater模板

使用Repeater模板

2006-05-15 08:00:00  作者:  来源:互联网  浏览次数:0  文字大小:【】【】【
简介:注)下面的代码是页面的代码,只贴了Repeater部分的代码,因为要绑定数据,如()所以在使用之前要先导入名空间 产品类型IDtd> 产品类型名称td>产品类型描述td> td> td> CommandName="show" Runat="server" />...
关键字:Repeater 模板

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

产品类型IDtd>

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

td>

td>

CommandName="show" Runat="server" />td>

td>

td>

CommandName="show" Runat="server"/>

AlternatingItemTemplate>

asp:repeater>form>

后置代码部分:

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

最终效果如下:

责任编辑:admin
相关文章