asp.net Repeater 数据绑定的具体实现(图文详解)
来源:
中文源码网 浏览:180 次 日期:2024-04-27 12:58:37
【下载文档: asp.net Repeater 数据绑定的具体实现(图文详解).txt 】
asp.net Repeater 数据绑定的具体实现(图文详解)
以下为设计步骤:
1、在C# 中连接数据库。如下图:2、在项目中添加新建项,建立一个数据集,并把Categories从服务器资源列表中拖到这个数据集模板中并点击菜单“生成-生成解决方案”,如下图:
3、在aspx的webform上放一个ObjectDataSource控件,设定它的TypeName为刚刚建立的数据集类型,用它的向导建立即可。4、在aspx的webform上放一个Repeater控件,用它的向导设定它的DataSourceID为上面的ObjectDataSource5、在网页中设定它的源码,即加上
等模板。如下面的代码:
复制代码 代码如下:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Repeater.Default" %>
7、要求在类别名称中带"O"的编辑框显示红色,则写出以下代码:复制代码 代码如下:protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.AlternatingItem) {
TextBox tb = (TextBox)e.Item.FindControl("TextBox1"); if (tb.Text.Contains("o")) { tb.BackColor = Color.Red; } } }7、运行显示的效果为: