博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
asp.net asp:Repeater嵌套绑定方法(2)
阅读量:4973 次
发布时间:2019-06-12

本文共 5172 字,大约阅读时间需要 17 分钟。

外面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;
    }

 

转载于:https://www.cnblogs.com/xiaogelove/archive/2010/11/16/1878390.html

你可能感兴趣的文章
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>
iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
查看>>
toad for oracle中文显示乱码
查看>>
SQL中Group By的使用
查看>>
两个表格中数据不用是一一对应关系--来筛选不同数据,或者相同数据
查看>>
hiho_offer收割18_题解报告_差第四题
查看>>
AngularJs表单验证
查看>>
静态方法是否属于线程安全
查看>>
02号团队-团队任务3:每日立会(2018-12-05)
查看>>
SQLite移植手记1
查看>>
js05-DOM对象二
查看>>
mariadb BINLOG_FORMAT = STATEMENT 异常
查看>>
iPhone在日本最牛,在中国输得最慘
查看>>
动态方法决议 和 消息转发
查看>>
C#生成随机数
查看>>
Java回顾之多线程
查看>>
机电行业如何进行信息化建设
查看>>
9、总线
查看>>
2018 Multi-University Training Contest 10 - Count
查看>>
HDU6203 ping ping ping
查看>>