• asp.net asp:Repeater嵌套绑定方法(2)


    外面repeater1 正常绑定, 里面的repeater2 直接在html 代码里面绑定返回数据集的方法给DataSource 属性即可。

    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"><%# DataBinder.Eval(Container.DataItem, "item_name")%>&nbsp;<a href="LinChuangYiyi.aspx?testid=<%#Eval("testitem_id") %>" style="color: #FF3399; font-weight:bold"><%# DataBinder.Eval(Container.DataItem, "lx")%></a></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" DataSource='<%# SearchReportByVidIn(Eval("item_name").ToString()) %>'>
          <ItemTemplate>
          
    <tr ><td align="left" class="brown02_12" ><%# DataBinder.Eval(Container.DataItem, "field_comment")%>&nbsp;<a href="LinChuangYiyi.aspx?testid=<%#Eval("testitem_id") %>" style="color: #FF3399; font-weight:bold"><%# DataBinder.Eval(Container.DataItem, "aid")%></a></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>
    <%--<td align="left" class="black_12"><%# DataBinder.Eval(Container.DataItem, "zcz_xx").ToString() == DataBinder.Eval(Container.DataItem, "zcz_sx").ToString() ? DataBinder.Eval(Container.DataItem, "zcz_xx").ToString() : ("上限:" + DataBinder.Eval(Container.DataItem, "zcz_sx").ToString() + "<br/>下限:" + DataBinder.Eval(Container.DataItem, "zcz_xx").ToString())%></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+flag).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 + flag).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("zcz_xx", Type.GetType("System.String"));
                //dc = tblDatas.Columns.Add("zcz_sx", 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["zcz_xx"] = dt.Rows[i]["zcz_xx"].ToString();
                        //newRow["zcz_sx"] = dt.Rows[i]["zcz_sx"].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;
        }

  • 相关阅读:
    某网的五一首发的黑夜3306终结版 工具+教程
    3389、1433、3306抓鸡原理和工具教程(原理篇)
    新手学习SEO要做的七件事是什么?
    通俗语言解释内外网IP与端口映射
    一次FCK拿bc全过程
    总结找到后台路径的N总思路方法
    threejs学习笔记(8)
    threejs学习笔记(7)
    threejs学习笔记(6)
    threejs学习笔记(5)
  • 原文地址:https://www.cnblogs.com/xiaogelove/p/1878390.html
Copyright © 2020-2023  润新知