Repeater 控件嵌套

 1 using System;
 2 using System.Data;
 3 using System.Configuration;
 4 using System.Collections;
 5 using System.Web;
 6 using System.Web.Security;
 7 using System.Web.UI;
 8 using System.Web.UI.WebControls;
 9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 
12 public partial class Web_Default : System.Web.UI.Page
13 {
14     /// <summary>
15     /// 实例化接口层news类的对象
16     /// </summary>
17     BLL.news B_news = new BLL.news();
18     BLL.BigClass B_bc = new BLL.BigClass();
19 
20     SQLServerDAL.FomatString FString = new SQLServerDAL.FomatString();
21     DBbase db = new DBbase();
22 
23     protected void Page_Load(object sender, EventArgs e)
24     {
25         if (!Page.IsPostBack)
26         {
27             DataBindRepeaterNew();
28             DataBindRepeaterBigClass();
29             this.Title = "新闻系统----本系统采用ASP.NET 2.0+SQL Server 2000技术架构!";
30             Session.Clear();
31         }
32     }
33 
34     /// <summary>
35     /// 获取最新新闻
36     /// </summary>
37     public void DataBindRepeaterNew()
38     {
39         RepeaterNew.DataSource = B_news.GetDataEightNew();
40         RepeaterNew.DataBind();
41     }
42 
43     /// <summary>
44     /// 获取允许显示的栏目名称集合
45     /// </summary>
46     public void DataBindRepeaterBigClass()
47     {
48         Repeater1.DataSource = B_bc.GetBigClass();
49         Repeater1.DataBind();
50     }
51 
52     /// <summary>
53     /// 截取字符串
54     /// </summary>
55     /// <param name="str">要截取的字符串</param>
56     /// <param name="len">要截取字符串的长度</param>
57     /// <returns>截取后的字符串</returns>
58     public string cutString(string str, int len)
59     {
60         return FString.CutString(str, len); 
61     }
62 
63     protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
64     {
65         object cid;
66         cid = DataBinder.Eval(e.Item.DataItem, "id");
67         Repeater Repeater2;
68         Repeater2 = (Repeater)e.Item.FindControl("Repeater2");
69         string sqlnews = "select top 4 id,title,infotime,hits from news where BigClassID='" + int.Parse(cid.ToString()) + "' and flag='已审核' order by cindex";
70         DataSet ds1 = db.ReturnDataSet(sqlnews);
71         Repeater2.DataSource = ds1.Tables[0].DefaultView;
72         Repeater2.DataBind();
73 
74     }
75 
76 }
77 

posted on 2008-12-28 22:20  鱼跃于渊  阅读(225)  评论(0编辑  收藏  举报

导航