Repeater的复杂使用讲解实例子

Repeater的复杂使用讲解实例子

在CSDN上看到大家问这到这种贴子,晚上回家想了下大概做下了

做得不完全,给大家一种思想吧(用到的嵌套Repeater控件)有些出入,楼主可自已再改动下,

http://topic.csdn.net/u/20080414/22/b54c735c-b2c0-4225-9a25-080d1309b168.html

 

 

代码:

 

<% @ Page Language="C#" AutoEventWireup="true" CodeFile="Test_GridView8.aspx.cs" Inherits="GridView_Test_GridView8"  %>

<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
< html  xmlns ="http://www.w3.org/1999/xhtml" >
< head  runat ="server" >
    
< title > 无标题页 </ title >
</ head >
< body >
    
< form  id ="form1"  runat ="server" >
        
< asp:Repeater  runat ="server"  ID ="objRepeater" >
            
< HeaderTemplate >
                
< table >
                    
< tr >
                    
</ tr >
                    
< th >
                        供应商
</ th >
                                            
< th  width ="250px" >
                        供应商2
</ th >
                                            
< th >
                        供应商3
</ th >
                                            
< th >
                        供应商4
</ th >
                
</ tr > s
            
</ HeaderTemplate >
            
< ItemTemplate >
                
< tr >
                    
< td >
                        
< del >
                            
<% #Eval("CategoryName" %>
                        
</ del >
                    
</ td >
                    
< td >
                        
< asp:Repeater  DataSource ='<%#GetChildren()  % > ' runat="server">
                            
< ItemTemplate >
                                
< table >
                                    
< tr >
                                        
< td  width ="250px" >
                                            
<% #Eval("ProductName" %>
                                        
</ td >
                                        
< td  width ="100px" >
                                            
<% #Eval("UnitPrice","{0:c}" %>
                                        
</ td >
                                        
< td  width ="100px" >
                                            
< del  style ="background-color: Red" >
                                                
<% #Eval("UnitsInStock","{0:c}" %>
                                            
</ del >
                                        
</ td >
                                    
</ tr >
                                
</ table >
                            
</ ItemTemplate >
                        
</ asp:Repeater >
                    
</ td >
                
</ tr >
            
</ ItemTemplate >
            
< AlternatingItemTemplate >
            
</ AlternatingItemTemplate >
            
< SeparatorTemplate >
            
</ SeparatorTemplate >
            
< FooterTemplate >
                
</ table >
            
</ FooterTemplate >
        
</ asp:Repeater >
    
</ form >
</ body >
</ html >

 

后代

 

using  System;
using  System.Data;
using  System.Configuration;
using  System.Collections;
using  System.Web;
using  System.Web.Security;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web.UI.WebControls.WebParts;
using  System.Web.UI.HtmlControls;

public   partial   class  GridView_Test_GridView8 : System.Web.UI.Page
{
    
变量
    
protected void Page_Load(object sender, EventArgs e)
    
{
        
if (!IsPostBack)
        
{
            GetData(); 
//加载显示的数据

        }

    }

    
//得到Product表中的数据集
    private void GetData()
    
{
        ds 
= C_Categories.Instance.GetList_Eds(strSql_Categories);
        
if (ds.Tables[0].Rows.Count > 0)
        
{
            
this.objRepeater.DataSource = ds.Tables[0];
            
//objGridView.DataKeyNames = new string[] { "ProductID" };//主键(注意DataKeyNames 是复数间接告诉我们这里是可以有多个字段即可以是联合主键)
            this.objRepeater.DataBind();
        }

    }

    
public DataSet GetChildren()
    
{
        
string strSql_Products = "select * from products where categoryid in (select categoryid from categories where categoryid=1)";
        
return C_Products.Instance.GetList_Eds(strSql_Products);
    }

}

 中间操作类方法:

 

         // 常规获得记录
         public  DataSet GetList_Eds( string  strSql)
        
{
            
if (strSql != "")
            
{
                
return DbHelperSql.ExecuteDataSet(strSql.ToString(), null);
            }

            
else
            
{
                
return null;
            }

        }

 

 数据库链接:

 

   < appSettings >
    
< add key = " ConnectionString "  value = " Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=NORTHWIND;Data Source=WANGYONGJUN "   />
  
</ appSettings >
  
< connectionStrings >
    
< add name = " NorthwindConnectionString "  connectionString = " Persist Security Info=True;Password=sa;User ID=sa;Initial Catalog=NORTHWIND;Data Source=WANGYONGJUN "  providerName = " System.Data.SqlClient "   />
  
</ connectionStrings >

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值