Repeater嵌套DataList

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RepeaterDemo.aspx.cs" Inherits="OldbSiteMapProviderDemo.RepeaterDemo" %>
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="Geovin Du 塗聚文"/><br><meta name="Keywords" content="捷为工作室"/><br><meta name="Description" content="缔友计算机信息技术有限公司"/><br><br>    <title>Repeater嵌套DataList</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Repeater runat="server" ID="parent" OnItemDataBound="parent_ItemDataBound">
   <HeaderTemplate>
<div class="urbangreymenu">
      </HeaderTemplate>
              <ItemTemplate>
                   
                          <h3 class="headerbar"> <%#Eval("bidclass")%>
                              <asp:Label ID="Label1" runat="server" Text='<%#Eval("bigid")%>' Visible="false"></asp:Label></h3>
                           
                            <asp:DataList runat="server" ID="child" RepeatColumns="2" SelectedItemStyle-CssClass="SelectedproudctclassStyle" ItemStyle-CssClass="proudctclassStyle">
                            <HeaderTemplate></HeaderTemplate>
                               <ItemTemplate>
                                        <ul><li>
                                          <a title='<%#Eval("smallcalss")%>' href='ProductClass.aspx?id=<%#DataBinder.Eval(Container.DataItem,"sid") %>'>
                                             <%#Eval("smallcalss")%> </a
                                            <asp:CheckBox ID="CheckBox1" runat="server" />
                                          </li></ul>
                               </ItemTemplate
                               <FooterTemplate></FooterTemplate>                           
                            </asp:DataList>
                         
              </ItemTemplate>
               <FooterTemplate>
               </div>
               </FooterTemplate>
          </asp:Repeater>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
    </form>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
using SiteMapProviderLibrary;
 
namespace OldbSiteMapProviderDemo
{
  //涂聚文     public partial class RepeaterDemo : System.Web.UI.Page
    {
        bigclassDB bigd = new bigclassDB();
        SmallClassDB smd = new SmallClassDB();
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DatabindReptBigProductType();
            }
        }
        /// <summary>
        /// 产品大类
        /// </summary>
        private void DatabindReptBigProductType()
        {
            DataTable dt = bigd.bidclassDataTable();
            parent.DataSource = dt;
            parent.DataBind();
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void parent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            string strFirstNo = "0";
            string Idx = "0";
            string b_id = "0";
            try
            {
                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                     DataList childs = (DataList)e.Item.FindControl("child");
                    DataRowView rows = (DataRowView)e.Item.DataItem;
                    Idx = rows["bigid"].ToString();                  
 
                    //Idx = (string)DataBinder.Eval(e.Item.DataItem, "bigid");
                    strFirstNo = rows["bigid"].ToString();
                    Label l = (Label)e.Item.FindControl("Label1");
                    strFirstNo = l.Text;
                    DataTable dt = smd.SmallClassDataTableBigID(strFirstNo);
 
                    childs.DataSource = dt;
                    childs.DataBind();
                }
            }
            catch (Exception ex)
            {
              string err=ex.Message.ToString();
              //Response.Write(e);
 
            }
            Response.Write(strFirstNo + "," + Idx + "<br/>" + b_id);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            string str = "";
            for (int i = 0; i < parent.Items.Count; i++)
            {
                DataList myDataList = (DataList)parent.Items[i].FindControl("child");
                for (int j = 0; j < myDataList.Items.Count; j++)
                {
                    CheckBox myCheckBox = (CheckBox)myDataList.Items[j].FindControl("CheckBox1");
                    if (myCheckBox.Checked)
                    {
                        str += "Repeat的第" + (i+1).ToString() + "行,DataList的第" + (j+1).ToString() + "行选中<br />";
                    }
                }
            }
            Response.Write(str);
 
        }
    }
}
posted @   ®Geovin Du Dream Park™  阅读(405)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
< 2011年5月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 1 2 3 4
5 6 7 8 9 10 11
点击右上角即可分享
微信分享提示