在Repeater控件中嵌套一个Repeater控件

做销售报表的页面
 1 < table  style ="BORDER-TOP: #42adf1 1px outset"  cellSpacing ="1"  cellPadding ="1"  width ="100%"   align ="center"  border ="0" >
 3                                          < tr >
 4                                              < td  class ="column"  width ="5%"  height ="20" ></ td >
 5                                              < td  class ="column"  nowrap width ="30%" >cell < / td >
 6                                              < td  class ="column"  nowrap width ="30%" >cell </ td >
 7                                              < td  class ="column"  nowrap width ="20%" >cell< td >
 8                                              < td  class ="column"  nowrap width ="20%" >cell </ td >
 9                                          </ tr >
10                                          < script  runat ="server" >
11                                            int l = 1;
12                                        
</ script >
13                                          < asp:repeater  id ="repeaterCollection"  runat ="server" >
14                                              < ItemTemplate >
15                                                  < asp:Literal  ID  ="NoneResource"  Runat =server ></ asp:Literal >
16                                                  < tr  class ="f2" >
17                                                      < td  align ="right" > &nbsp; <% = l ++ %>
18                                                         . &nbsp; </ td >
19                                                      < td  nowrap height ="20" >
20                                                          < TABLE  WIDTH ="100%"  BORDER ="0"  CELLSPACING ="0"  CELLPADDING ="0" >
21                                                              < TR >
22                                                                  < TD  align ="left"  width ="90%"  nowrap > <% #DataBinder.Eval(Container.DataItem,"city") %> </ TD >
23                                                                  < TD  align =right  nowrap >< onmousedown ="AreaDetailsOnOff('AreaDetails<%=l%>')"  style ="cursor:hand" >   &raquo;&raquo;< / a ></ td >                                                     
24                                                              </ TR >
25                                                          </ TABLE >
26                                                      </ TD >
27                                                      < td  nowrap >
28                                                          <% #DataBinder.Eval(Container.DataItem,"name") %>
29                                                      </ td >
30                                                      < td  nowrap >
31                                                          <% # SalesReport.GetProductSalesTotalNum(DataBinder.Eval(Container.DataItem,"DealerID").ToString()) %>
32                                                      </ td >
33                                                      < td  nowrap >
34                                                          <% # SalesReport.GetProductSalesWorth(DataBinder.Eval(Container.DataItem,"DealerID").ToString()) %>
35                                                          <% # SalesReport.SetDealerID(DataBinder.Eval(Container.DataItem,"DealerID").ToString()) %>
36                                                      </ td >
37                                                  </ tr >
38                                                  < tr  class ="f2" >
39                                                      < td ></ td >
40                                                      < td  colspan =4  height =1 >
41                                                          < DIV  id ="AreaDetails<%=l%>"  style ="DISPLAY: none;" >
42                                                              < table  cellSpacing ="1"  cellPadding ="0"  border =0  width ="100%"  align =center  class ="tableBorder" >
43                                                                  < tr >
44                                                                      < td  class ="child"  width ="5%"  height ="12" ></ td >
45                                                                      < td  class ="child"  nowrap width ="25%" > &nbsp;cell </ td >
46                                                                      < td  class ="child"  nowrap width ="22%" > &nbsp;cell </ td >
47                                                                      < td  class ="child"  nowrap width ="22%" > &nbsp;cell </ td >
48                                                                      < td  class ="child"  nowrap width ="22%" > &nbsp;cell </ td >
49                                                                  </ tr >                                                         
50                                                                  < script  language =C#  runat =server >
51                                                                    int i = 1;
52                                                                
</ script >
53                                                                  < CT:MyRepeater  id ="myRepeater"  runat ="server" >         
54                                                                      < ItemTemplate >
55                                                                          < asp:Literal  ID  ="nonetotalprod"  Runat =server ></ asp:Literal >
56                                                                          < tr  class ="f2" >
57                                                                              < td > &nbsp; <% =  i ++   %> . &nbsp; </ td >
58                                                                              < td  nowrap height ="2" >
59                                                                                  <% #DataBinder.Eval(Container.DataItem,"PName") %> </ a ></ td >
60                                                                              < td  nowrap >
61                                                                                  <% #DataBinder.Eval(Container.DataItem,"quantity") %>
62                                                                              </ td >
63                                                                              < td  nowrap >
64                                                                                  <% #DataBinder.Eval(Container.DataItem,"UnitPrice") %>
65                                                                              </ td >
66                                                                              < td  nowrap >
67                                                                                  <% #SalesSchemeTrack.SetTotalPrice(DataBinder.Eval(Container.DataItem,"quantity").ToString(),DataBinder.Eval(Container.DataItem,"UnitPrice").ToString(),DataBinder.Eval(Container.DataItem,"DiscPercent").ToString()) %>
68                                                                              </ td >
69                                                                          </ tr >
70                                                                      </ ItemTemplate >
71                                                                  </ CT:MyRepeater >
72                                                              </ table >
73                                                          </ div >
74                                                      </ td >
75                                                  </ tr >
76                                              </ ItemTemplate >
77                                          </ asp:repeater >
78                                          < tr  class ="f2" >
79                                              < td  align ="right"  colSpan ="9" >
80                                                  < TABLE  class ="tableborder"  cellSpacing ="0"  cellPadding ="0"  border ="0" >
81                                                      < TR >
82                                                          < TD >< asp:label  id ="pageindex"  runat ="server"  CssClass ="pageIndex" ></ asp:label ></ TD >
83                                                      </ TR >
84                                                  </ TABLE >
85                                              </ td >
86                                          </ tr >
87                                      </ table >
88                                  </ TD >
89                              </ TR >
90                          </ table >
91                      </ td >
92                  </ tr >
93              </ TABLE >
<script language=""javascript>
function AreaDetailsOnOff (menuName) {
    menu = document.getElementById(menuName);
    if (menu.style.display == 'none') {
      menu.style.display = 'block';
    } else {
      menu.style.display = 'none';
    }
}
</script>


C#代码,没给全,BaseControl,页面基类
想要的朋友联系我.因为时间紧代码写得有点杂.
  1 using  System;
  2 using  System.Web;
  3 using  System.Web.UI;
  4 using  System.Web.UI.WebControls;
  5 using  System.Web.UI.Design;
  6 using  System.Web.UI.HtmlControls;
  7 using  System.Collections;
  8 using  Jessup.Framework;
  9 using  Jessup.UI.WebControls;
 10 using  Jessup.Enumeration;
 11 using  System.Web.Security;
 12
 13 namespace  Jessup.UI.Controls
 14 {
 15    /// <summary>
 16    /// SalesDataColletion 地区总销售报告。
 17    /// </summary>

 18    
 19    [ParseChildren(true)]
 20    public class SalesReport : BaseControl
 21    {
 22        #region 成员变量,构造函数
 23        Repeater repeaterCollection;
 24        Label pageindex;
 25        Literal NoneResource;
 26
 27//        int dealerID = 0;
 28        string skinFileName = "SalesReport.ascx";
 29        string pageStr = "";
 30        static string nonesource="<tr class=\"f2\"><td colspan=\"9\" align=\"center\" height=\"40\">{0}</td></tr>";
 31
 32        public SalesReport()
 33        {
 34            if(base.SkinFilename == null)
 35                base.SkinFilename = this.skinFileName;
 36        }

 37
 38        public static string SetDealerID(string did)
 39        {
 40            PageContext pageContext = PageContext.Current;
 41            pageContext.DealerID = Format.StringToInt(did);
 42//            MyRepeater myRep = new MyRepeater();
 43//            myRep.DealerID = Format.StringToInt(did);
 44            return "";            
 45        }

 46
 47        #endregion

 48
 49        #region 初始化控件
 50        override protected void InitializeSkin(Control skin) 
 51        {
 52            PageContext pageContext = PageContext.Current;
 53            if((int)Identifier.UserSession.Role < (int)UserRole.Employee)
 54            {
 55                Identifier.CheckUserIdentifier((int)UserRole.Employee,pageContext.Context.Request.Path,true);
 56            }

 57
 58            //Repeater控件绑定
 59            repeaterCollection = (Repeater) skin.FindControl("repeaterCollection");
 60            BindingRepeater();
 61
 62            pageindex    = (Label) skin.FindControl("pageindex");
 63            NoneResource= (Literal)skin.FindControl("NoneResource");
 64            pageindex.Text = PageString;
 65
 66        }

 67        #endregion

 68
 69        #region Repeater控件绑定
 70        private void BindingRepeater()
 71        {
 72            try
 73            {
 74                PagedDataSource dataSource = new PagedDataSource();
 75                dataSource.DataSource = Products.GetSalesProductSchemeTotal().Tables[0].DefaultView;
 76                if(dataSource.DataSourceCount == 0)
 77                {
 78                    NoneResource.Text = string.Format(nonesource,Globals.GetString("NoneSource"));
 79                    return;
 80                }
                        //分页.
 81                PageString = Globals.AllowPageString(dataSource,5);
 82                repeaterCollection.DataSource = dataSource;
 83                repeaterCollection.DataBind();
 84            }

 85            catch(Exception e)
 86            {
 87                throw new Exception("Can't connection Database.<br>" + e.ToString());
 88            }

 89        }

 90        #endregion

 91
 92        public static string GetProductSalesTotalNum(string dealerid)
 93        {
 94            int did = Format.StringToInt(dealerid);
 95            string salesTotalNum = Products.GetSalesTotalNum(did);
 96            return salesTotalNum;
 97        }

 98
 99        public static string GetProductSalesWorth(string dealerid)
100        {
101            int did = Format.StringToInt(dealerid);
102            string salesTotalNum = Products.GetSalesTotalValue(did);
103            return salesTotalNum;
104
105        }

106        //分页字符串
107        public string PageString
108        {
109            get return pageStr;}
110            set { pageStr= value;}
111        }

112
113    }

114}

115


MyRepeater 重载Repeater控件

 1 using  System;
 2 using  System.Web;
 3 using  System.Web.UI;
 4 using  System.Web.UI.WebControls;
 5 using  System.Web.UI.Design;
 6 using  System.Web.UI.HtmlControls;
 7 using  System.Collections;
 8 using  Jessup.Framework;
 9 using  Jessup.UI.WebControls;
10 using  Jessup.Enumeration;
11 using  System.Web.Security;
12
13 namespace  Jessup.UI.Controls
14 {
15    /// <summary>
16    /// MyRepeater 重载Repeater控件。
17    /// </summary>

18
19    [ParseChildren(true)]
20    public class MyRepeater : Repeater
21    {
22        int DealerID;
                //PageContext: 页面上下文,获取查询ID
23        PageContext pageContext = PageContext.Current;
24        public MyRepeater()
25        {
26            DealerID = pageContext.DealerID;
27        }

28
29//        public int DealerID
30//        {
31//            get { return this.dealerid; }
32//            set { dealerid = value; }
33//        }
34        protected override void CreateChildControls() 
35        {
36            try
37            {
38                    DealerID = pageContext.DealerID;
39                if(this.DealerID > 0)
40                {//取得数据源
41                    this.DataSource = Products.GetSalesProductScheme(DealerID);
42                    this.DataBind();
43                }

44            }

45            catch(Exception e)
46            {
47                throw new Exception("Can't connection Database.<br>" + e.ToString());
48            }

49        
50        }

51    }

52}

53

你可能感兴趣的:(控件)