repeater嵌套

 1    <asp:Repeater ID="repeaterParent" runat="server"  OnItemDataBound="repeaterParent_ItemDataBound">
 2        <ItemTemplate>
 3            <!---------------------------------------------------------------------------------------->
 4            <table width="186" border="1" class="MenuTB">
 5                <tr>
 6                    <th style="cursor:pointer;">
 7                        <img src="images/comments.gif" / alt=""><%#Eval("MenuText"%>
 8                    </th>
 9                </tr>
10                <tr style="display:none">
11                    <td>
12                        <ul>
13                            <asp:Repeater ID="repeaterMinMenu" runat="server">
14                                <ItemTemplate>
15                                    <li>
16                                        <href="<%#Eval("MenuLink") %>" target="frmContent"><%#Eval("MenuText"%></a></li>
17                                </ItemTemplate>
18                            </asp:Repeater>
19                        </ul>
20                    </td>
21                </tr>
22            </table>
23            <!----------------------------------------------------------------------------------------->
24        </ItemTemplate>
25    </asp:Repeater>

C#:
 1        protected void BindParentRepeaterData()//绑定父repeater数据
 2        {
 3            string SqlGetParentMenu = @"SELECT MenuId,MenuText FROM website_Menu WHERE ParentId IS NULL OR ParentId=0";
 4
 5            DataTable dtGetParentMenu = SqlHelper.ExecuteDataset(Configurations.RemoteConnectionString, CommandType.Text, SqlGetParentMenu).Tables[0];
 6
 7            repeaterParent.DataSource = dtGetParentMenu;
 8
 9            repeaterParent.DataBind();
10        }

11
12
13        protected void repeaterParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
14        {
15            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
16            {
17                int MenuId = Convert.ToInt32(((DataRowView)e.Item.DataItem).Row["MenuId"]);
18
19                Repeater repeaterMinMenu = (Repeater)e.Item.FindControl("repeaterMinMenu");
20
21                if (repeaterMinMenu != null)
22                {
23                    string SqlGetMinMenu = string.Format(@"SELECT A.MenuId,A.ParentId,A.MenuText,A.MenuLink   FROM dbo.website_Menu A
24                                                            INNER JOIN dbo.website_RolesMenu B 
25                                                            ON A.MenuId = B.MenuId  AND A.ParentId = {0}
26                                                            INNER JOIN dbo.User_UsersRoles C 
27                                                            ON B.RoleId = C.RoleId AND C.UserId = {1}
28                                                            GROUP BY A.MenuId,A.ParentId,A.MenuText,A.MenuLink ",MenuId,Kuqu.Components.Tickets.UserInfo.Id);
29
30                    DataTable dtGetMinMenu = SqlHelper.ExecuteDataset(Configurations.RemoteConnectionString, CommandType.Text, SqlGetMinMenu).Tables[0];
31
32                    repeaterMinMenu.DataSource = dtGetMinMenu;
33
34                    repeaterMinMenu.DataBind();
35                }

36            }

37        }

posted on 2007-09-26 10:40  小子好黑  阅读(828)  评论(0编辑  收藏  举报

导航