zoukankan      html  css  js  c++  java
  • asp.net asp:Repeater嵌套绑定方法(1)

    通过外面repeater1的 Repeater1_ItemDataBound 事件里获取到里面repeater2的ID 进行绑定 常用于VS2003开发环境

    html

    <asp:Repeater id="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
              <HeaderTemplate>
               <table width="100%" border="0" cellspacing="0" cellpadding="0">
              </HeaderTemplate>
              <ItemTemplate>
               <tr>
                <td align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                   <td class="brown02_14" style="color:#ED9C72">
                    <asp:Label ID="MaterielName" runat="server" Text=' <%# DataBinder.Eval(Container.DataItem, "item_name")%>'>
                    </asp:Label></td>
                   <td align="right" class="brown02_14" style="color:#ED9C72">医生:<%# DataBinder.Eval(Container.DataItem, "check_opername")%></td>
                  </tr>
                 </table>
                </td>
               </tr>
               <table width="100%" border="0" cellpadding="4" cellspacing="0">
                <tr>
                 <td align="left" bgcolor="#E7EFFC" class="brown02_14">检查项目名称</td>
                 <td width="50%" align="left" bgcolor="#E7EFFC" class="brown02_14">结果</td>
                 <td width="5%" align="left" bgcolor="#E7EFFC" class="brown02_14">单位</td>
                 <td width="13%" align="right" bgcolor="#E7EFFC" class="brown02_14">正常范围值</td>
                </tr>
                <tr>
                 <td>
                  <asp:Repeater id="rptDetails1" runat="server">
                   <ItemTemplate>
                    <tr>
                     <td align="left" class="brown02_12"><%# DataBinder.Eval(Container.DataItem, "field_comment")%></td>
                     <td align="left" class="black_12"><%# DataBinder.Eval(Container.DataItem, "field_results").ToString().Replace("\r\n","<br/>")%></td>
                     <td align="left" class="black_12"><%# DataBinder.Eval(Container.DataItem, "dw")%></td>
                     <td align="right" class="black_12"><%# DataBinder.Eval(Container.DataItem, "fw")%></td>
                    </tr>
                    <tr>
                     <td colspan="4" height="0"></td>
                    </tr>
                   </ItemTemplate>
                  </asp:Repeater>
                 </td>
                </tr>
               </table>
              </ItemTemplate>
              <FooterTemplate>
         </table>
         </FooterTemplate> </asp:Repeater>

    .cs

    public void SearchReportByVid()
      {
       DataTable dt = manager.SearchReportByVid(vid + "1").Tables[0];
       DataTable dtt = new DataTable("dttt");
       DataRow newRow = null;
       if (dt.Rows.Count != 0)
       {
        DataColumn dc = new DataColumn();
        dc = dtt.Columns.Add("item_name", Type.GetType("System.String"));
        dc = dtt.Columns.Add("check_opername", Type.GetType("System.String"));
        dc = dtt.Columns.Add("testitem_id", Type.GetType("System.String"));
        dc = dtt.Columns.Add("lx", Type.GetType("System.String"));
       
        for (int i = 0; i < dt.Rows.Count; i++)
        {
         if (i < dt.Rows.Count - 1)
         {
          if (dt.Rows[i]["item_name"].ToString().Trim() != dt.Rows[i + 1]["item_name"].ToString().Trim())
          {
           newRow = dtt.NewRow();
           newRow["item_name"] = dt.Rows[i]["item_name"].ToString();
           newRow["check_opername"] = dt.Rows[i]["check_opername"].ToString();
           newRow["testitem_id"] = dt.Rows[i]["testitem_id"].ToString();
           newRow["lx"] = dt.Rows[i]["lx"].ToString();
           dtt.Rows.Add(newRow);

          }
         }
         else
         {
          newRow = dtt.NewRow();
          newRow["item_name"] = dt.Rows[i]["item_name"].ToString();
          newRow["check_opername"] = dt.Rows[i]["check_opername"].ToString();
          newRow["testitem_id"] = dt.Rows[i]["testitem_id"].ToString();
          newRow["lx"] = dt.Rows[i]["lx"].ToString();
          dtt.Rows.Add(newRow);
         }

        }
       }
       Repeater1.DataSource = dtt;
       Repeater1.DataBind();

      }
      public DataTable SearchReportByVidIn(string item_name)
      {
       DataTable tblDatas = new DataTable("dtt");

       DataTable dt = manager.SearchReportByVid(vid + "1").Tables[0];
       if (dt.Rows.Count != 0)
       {
        DataColumn dc = new DataColumn();
        dc = tblDatas.Columns.Add("field_comment", Type.GetType("System.String"));
        dc = tblDatas.Columns.Add("field_results", Type.GetType("System.String"));
        dc = tblDatas.Columns.Add("dw", Type.GetType("System.String"));
        dc = tblDatas.Columns.Add("testitem_id", Type.GetType("System.String"));
        dc = tblDatas.Columns.Add("aid", Type.GetType("System.String"));
        dc = tblDatas.Columns.Add("fw", Type.GetType("System.String"));

        for (int i = 0; i < dt.Rows.Count; i++)
        {
         if (dt.Rows[i]["item_name"].ToString().Trim() == item_name)
         {
          DataRow newRow = tblDatas.NewRow();
          newRow["field_comment"] = dt.Rows[i]["field_comment"].ToString();
          newRow["field_results"] = dt.Rows[i]["field_results"].ToString();
          newRow["dw"] = dt.Rows[i]["dw"].ToString();
          newRow["testitem_id"] = dt.Rows[i]["testitem_id"].ToString();
          newRow["aid"] = dt.Rows[i]["aid"].ToString();
          newRow["fw"] = dt.Rows[i]["fw"].ToString();

          tblDatas.Rows.Add(newRow);
         }
        }
       }
       return tblDatas;
      }

      protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
      {
       if (e.Item.ItemType == ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
       {
        Repeater rp2 = (System.Web.UI.WebControls.Repeater)e.Item.FindControl("rptDetails1");
        Label   lb   =   (Label)e.Item.FindControl( "MaterielName");
        string item_name= lb.Text;
        DataTable tblDatas =SearchReportByVidIn(item_name.ToString());

        if (tblDatas != null)
        {
         rp2.DataSource = tblDatas;
         rp2.DataBind();
        }
       }
      }

  • 相关阅读:
    k8s之Controller Manager(七)
    k8s 之apiserver部署(六)
    k8s之etcd集群安装(五)
    k8s 之harbor仓库安装(四)
    k8s 之docker环境部署 (三)
    如何在PPT中同时插入多张图片且每张占一页
    ICMPV6
    整理桌面 | Windows自带工具
    教你在Linux中如何配置网络地址
    解决在gns3中wireshark抓包无法显示和实时刷新问题
  • 原文地址:https://www.cnblogs.com/xiaogelove/p/1878378.html
Copyright © 2011-2022 走看看