zoukankan      html  css  js  c++  java
  • Repeater嵌套使用

    未完。。

    前台代码:

    <asp:Repeater ID="Repeater_Info" runat="server" OnItemDataBound="Repeater_Info_ItemDataBound">
    //OnItemDataBound是绑定后台,使后台的代码和repeater绑定
      <ItemTemplate>
    <tr>
    <td width="20" nowrap="nowrap">//nowrap:表单内容不换行
              <strong>内容1</strong>
    </td>
    <td align="left" nowrap="nowrap">
    <strong>内容2</strong>
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <asp:Repeater ID="Content_List" runat="server">
    <ItemTemplate>
    <td nowrap="nowrap" runat="server" id="typeTd">//runat="server",服务器控件的使用,可以在后台调用id
                   </td>
    <td>
    <label for="<%#Eval("ContentID") %>">//绑定后台数据
    <%#Eval("Content") %>
    </label>//点击label上显示的后台的Content的内容,可以选中ContentID绑定的内容
    </td>
    </ItemTemplate>
    </asp:Repeater>
    </td>
    </tr>
    </ItemTemplate>
    </asp:Repeater>

    后台代码:

    protected void Repeater_Info_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    //判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,HeaderTemplate,ItemTemplate,SeparatorTemplate)
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    Repeater rep
    = e.Item.FindControl("Content_List") as Repeater;//找到里层的repeater对象
    rep.ItemDataBound += new RepeaterItemEventHandler(rep_ItemDataBound);
    DataRowView rowv
    = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项
    int typeid = Convert.ToInt32(rowv["QuestionID"]); //获取填充子类的id
              //数据库的连接,数据的绑定
    DataTable dt
    = dsInfo.Tables[0];
    AQ.TypeID
    = (int)dt.Rows[0]["TypeID"];
    rep.DataSource
    = dsInfo.Tables[0];//数据绑定
    rep.DataBind();
    }
    }

    void rep_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    //找到里层的td对象
    HtmlTableCell td = e.Item.FindControl("typeTd") as HtmlTableCell;
    DataRowView rowv
    = (DataRowView) e.Item.DataItem ;
    if ((int)rowv["TypeID"] == 1)
    {

    td.InnerHtml = "<input type=\"radio\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
    }
    else if ((int)rowv["TypeID"] == 2)
    {

    td.InnerHtml = "<input type=\"checkbox\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
    }
    else
    {

    td.InnerHtml = "<input type=\"text\" id=\"" + rowv["ContentID"].ToString() + "\" name=\"" + rowv["QuestionID"].ToString() + "\" value=\"" + rowv["ContentID"].ToString() + "\"/>";
    }
    }
    }
  • 相关阅读:
    C++学生成绩管理系统
    蓝桥杯算法训练 最大最小公倍数
    蓝桥杯基础练习 完美的代价
    vim编辑器的使用技巧
    C语言中static关键字的用法
    在linux环境下编译运行OpenCV程序的两种方法
    Linux中gcc编译器的用法
    浅谈Java中的hashcode方法
    读CopyOnWriteArrayList有感
    徐汉彬:Web系统大规模并发——电商秒杀与抢购(技术实现)
  • 原文地址:https://www.cnblogs.com/jianglan/p/2166727.html
Copyright © 2011-2022 走看看