C# Repeater嵌套循环[通俗易懂]

C# Repeater嵌套循环[通俗易懂]前台代码:<asp:RepeaterID=”rptList”runat=”server”OnItemDataBound=”users_list”><HeaderTemplate><tablewidth=”100%”border=”0″cellspacing=”0″cellpadding=”0″…

大家好,又见面了,我是你们的朋友全栈君。

前台代码:

<asp:Repeater ID="rptList" runat="server" OnItemDataBound="users_list">
            <HeaderTemplate>
                <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
                    <thead>
                        <tr>
                            <th style="width: 80px;">
                                主表字段
                            </th>
                            <th style="width: 320px;">
                                <table width="100%" border="0" cellpadding="5" cellspacing="1">
                                    <tr bgcolor="#FFFFFF">
                                        <th width="50%">
                                            <div align="center">
                                                <font>对应字段1</font></div>
                                        </th>
                                        <th width="50%">
                                            <div align="center">
                                                <font>对应字段1</font></div>
                                        </th>
                                    </tr>
                                </table>
                            </th>
                            <th style="width: 100px;">
                                <i class="iconfont icon-setting bigger"></i>操作
                            </th>
                        </tr>
                    </thead>
            </HeaderTemplate>
            <ItemTemplate>
                <tr>
                    <td>
                        主表数据
                    </td>
                    <td>
                        <table width="100%" border="0">
                            <asp:Repeater ID="users_list" runat="server">
                                <ItemTemplate>
                                    <tr bgcolor="#FFFFFF">
                                        <td width="50%" align="center">
                                            对应数据1
                                        </td>
                                        <td width="50%" align="center">
                                            对应数据2
                                        </td>
                                    </tr>
                                </ItemTemplate>
                            </asp:Repeater>
                        </table>
                    </td>
                    <td>
                       <a href="#">修改</a>
                       <a href="#">查看</a>
                    </td>
                </tr>
            </ItemTemplate>
            <FooterTemplate>
                <%#rptList.Items.Count == 0 ? "<tr><td align=\"center\" colspan=\"3\"><font color=\"#F89406\">暂无记录</font></td></tr>" : ""%>
                </table>
            </FooterTemplate>
        </asp:Repeater>

后台代码:

      	//主表数据绑定
        private void RptBind(string _strWhere, string _orderby)
        { 
   
            BLL.xs_user bll = new BLL.xs_user();
            this.rptList.DataSource = bll.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount, "manager_qualification_certificate");
            this.rptList.DataBind();
        }

        //副表数据绑定
        protected void users_list(object sender, RepeaterItemEventArgs e)
        { 
   
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            { 
   
                string ID = ((DataRowView)e.Item.DataItem).Row["ID"].ToString();//获得对应ID
                Repeater repeater= (Repeater)e.Item.FindControl("users_list");//找到要绑定数据的Repeater
                //Literal Lit = ((Literal)e.Item.FindControl("Lit_cn"));
                //Literal Lit_remark = ((Literal)e.Item.FindControl("Lit_remark"));

                if (repeater!= null)
                { 
   
                    DataTable dt = 获取到的数据;

                    //string remark = "";
                    //foreach (DataRow item in dt.Rows)
                    //{ 
   
                    // if (!string.IsNullOrWhiteSpace(item["u_remark"].ToString()))
                    // { 
   
                    // remark += item["name"].ToString() + ":" + item["u_remark"].ToString() + "。";
                    // }
                    //}

                    //Lit_remark.Text = remark + Lit_remark.Text;
                    repeater.DataSource = dt;
                    repeater.DataBind();
                }
            }
        }

共同学习,一起进步,有些东西我也不懂,可以大家一起讨论!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/159112.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • php二次开发知识,Discuz二次开发基本知识详细讲解

    php二次开发知识,Discuz二次开发基本知识详细讲解Discuz是国内最流行的论坛软件管理系统,今天小编跟大家分享一篇关于Discuz二次开发基本知识详细讲解,感兴趣的朋友跟小编一起来了解一下吧!一)Discuz!的文件系统目录注:想搞DZ开发,就得弄懂DZ中每个文件的功能。a)Admin:后台管理功能模块b)Api:DZ系统与其它系统之间接口程序c)Archiver:DZ中,用以搜索引擎优化的无图版d)Attachments:DZ中,…

    2022年5月12日
    38
  • jquery ui 笔记

    jquery ui 笔记

    2022年1月3日
    145
  • executescalar mysql_ExecuteScalar

    executescalar mysql_ExecuteScalar这两个答案和一点点思考使我想到了一个接近答案的东西。首先再澄清一下:该应用程序是用C#(2.0+)编写的,并使用ADO.NET与SQLServer2005进行通信。镜像设置是托管主体和镜像的两个W2k3服务器以及托管作为监视器的快速实例的第三个服务器。这样做的好处是,故障转移对于使用数据库的应用程序几乎是透明的,它将对某些连接引发错误,但从根本上讲一切都会很好地进行。是的,我们得到了奇怪的误报…

    2022年6月30日
    16
  • pycharm 字体以及颜色修改「建议收藏」

    pycharm 字体以及颜色修改「建议收藏」 自处记录本人使用Pycharm时习惯用的代码风格以及左侧文件栏的字体大小。Pycharm代码风格修改如下图: Pycharm左侧工具栏字体大小相关设置:  

    2022年8月26日
    3
  • 知识图谱(二)——知识推理

    知识图谱(二)——知识推理知识推理是知识图谱中很重要的一部分,主要用于推理暗含的知识(丰富知识图谱),检查知识库的不一致(知识清洗)知识推理分类演绎推理从一般到特殊的过程.从一般性的前提出发,通过推导,得到具体描述或个别结论(三段论),结论已经蕴含一般性知识中,只是通过演绎推理揭示出来,不能得到新知识.归纳推理从特殊到一般的推理过程.从一类事物的大量特殊事例出发,去推出该类事物的一般性结论(数学归纳法)…

    2022年6月1日
    62
  • SpringBoot集成Activiti6教程

    SpringBoot集成Activiti6教程第一步在项目pom.xml文件中添加所需依赖&lt;?xmlversion="1.0"encoding="UTF-8"?&gt;&lt;projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="htt

    2022年7月21日
    9

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号