如何使用Repeater控件的模板

显示结果

页眉模板--人员信息

页脚模板--显示结束



源代码

     private   void  Page_Load( object  sender, System.EventArgs e)
        
{
            
//页面初试化时进行数据绑定
            if(!IsPostBack)
                RepeaterDataBind();
        }


        
private   void  RepeaterDataBind()
        
{
            
//定义数据连接对象,其中数据库连接字符串是在Web.Config文件中定义的
            SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionSqlServer"].ToString());
            
//创建数据适配器对象
            SqlDataAdapter da = new SqlDataAdapter("select LastName,FirstName,TitleOfCourtesy from Employees",conn);
            
//创建DataSet对象
            DataSet ds = new DataSet();
            
try
            
{
                
//填充数据集
                da.Fill(ds,"testTable");
                
//进行数据绑定
                RepeaterTem.DataSource = ds.Tables["testTable"];
                RepeaterTem.DataBind();
            }

            
catch(Exception error)
            
{
                Response.Write(error.ToString());
            }
        
        }


页面代码 < asp:Repeater id = " RepeaterTem "  runat = " server " >
                
< HeaderTemplate >
                    
< h3 > 页眉模板--人员信息 </ h3 >
                    
< table >
                
</ HeaderTemplate >
                
< ItemTemplate >
                    
< font color = " blue " >
                        
<% #DataBinder.Eval(Container.DataItem, " TitleOfCourtesy " ) %>
                        
<% #DataBinder.Eval(Container.DataItem, " LastName " ) %>
                        
<% #DataBinder.Eval(Container.DataItem, " FirstName " ) %>
                    
</ font >
                
</ ItemTemplate >
                
< AlternatingItemTemplate >
                    
< font color = " red " >
                        
<% #DataBinder.Eval(Container.DataItem, " TitleOfCourtesy " ) %>
                        
<% #DataBinder.Eval(Container.DataItem, " LastName " ) %>
                        
<% #DataBinder.Eval(Container.DataItem, " FirstName " ) %>
                    
</ font >
                
</ AlternatingItemTemplate >
                
< SeparatorTemplate >
                    
< hr color = " #green "  width = " 100% " >
                
</ SeparatorTemplate >
                
< FooterTemplate >
                    
</ TABLE >
                    
< h3 > 页脚模板--显示结束 </ h3 >
                
</ FooterTemplate >
            
</ asp:Repeater >


<script type="text/javascript"> // </script>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值